Debian Codegraph @

vendor/symfony/console/Command/ListCommand.php

raw
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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\Descriptor\ApplicationDescription;
15 use Symfony\Component\Console\Helper\DescriptorHelper;
16 use Symfony\Component\Console\Input\InputArgument;
17 use Symfony\Component\Console\Input\InputInterface;
18 use Symfony\Component\Console\Input\InputOption;
19 use Symfony\Component\Console\Output\OutputInterface;
20
21 /**
22 * ListCommand displays the list of all available commands for the application.
23 *
24 * @author Fabien Potencier <[email protected]>
25 */
26 class ListCommand extends Command
27 {
28 protected function configure(): void
29 {
30 $this
31 ->setName('list')
32 ->setDefinition([
33 new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name', null, fn () => array_keys((new ApplicationDescription($this->getApplication()))->getNamespaces())),
34 new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
35 new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', static fn () => (new DescriptorHelper())->getFormats()),
36 new InputOption('short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments'),
37 ])
38 ->setDescription('List commands')
39 ->setHelp(<<<'EOF'
40 The <info>%command.name%</info> command lists all commands:
41
42 <info>%command.full_name%</info>
43
44 You can also display the commands for a specific namespace:
45
46 <info>%command.full_name% test</info>
47
48 You can also output the information in other formats by using the <info>--format</info> option:
49
50 <info>%command.full_name% --format=xml</info>
51
52 It's also possible to get raw list of commands (useful for embedding command runner):
53
54 <info>%command.full_name% --raw</info>
55 EOF
56 )
57 ;
58 }
59
60 protected function execute(InputInterface $input, OutputInterface $output): int
61 {
62 $helper = new DescriptorHelper();
63 $helper->describe($output, $this->getApplication(), [
64 'format' => $input->getOption('format'),
65 'raw_text' => $input->getOption('raw'),
66 'namespace' => $input->getArgument('namespace'),
67 'short' => $input->getOption('short'),
68 ]);
69
70 return 0;
71 }
72 }