2010-01-04 14:42:28 +00:00
< ? php
2011-01-15 13:29:43 +00:00
/*
* This file is part of the Symfony package .
*
2011-03-06 11:40:06 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . com >
2011-01-15 13:29:43 +00:00
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2010-08-20 22:09:55 +01:00
namespace Symfony\Component\Console\Command ;
2010-01-04 14:42:28 +00:00
2013-03-22 13:40:47 +00:00
use Symfony\Component\Console\Helper\DescriptorHelper ;
2010-08-20 22:09:55 +01:00
use Symfony\Component\Console\Input\InputArgument ;
use Symfony\Component\Console\Input\InputOption ;
use Symfony\Component\Console\Input\InputInterface ;
use Symfony\Component\Console\Output\OutputInterface ;
2012-03-12 00:11:44 +00:00
use Symfony\Component\Console\Input\InputDefinition ;
2010-01-04 14:42:28 +00:00
/**
2010-01-04 18:51:21 +00:00
* ListCommand displays the list of all available commands for the application .
2010-01-04 14:42:28 +00:00
*
2011-03-06 11:40:06 +00:00
* @ author Fabien Potencier < fabien @ symfony . com >
2010-01-04 14:42:28 +00:00
*/
2010-01-04 18:51:21 +00:00
class ListCommand extends Command
2010-01-04 14:42:28 +00:00
{
2010-05-06 12:25:53 +01:00
/**
2011-02-07 00:34:24 +00:00
* { @ inheritdoc }
2010-05-06 12:25:53 +01:00
*/
protected function configure ()
{
$this
-> setName ( 'list' )
2012-02-12 15:37:55 +00:00
-> setDefinition ( $this -> createDefinition ())
2010-05-06 12:25:53 +01:00
-> setDescription ( 'Lists commands' )
2015-12-21 11:01:57 +00:00
-> setHelp ( <<< 'EOF'
2012-02-12 15:37:55 +00:00
The < info >% command . name %</ info > command lists all commands :
2010-01-04 14:42:28 +00:00
2012-02-12 15:37:55 +00:00
< info > php % command . full_name %</ info >
2010-01-04 14:42:28 +00:00
2010-01-04 18:51:21 +00:00
You can also display the commands for a specific namespace :
2010-01-04 14:42:28 +00:00
2012-02-12 15:37:55 +00:00
< info > php % command . full_name % test </ info >
2010-01-04 14:42:28 +00:00
2013-03-22 13:40:47 +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
2013-03-22 13:40:47 +00:00
< info > php % command . full_name % -- format = xml </ info >
2011-12-17 23:19:10 +00:00
It ' s also possible to get raw list of commands ( useful for embedding command runner ) :
2012-02-12 15:37:55 +00:00
< info > php % command . full_name % -- raw </ info >
2010-01-04 14:42:28 +00:00
EOF
2012-02-12 15:37:55 +00:00
)
;
2010-01-04 14:42:28 +00:00
}
2010-05-06 12:25:53 +01:00
2012-03-12 00:11:44 +00:00
/**
* { @ inheritdoc }
*/
2013-03-22 13:40:47 +00:00
public function getNativeDefinition ()
2012-03-12 00:11:44 +00:00
{
return $this -> createDefinition ();
}
2010-05-06 12:25:53 +01:00
/**
2011-02-07 00:34:24 +00:00
* { @ inheritdoc }
2010-05-06 12:25:53 +01:00
*/
protected function execute ( InputInterface $input , OutputInterface $output )
2010-01-04 14:42:28 +00:00
{
2010-05-07 15:09:11 +01:00
if ( $input -> getOption ( 'xml' )) {
2015-06-07 07:33:05 +01:00
@ trigger_error ( 'The --xml option was deprecated in version 2.7 and will be removed in version 3.0. Use the --format option instead.' , E_USER_DEPRECATED );
2015-05-16 14:23:52 +01:00
2013-03-22 13:40:47 +00:00
$input -> setOption ( 'format' , 'xml' );
2010-05-06 12:25:53 +01:00
}
2013-03-22 13:40:47 +00:00
$helper = new DescriptorHelper ();
2013-07-08 20:00:49 +01:00
$helper -> describe ( $output , $this -> getApplication (), array (
2014-10-30 20:17:55 +00:00
'format' => $input -> getOption ( 'format' ),
'raw_text' => $input -> getOption ( 'raw' ),
2013-07-08 20:00:49 +01:00
'namespace' => $input -> getArgument ( 'namespace' ),
));
2010-01-04 14:42:28 +00:00
}
2012-03-12 00:11:44 +00:00
2013-03-22 13:40:47 +00:00
/**
* { @ inheritdoc }
*/
2012-03-12 00:11:44 +00:00
private function createDefinition ()
{
return new InputDefinition ( array (
new InputArgument ( 'namespace' , InputArgument :: OPTIONAL , 'The namespace name' ),
2013-03-22 13:40:47 +00:00
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' ),
2015-05-16 14:21:12 +01:00
new InputOption ( 'format' , null , InputOption :: VALUE_REQUIRED , 'The output format (txt, xml, json, or md)' , 'txt' ),
2012-03-12 00:11:44 +00:00
));
}
2010-01-04 14:42:28 +00:00
}