Example #1
0
 /**
  * Register default command.
  *
  * @return  Console  Return this object to support chaining.
  *
  * @since  2.0
  */
 public function registerRootCommand()
 {
     if ($this->rootCommand) {
         return $this;
     }
     $this->rootCommand = new RootCommand(null, $this->io);
     $this->rootCommand->setApplication($this);
     $this->description ? $this->rootCommand->description($this->description) : null;
     $this->help ? $this->rootCommand->help($this->help) : null;
     return $this;
 }
 /**
  * Describe a command detail.
  *
  * @param   AbstractCommand  $command  The command to described.
  *
  * @return  string  Return the described text.
  *
  * @throws  \RuntimeException
  *
  * @since  2.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) ? "\nCommands:\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 #3
0
 /**
  * Get option from input.
  *
  * @param string $name    Option name.
  * @param string $default Default if not found.
  *
  * @return  mixed
  */
 public function getOption($name, $default = null)
 {
     return $this->command->getOption($name, $default);
 }
 /**
  * Constructor
  */
 function __construct()
 {
     parent::__construct('foo');
 }