/** * 添加一个command * * @param CommandInterface $command */ function addCommand(CommandInterface $command) { $command->setConsole($this); $this->commands[$command->getName()] = $command; }
/** * 获取command的usage信息 * * @param CommandInterface $command * @return string */ protected function getCommandUsage(CommandInterface $command) { $argumentsUsages = []; foreach ($command->getDefinition()->getArguments() as $argument) { $usage = "<{$argument->getName()}>"; if ($argument->isValueOptional()) { $usage = "[{$usage}]"; } $argumentsUsages[] = $usage; } $usages[] = $command->getName(); $options = $command->getDefinition()->getOptions(); if ($haveOptions = !empty($options)) { $usages[] = '[options]'; } if (!empty($argumentsUsages)) { if ($haveOptions) { $usages[] = '--'; } $usages[] = implode(' ', $argumentsUsages); } return implode(' ', $usages); }