Chris@0: setName('help')
Chris@0: ->setAliases(array('?'))
Chris@0: ->setDefinition(array(
Chris@0: new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', null),
Chris@0: ))
Chris@0: ->setDescription('Show a list of commands. Type `help [foo]` for information about [foo].')
Chris@0: ->setHelp('My. How meta.');
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Helper for setting a subcommand to retrieve help for.
Chris@0: *
Chris@0: * @param Command $command
Chris@0: */
Chris@0: public function setCommand($command)
Chris@0: {
Chris@0: $this->command = $command;
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * {@inheritdoc}
Chris@0: */
Chris@0: protected function execute(InputInterface $input, OutputInterface $output)
Chris@0: {
Chris@0: if ($this->command !== null) {
Chris@0: // help for an individual command
Chris@0: $output->page($this->command->asText());
Chris@0: $this->command = null;
Chris@0: } elseif ($name = $input->getArgument('command_name')) {
Chris@0: // help for an individual command
Chris@0: $output->page($this->getApplication()->get($name)->asText());
Chris@0: } else {
Chris@0: // list available commands
Chris@0: $commands = $this->getApplication()->all();
Chris@0:
Chris@0: $table = $this->getTable($output);
Chris@0:
Chris@0: foreach ($commands as $name => $command) {
Chris@0: if ($name !== $command->getName()) {
Chris@0: continue;
Chris@0: }
Chris@0:
Chris@0: if ($command->getAliases()) {
Chris@0: $aliases = sprintf('Aliases: %s', implode(', ', $command->getAliases()));
Chris@0: } else {
Chris@0: $aliases = '';
Chris@0: }
Chris@0:
Chris@0: $table->addRow(array(
Chris@0: sprintf('%s', $name),
Chris@0: $command->getDescription(),
Chris@0: $aliases,
Chris@0: ));
Chris@0: }
Chris@0:
Chris@0: $output->startPaging();
Chris@0: if ($table instanceof TableHelper) {
Chris@0: $table->render($output);
Chris@0: } else {
Chris@0: $table->render();
Chris@0: }
Chris@0: $output->stopPaging();
Chris@0: }
Chris@0: }
Chris@0: }