Raw output of commands in app/console list
This commit is contained in:
parent
be4e5388ef
commit
5f98b73e7c
@ -622,12 +622,17 @@ class Application
|
||||
* Returns a text representation of the Application.
|
||||
*
|
||||
* @param string $namespace An optional namespace name
|
||||
* @param boolean $raw Whether to return raw command list
|
||||
*
|
||||
* @return string A string representing the Application
|
||||
*/
|
||||
public function asText($namespace = null)
|
||||
public function asText($namespace = null, $raw = false)
|
||||
{
|
||||
$commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
|
||||
|
||||
if($raw) {
|
||||
return array_keys($commands);
|
||||
}
|
||||
|
||||
$messages = array($this->getHelp(), '');
|
||||
if ($namespace) {
|
||||
|
@ -34,6 +34,7 @@ class ListCommand extends Command
|
||||
->setDefinition(array(
|
||||
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
|
||||
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
|
||||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list')
|
||||
))
|
||||
->setName('list')
|
||||
->setDescription('Lists commands')
|
||||
@ -49,6 +50,10 @@ You can also display the commands for a specific namespace:
|
||||
You can also output the information as XML by using the <comment>--xml</comment> option:
|
||||
|
||||
<info>php app/console list --xml</info>
|
||||
|
||||
It's also possible to get raw list of commands (useful for embedding command runner):
|
||||
|
||||
<info>php app/console list --raw</info>
|
||||
EOF
|
||||
);
|
||||
}
|
||||
@ -61,7 +66,7 @@ EOF
|
||||
if ($input->getOption('xml')) {
|
||||
$output->writeln($this->getApplication()->asXml($input->getArgument('namespace')), OutputInterface::OUTPUT_RAW);
|
||||
} else {
|
||||
$output->writeln($this->getApplication()->asText($input->getArgument('namespace')));
|
||||
$output->writeln($this->getApplication()->asText($input->getArgument('namespace'), $input->getOption('raw')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array());
|
||||
$this->assertRegExp('/list \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
|
||||
$this->assertRegExp('/list \[--xml\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
|
||||
|
||||
$commandTester->execute(array('--xml' => true));
|
||||
$this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
|
||||
@ -33,7 +33,7 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase
|
||||
$application = new Application();
|
||||
$commandTester = new CommandTester($application->get('help'));
|
||||
$commandTester->execute(array('command_name' => 'list'));
|
||||
$this->assertRegExp('/list \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
|
||||
$this->assertRegExp('/list \[--xml\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
|
||||
|
||||
$commandTester->execute(array('command_name' => 'list', '--xml' => true));
|
||||
$this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
|
||||
|
@ -26,5 +26,8 @@ class ListCommandTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$commandTester->execute(array('command' => $command->getName(), '--xml' => true));
|
||||
$this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
|
||||
|
||||
$commandTester->execute(array('command' => $command->getName(), '--raw' => true));
|
||||
$this->assertRegExp('/help\n/', $commandTester->getDisplay(), 'boo');
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
</options>
|
||||
</command>
|
||||
<command id="list" name="list">
|
||||
<usage>list [--xml] [namespace]</usage>
|
||||
<usage>list [--xml] [--raw] [namespace]</usage>
|
||||
<description>Lists commands</description>
|
||||
<help>The <info>list</info> command lists all commands:
|
||||
|
||||
@ -39,7 +39,11 @@
|
||||
|
||||
You can also output the information as XML by using the <comment>--xml</comment> option:
|
||||
|
||||
<info>php app/console list --xml</info></help>
|
||||
<info>php app/console list --xml</info>
|
||||
|
||||
It's also possible to get raw list of commands (useful for embedding command runner):
|
||||
|
||||
<info>php app/console list --raw</info></help>
|
||||
<aliases/>
|
||||
<arguments>
|
||||
<argument name="namespace" is_required="0" is_array="0">
|
||||
@ -51,6 +55,9 @@
|
||||
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>To output help as XML</description>
|
||||
</option>
|
||||
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>To output raw command list</description>
|
||||
</option>
|
||||
</options>
|
||||
</command>
|
||||
<command id="foo:bar" name="foo:bar">
|
||||
|
@ -6,6 +6,6 @@
|
||||
|
||||
|
||||
|
||||
list [--xml] [namespace]
|
||||
list [--xml] [--raw] [namespace]
|
||||
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
Usage:
|
||||
list [--xml] [namespace]
|
||||
list [--xml] [--raw] [namespace]
|
||||
|
||||
Arguments:
|
||||
namespace The namespace name
|
||||
|
||||
Options:
|
||||
--xml To output help as XML
|
||||
--raw To output raw command list
|
||||
|
||||
Help:
|
||||
The list command lists all commands:
|
||||
@ -19,4 +20,8 @@ Help:
|
||||
You can also output the information as XML by using the --xml option:
|
||||
|
||||
php app/console list --xml
|
||||
|
||||
It's also possible to get raw list of commands (useful for embedding command runner):
|
||||
|
||||
php app/console list --raw
|
||||
|
||||
|
Reference in New Issue
Block a user