/** * 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; }
/** * Construct an OptionParser so you can define its behavior * * @param string|null $command The command name this parser is for. The command name is used for generating help. * @param bool $default Whether you want the verbose and quiet options set. Setting * this to false will prevent the addition of `--verbose` & `--quiet` options. */ public function __construct($command = null, $default = true) { $this->_command = $command; $helpOptn = new CommandLineOption('help', 'Display this help.'); $helpOptn->addAlias('h'); $this->addOption($helpOptn); if ($default) { $verboseOptn = new CommandLineOption('verbose', 'Enable verbose output.'); $verboseOptn->addAlias("v"); $quietOptn = new CommandLineOption('quiet', 'Enable quiet output.'); $quietOptn->addAlias("q"); $this->addOption($verboseOptn)->addOption($quietOptn); } }