getDefinition() 공개 메소드

获取输入参数定义
public getDefinition ( ) : Definition
리턴 think\console\input\Definition The InputDefinition instance
예제 #1
0
 /**
  * 合并参数定义
  * @param bool $mergeArgs
  */
 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;
     }
 }
예제 #2
0
 /**
  * 描述控制台
  * @param Console $console
  * @param array   $options
  * @return string|mixed
  */
 protected function describeConsole(Console $console, array $options = [])
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ConsoleDescription($console, $describedNamespace);
     if (isset($options['raw_text']) && $options['raw_text']) {
         $width = $this->getColumnWidth($description->getCommands());
         foreach ($description->getCommands() as $command) {
             $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
             $this->writeText("\n");
         }
     } else {
         if ('' != ($help = $console->getHelp())) {
             $this->writeText("{$help}\n\n", $options);
         }
         $this->writeText("<comment>Usage:</comment>\n", $options);
         $this->writeText("  command [options] [arguments]\n\n", $options);
         $this->describeInputDefinition(new InputDefinition($console->getDefinition()->getOptions()), $options);
         $this->writeText("\n");
         $this->writeText("\n");
         $width = $this->getColumnWidth($description->getCommands());
         if ($describedNamespace) {
             $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
         } else {
             $this->writeText('<comment>Available commands:</comment>', $options);
         }
         // add commands by namespace
         foreach ($description->getNamespaces() as $namespace) {
             if (!$describedNamespace && ConsoleDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                 $this->writeText("\n");
                 $this->writeText(' <comment>' . $namespace['id'] . '</comment>', $options);
             }
             foreach ($namespace['commands'] as $name) {
                 $this->writeText("\n");
                 $spacingWidth = $width - strlen($name);
                 $this->writeText(sprintf("  <info>%s</info>%s%s", $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
             }
         }
         $this->writeText("\n");
     }
 }