1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\Console\Command;
13:
14: use Symfony\Component\Console\Input\InputArgument;
15: use Symfony\Component\Console\Input\InputOption;
16: use Symfony\Component\Console\Input\InputInterface;
17: use Symfony\Component\Console\Output\OutputInterface;
18: use Symfony\Component\Console\Output\Output;
19: use Symfony\Component\Console\Command\Command;
20:
21: 22: 23: 24: 25:
26: class HelpCommand extends Command
27: {
28: private $command;
29:
30: 31: 32:
33: protected function configure()
34: {
35: $this->ignoreValidationErrors();
36:
37: $this
38: ->setName('help')
39: ->setDefinition(array(
40: new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
41: new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
42: ))
43: ->setDescription('Displays help for a command')
44: ->setHelp(<<<EOF
45: The <info>%command.name%</info> command displays help for a given command:
46:
47: <info>php %command.full_name% list</info>
48:
49: You can also output the help as XML by using the <comment>--xml</comment> option:
50:
51: <info>php %command.full_name% --xml list</info>
52: EOF
53: )
54: ;
55: }
56:
57: /**
58: * Sets the command
59: *
60: * @param Command $command The command to set
61: */
62: public function setCommand(Command $command)
63: {
64: $this->command = $command;
65: }
66:
67: /**
68: * {@inheritdoc}
69: */
70: protected function execute(InputInterface $input, OutputInterface $output)
71: {
72: if (null === $this->command) {
73: $this->command = $this->getApplication()->get($input->getArgument('command_name'));
74: }
75:
76: if ($input->getOption('xml')) {
77: $output->writeln($this->command->asXml(), OutputInterface::OUTPUT_RAW);
78: } else {
79: $output->writeln($this->command->asText());
80: }
81:
82: $this->command = null;
83: }
84: }
85: