Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Console\Command; Chris@0: Chris@0: use Symfony\Component\Console\Helper\DescriptorHelper; Chris@0: use Symfony\Component\Console\Input\InputArgument; Chris@17: use Symfony\Component\Console\Input\InputInterface; Chris@0: use Symfony\Component\Console\Input\InputOption; Chris@0: use Symfony\Component\Console\Output\OutputInterface; Chris@0: Chris@0: /** Chris@0: * HelpCommand displays the help for a given command. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class HelpCommand extends Command Chris@0: { Chris@0: private $command; Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function configure() Chris@0: { Chris@0: $this->ignoreValidationErrors(); Chris@0: Chris@0: $this Chris@0: ->setName('help') Chris@17: ->setDefinition([ Chris@0: new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'), Chris@0: new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'), Chris@0: new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'), Chris@17: ]) Chris@0: ->setDescription('Displays help for a command') Chris@0: ->setHelp(<<<'EOF' Chris@0: The %command.name% command displays help for a given command: Chris@0: Chris@0: php %command.full_name% list Chris@0: Chris@0: You can also output the help in other formats by using the --format option: Chris@0: Chris@0: php %command.full_name% --format=xml list Chris@0: Chris@0: To display the list of available commands, please use the list command. Chris@0: EOF Chris@0: ) Chris@0: ; Chris@0: } Chris@0: Chris@0: public function setCommand(Command $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 (null === $this->command) { Chris@0: $this->command = $this->getApplication()->find($input->getArgument('command_name')); Chris@0: } Chris@0: Chris@0: $helper = new DescriptorHelper(); Chris@17: $helper->describe($output, $this->command, [ Chris@0: 'format' => $input->getOption('format'), Chris@0: 'raw_text' => $input->getOption('raw'), Chris@17: ]); Chris@0: Chris@0: $this->command = null; Chris@0: } Chris@0: }