Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Expand ProcessBuilder to provide methods for adding flags and options as well #5451

Closed
boombatower opened this Issue · 4 comments

3 participants

@boombatower

I wrote my own CommandBuilder class that builds a command string. The class provides:

  • addArgument($argument) - command argument1 argument2
  • addOption($option, $value) - command --option1 value --option2 value
  • addFlag($flag) - command --flag1 --flag2

The following format options were also provided to allow for various preferences or requirements.

<?php
array(
  'single_dash' => FALSE,  // all flags/options have single dash instead of double, normally only single letter flags have single dash. useful for some command line interfaces like java -jar ...
  'option_equal' => FALSE, // add equal between option and value, --option=value
  'escape' => TRUE, // wrap each value using escapeshellarg()
  'newline' => FALSE, // print each part of the command on newline for readability
)

If this seems like a reasonable addition I will go ahead and merge into ProcessBuilder and make a pull request.

@boombatower

Also seems like doing something like CommandBuilder that can be passed to Process constructor is a better design since it allows people to extend the Process class and use ProcessBuilder with their class. Or perhaps split about the command building into a command builder class and allow them to be build separately with the command builder defining a __toString(). Building the command string is the hard part or the part that can benefit most from a builder, rather than setting booleans.

@boombatower

Although looking at Process class, everything is private...seems like should be protected.

@pscheit

+1 for that and i would love it as a CommandBuilder, too. I have code in preparation for this. Are you still processing it?

@fabpot
Owner

Closing this issue as this would complexify the component too much for no real added benefits.

@fabpot fabpot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.