diff options
Diffstat (limited to 'vendor/symfony/console/Command/ListCommand.php')
-rw-r--r-- | vendor/symfony/console/Command/ListCommand.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/symfony/console/Command/ListCommand.php b/vendor/symfony/console/Command/ListCommand.php new file mode 100644 index 0000000..61b4b1b --- /dev/null +++ b/vendor/symfony/console/Command/ListCommand.php | |||
@@ -0,0 +1,72 @@ | |||
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\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 <fabien@symfony.com> | ||
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', 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 <comment>--format</comment> 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 | } | ||