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\InputDefinition; 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: * ListCommand displays the list of all available commands for the application. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class ListCommand extends Command Chris@0: { Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function configure() Chris@0: { Chris@0: $this Chris@0: ->setName('list') Chris@0: ->setDefinition($this->createDefinition()) Chris@0: ->setDescription('Lists commands') Chris@0: ->setHelp(<<<'EOF' Chris@0: The %command.name% command lists all commands: Chris@0: Chris@0: php %command.full_name% Chris@0: Chris@0: You can also display the commands for a specific namespace: Chris@0: Chris@0: php %command.full_name% test Chris@0: Chris@0: You can also output the information in other formats by using the --format option: Chris@0: Chris@0: php %command.full_name% --format=xml Chris@0: Chris@0: It's also possible to get raw list of commands (useful for embedding command runner): Chris@0: Chris@0: php %command.full_name% --raw Chris@0: EOF Chris@0: ) Chris@0: ; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getNativeDefinition() Chris@0: { Chris@0: return $this->createDefinition(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function execute(InputInterface $input, OutputInterface $output) Chris@0: { Chris@0: $helper = new DescriptorHelper(); Chris@17: $helper->describe($output, $this->getApplication(), [ Chris@0: 'format' => $input->getOption('format'), Chris@0: 'raw_text' => $input->getOption('raw'), Chris@0: 'namespace' => $input->getArgument('namespace'), Chris@17: ]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: private function createDefinition() Chris@0: { Chris@17: return new InputDefinition([ Chris@0: new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), Chris@0: new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), Chris@0: new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'), Chris@17: ]); Chris@0: } Chris@0: }