/** * @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) { $arguments = $command->getArguments(); if (count($arguments) === 0) { return; } $table = new TableWidget($this->input, $this->output); $table->setTitle("<header>Arguments:</header>"); foreach ($arguments as $argument) { $name = $argument->getName(); $description = $argument->getDescription(); if ($argument->isRequired()) { if ($argument->isMultiple()) { $name = "\\<{$name}...>"; } else { $name = "\\<{$name}>"; } } else { if ($argument->isMultiple()) { $name = "\\<{$name}... ?>"; } else { $name = "\\<{$name} ?>"; } } $table->addRow("<keyword>{$name}</keyword>", $description); } $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; }