/** * @param ICommand $command */ public function render(ICommand $command) { $name = $command->getName(); $usage = "{$name} "; if (count($command->getArguments())) { $usage .= $this->getArgumentsUsage($command->getArguments()); } if (count($command->getOptions())) { $usage .= ' ' . $this->getOptionsUsage($command->getOptions()); } $usage = trim($usage); $this->output->writeLine(); $this->output->writeLine("<header>Usage:</header>"); $this->output->writeLineIndented("{$usage}"); }
/** * @param ICommand $command */ public function render(ICommand $command) { $options = $command->getOptions(); if (count($options) === 0) { return; } $table = new TableWidget($this->input, $this->output); $table->setTitle("<header>Options:</header>"); foreach ($options as $option) { $name = $option->getName(); $alias = ' '; if ($option->getAlias()) { $alias = $option->getAlias(); if ($option->isIncremental()) { $alias = s('-:a|:a:a|:a:a:a', [':a' => substr($alias, 1)]); } $alias .= ','; } $table->addRow("<keyword>{$alias} {$name}</keyword>", $option->getDescription()); } $this->output->writeLine(); $table->render(); }
/** * @param ICommand $command * @param array $groupedArgs * @param bool $strict * * @return array * @throws MissingArgumentValueException * @throws TooManyArgumentValuesException * @throws UnknownOptionException */ public function matchCommand(ICommand $command, array $groupedArgs, $strict = true) { foreach ($command->getArguments() as $argument) { $groupedArgs = $this->matchArgument($argument, $groupedArgs, $strict); } $leftoverArgs = array_get($groupedArgs, 'arguments', []); if (is_array($leftoverArgs) && count($leftoverArgs) > 0 && $strict) { throw new TooManyArgumentValuesException(s('Too many arguments, remove: %s.', implode(', ', $leftoverArgs))); } $foundOptions = ['arguments', 'options']; foreach ($command->getOptions() as $option) { $groupedArgs = $this->matchOption($option, $groupedArgs, $strict); $foundOptions[] = $option->getNameOrAlias(); } if ($strict) { foreach ($groupedArgs as $key => $arg) { if (!array_contains($foundOptions, $key)) { throw new UnknownOptionException(s('Invalid option "%s".', $key)); } } } return $groupedArgs; }