Exemple #1
0
 /**
  * 添加一个command
  * 
  * @param CommandInterface $command
  */
 function addCommand(CommandInterface $command)
 {
     $command->setConsole($this);
     $this->commands[$command->getName()] = $command;
 }
Exemple #2
0
 /**
  * 获取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);
 }