vendor/symfony/src/Symfony/Component/Console/Command/HelpCommand.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony package.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    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  * HelpCommand displays the help for a given command.
       
    23  *
       
    24  * @author Fabien Potencier <fabien@symfony.com>
       
    25  */
       
    26 class HelpCommand extends Command
       
    27 {
       
    28     private $command;
       
    29 
       
    30     /**
       
    31      * {@inheritdoc}
       
    32      */
       
    33     protected function configure()
       
    34     {
       
    35         $this->ignoreValidationErrors = true;
       
    36 
       
    37         $this
       
    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             ->setName('help')
       
    43             ->setDescription('Displays help for a command')
       
    44             ->setHelp(<<<EOF
       
    45 The <info>help</info> command displays help for a given command:
       
    46 
       
    47   <info>php app/console help list</info>
       
    48 
       
    49 You can also output the help as XML by using the <comment>--xml</comment> option:
       
    50 
       
    51   <info>php app/console help --xml list</info>
       
    52 EOF
       
    53             );
       
    54     }
       
    55 
       
    56     /**
       
    57      * Sets the command
       
    58      *
       
    59      * @param Command $command The command to set
       
    60      */
       
    61     public function setCommand(Command $command)
       
    62     {
       
    63         $this->command = $command;
       
    64     }
       
    65 
       
    66     /**
       
    67      * {@inheritdoc}
       
    68      */
       
    69     protected function execute(InputInterface $input, OutputInterface $output)
       
    70     {
       
    71         if (null === $this->command) {
       
    72             $this->command = $this->getApplication()->get($input->getArgument('command_name'));
       
    73         }
       
    74 
       
    75         if ($input->getOption('xml')) {
       
    76             $output->writeln($this->command->asXml(), OutputInterface::OUTPUT_RAW);
       
    77         } else {
       
    78             $output->writeln($this->command->asText());
       
    79         }
       
    80     }
       
    81 }