think\console\Command::mergeConsoleDefinition PHP Method

mergeConsoleDefinition() public method

合并参数定义
public mergeConsoleDefinition ( boolean $mergeArgs = true )
$mergeArgs boolean
    public function mergeConsoleDefinition($mergeArgs = true)
    {
        if (null === $this->console || true === $this->consoleDefinitionMerged && ($this->consoleDefinitionMergedWithArgs || !$mergeArgs)) {
            return;
        }
        if ($mergeArgs) {
            $currentArguments = $this->definition->getArguments();
            $this->definition->setArguments($this->console->getDefinition()->getArguments());
            $this->definition->addArguments($currentArguments);
        }
        $this->definition->addOptions($this->console->getDefinition()->getOptions());
        $this->consoleDefinitionMerged = true;
        if ($mergeArgs) {
            $this->consoleDefinitionMergedWithArgs = true;
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 描述指令
  * @param Command $command
  * @param array   $options
  * @return string|mixed
  */
 protected function describeCommand(Command $command, array $options = [])
 {
     $command->getSynopsis(true);
     $command->getSynopsis(false);
     $command->mergeConsoleDefinition(false);
     $this->writeText('<comment>Usage:</comment>', $options);
     foreach (array_merge([$command->getSynopsis(true)], $command->getAliases(), $command->getUsages()) as $usage) {
         $this->writeText("\n");
         $this->writeText('  ' . $usage, $options);
     }
     $this->writeText("\n");
     $definition = $command->getNativeDefinition();
     if ($definition->getOptions() || $definition->getArguments()) {
         $this->writeText("\n");
         $this->describeInputDefinition($definition, $options);
         $this->writeText("\n");
     }
     if ($help = $command->getProcessedHelp()) {
         $this->writeText("\n");
         $this->writeText('<comment>Help:</comment>', $options);
         $this->writeText("\n");
         $this->writeText(' ' . str_replace("\n", "\n ", $help), $options);
         $this->writeText("\n");
     }
 }