Beispiel #1
0
 /**
  * Gets the option parser instance and configures it.
  *
  * @return CommandLineParser
  */
 public function getParser()
 {
     $parser = parent::getParser();
     $parser->description(['PHP Built-in Server', '<warning>[WARN] Don\'t use this at the production environment</warning>']);
     $parser->options()["help"]->removeAlias("h");
     $hostOptn = new CommandLineOption("host", "Server host name", ServerShell::DEFAULT_HOST);
     $hostOptn->addAlias('h');
     $portOptn = new CommandLineOption("port", "Server port", ServerShell::DEFAULT_PORT);
     $portOptn->addAlias('p');
     $documentRootOptn = new CommandLineOption("document-root", "Server DocumentRoot", getcwd());
     $documentRootOptn->addAlias('d');
     $parser->addOption($hostOptn)->addOption($portOptn)->addOption($documentRootOptn);
     return $parser;
 }
 /**
  * Add an option to the option parser. Options allow you to define optional or required
  * parameters for your console application. Options are defined by the parameters they use.
  *
  * ### Options
  *
  * - `alias` - The single letter variant for this option, leave undefined for none.
  * - `description` - Help text for this option. Used when generating help for the option.
  * - `default` - The default value for this option. Defaults are added into the parsed params when the
  *    attached option is not provided or has no value. Using default and boolean together will not work.
  *    are added into the parsed parameters when the option is undefined. Defaults to null.
  * - `choices` A list of valid choices for this option. If left empty all values are valid..
  *   An exception will be raised when parse() encounters an invalid value.
  *
  * @param CommandLineOption|string $name The long name you want to the value to be parsed out as when options are parsed.
  *   Will also accept an instance of CommandLineOption
  * @param array $options An array of parameters that define the behavior of the option
  * @return $this
  */
 public function addOption($name, array $options = [])
 {
     if ($name instanceof CommandLineOption) {
         $option = $name;
         $name = $option->name();
     } else {
         $defaults = ['name' => $name, 'description' => '', 'parser' => null];
         $options += $defaults;
         $option = new CommandLineOption($options);
     }
     $this->_options[$name] = $option;
     foreach ($option->alias() as $key) {
         $this->_optionsAlias[$key] = $name;
     }
     asort($this->_options);
     return $this;
 }