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