Lines Matching defs:command
8 * Parses command line options passed to the CLI script. Allows CLI scripts to easily register all accepted options and
22 /** @var string current parsed command if any */
23 protected $command = '';
56 'commandhelp' => 'This tool accepts a command as first parameter as outlined below:'
58 ); // default command
112 * @param string $command if theses apply to a sub command only
115 public function registerArgument($arg, $help, $required = true, $command = '')
117 if (!isset($this->setup[$command])) {
118 throw new Exception("Command $command not registered");
121 $this->setup[$command]['args'][] = array(
129 * This registers a sub command
133 * @param string $command
137 public function registerCommand($command, $help)
139 if (isset($this->setup[$command])) {
140 throw new Exception("Command $command already registered");
143 $this->setup[$command] = array(
158 * @param string $command what command does this option apply to
161 public function registerOption($long, $help, $short = null, $needsarg = false, $command = '')
163 if (!isset($this->setup[$command])) {
164 throw new Exception("Command $command not registered");
167 $this->setup[$command]['opts'][$long] = array(
178 $this->setup[$command]['short'][$short] = $long;
196 foreach ($this->setup[$this->command]['args'] as $arg) {
209 * Parses the given arguments for known options and command
212 * array is stripped from any options and possible command. All found otions can be accessed via the
215 * Note that command options will overwrite any global options with the same name
254 if (!isset($this->setup[$this->command]['opts'][$opt])) {
259 if ($this->setup[$this->command]['opts'][$opt]['needsarg']) {
277 if (!isset($this->setup[$this->command]['short'][$opt])) {
280 $opt = $this->setup[$this->command]['short'][$opt]; // store it under long name
284 if ($this->setup[$this->command]['opts'][$opt]['needsarg']) {
302 // if not done yet, check if first argument is a command and reexecute argument parsing if it is
303 if (!$this->command && $this->args && isset($this->setup[$this->args[0]])) {
304 // it is a command!
305 $this->command = array_shift($this->args);
335 * Return the found command if any
341 return $this->command;
371 foreach ($this->setup as $command => $config) {
372 $hasopts = (bool)$this->setup[$command]['opts'];
373 $hasargs = (bool)$this->setup[$command]['args'];
375 // usage or command syntax line
376 if (!$command) {
383 $text .= $this->colors->wrap(' ' . $command, Colors::C_PURPLE);
391 if (!$command && $hascommands) {
395 foreach ($this->setup[$command]['args'] as $arg) {
405 // usage or command intro
406 if ($this->setup[$command]['help']) {
410 array('', $this->setup[$command]['help'] . $this->newline)
416 if (!$command) {
421 foreach ($this->setup[$command]['opts'] as $long => $opt) {
447 if (!$command) {
452 foreach ($this->setup[$command]['args'] as $arg) {
463 // head line and intro for following command documentation
464 if (!$command && $hascommands) {