/**
  * Describe a command detail.
  *
  * @param   AbstractCommand  $command  The command to described.
  *
  * @return  string  Return the described text.
  *
  * @throws  \RuntimeException
  *
  * @since  1.0
  */
 public function describe(AbstractCommand $command)
 {
     // Describe Options
     $options = $command->getAllOptions();
     $optionDescriptor = $this->getOptionDescriptor();
     foreach ($options as $option) {
         $optionDescriptor->addItem($option);
     }
     $render['option'] = count($options) ? "\n\nOptions:\n\n" . $optionDescriptor->render() : '';
     // Describe Commands
     $commands = $command->getChildren();
     $commandDescriptor = $this->getCommandDescriptor();
     foreach ($commands as $cmd) {
         $commandDescriptor->addItem($cmd);
     }
     $render['command'] = count($commands) ? "\nAvailable commands:\n\n" . $commandDescriptor->render() : '';
     // Render Help template
     /** @var Console $console */
     $console = $command->getApplication();
     if (!$console instanceof Console) {
         throw new \RuntimeException(sprintf('Help descriptor need Console object in %s command.', get_class($command)));
     }
     $consoleName = $console->getName();
     $version = $console->getVersion();
     $commandName = $command->getName();
     $description = $command->getDescription();
     $usage = $command->getUsage();
     $help = $command->getHelp();
     // Clean line indent of description
     $description = explode("\n", $description);
     foreach ($description as &$line) {
         $line = trim($line);
     }
     $description = implode("\n", $description);
     $description = $description ? $description . "\n" : '';
     $template = sprintf($this->template, $consoleName, $version, $commandName, $description, $usage, $help);
     return str_replace(array('{OPTIONS}', '{COMMANDS}'), $render, $template);
 }
Example #2
0
 /**
  * Register default command.
  *
  * @return  Console  Return this object to support chaining.
  *
  * @since  1.0
  */
 public function registerRootCommand()
 {
     $this->rootCommand = new RootCommand(null, $this->input, $this->output);
     $this->rootCommand->setApplication($this)->addCommand(new HelpCommand());
     return $this;
 }