This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Console/Command/ListCommand.php

96 lines
2.7 KiB
PHP
Raw Normal View History

2010-01-04 14:42:28 +00:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Command;
2010-01-04 14:42:28 +00:00
use Symfony\Component\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputDefinition;
2010-01-04 14:42:28 +00:00
/**
* ListCommand displays the list of all available commands for the application.
2010-01-04 14:42:28 +00:00
*
* @author Fabien Potencier <fabien@symfony.com>
2010-01-04 14:42:28 +00:00
*/
class ListCommand extends Command
2010-01-04 14:42:28 +00:00
{
/**
2011-02-07 00:34:24 +00:00
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('list')
->setDefinition($this->createDefinition())
->setDescription('Lists commands')
->setHelp(<<<EOF
The <info>%command.name%</info> command lists all commands:
2010-01-04 14:42:28 +00:00
<info>php %command.full_name%</info>
2010-01-04 14:42:28 +00:00
You can also display the commands for a specific namespace:
2010-01-04 14:42:28 +00:00
<info>php %command.full_name% test</info>
2010-01-04 14:42:28 +00:00
You can also output the information in other formats by using the <comment>--format</comment> option:
2010-01-04 14:42:28 +00:00
<info>php %command.full_name% --format=xml</info>
It's also possible to get raw list of commands (useful for embedding command runner):
<info>php %command.full_name% --raw</info>
2010-01-04 14:42:28 +00:00
EOF
)
;
2010-01-04 14:42:28 +00:00
}
/**
* {@inheritdoc}
*/
public function getNativeDefinition()
{
return $this->createDefinition();
}
/**
2011-02-07 00:34:24 +00:00
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
2010-01-04 14:42:28 +00:00
{
if ($input->getOption('xml')) {
$input->setOption('format', 'xml');
}
$helper = new DescriptorHelper();
$helper->describe($output, $this->getApplication(), array(
2014-10-30 20:17:55 +00:00
'format' => $input->getOption('format'),
'raw_text' => $input->getOption('raw'),
'namespace' => $input->getArgument('namespace'),
));
2010-01-04 14:42:28 +00:00
}
/**
* {@inheritdoc}
*/
private function createDefinition()
{
return new InputDefinition(array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output list as XML'),
2012-03-15 14:47:03 +00:00
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats', 'txt'),
));
}
2010-01-04 14:42:28 +00:00
}