/** * Make a new Subcommand * * @param string|array $name The long name of the subcommand, or an array with all the properties. * @param string $help The help text for this option. * @param CommandLineParser|null $parser A parser for this subcommand. */ public function __construct($name, $help = '', $parser = null) { if (is_array($name) && isset($name['name'])) { foreach ($name as $key => $value) { $this->{'_' . $key} = $value; } } else { $this->_name = $name; $this->_help = $help; $this->_parser = $parser; } if ($this->_parser) { $this->_parser->command($this->_name); } }
/** * Generate the usage for a shell based on its arguments and options. * Usage strings favor short options over the long ones. and optional args will * be indicated with [] * * @return string */ protected function _generateUsage() { $usage = ['coretyson ' . $this->_parser->command()]; $subcommands = $this->_parser->subcommands(); if (!empty($subcommands)) { $usage[] = '<subcommand>'; } $options = []; foreach ($this->_parser->options() as $option) { $options[] = $option->usage(); } if (count($options) > $this->_maxOptions) { $options = ['[options]']; } $usage = array_merge($usage, $options); $args = []; foreach ($this->_parser->arguments() as $argument) { $args[] = $argument->usage(); } if (count($args) > $this->_maxArgs) { $args = ['[arguments]']; } $usage = array_merge($usage, $args); return implode(' ', $usage); }