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