global commands are always first in command list

This commit is contained in:
spdionis 2014-11-18 02:17:03 +02:00 committed by Fabien Potencier
parent 2455b69bf9
commit 70f2b3eb8c
3 changed files with 50 additions and 3 deletions

View File

@ -134,15 +134,17 @@ class ApplicationDescription
private function sortCommands(array $commands)
{
$namespacedCommands = array();
$globalCommands = array();
foreach ($commands as $name => $command) {
$key = $this->application->extractNamespace($name, 1);
if (!$key) {
$key = '_global';
$globalCommands['_global'][$name] = $command;
} else {
$namespacedCommands[$key][$name] = $command;
}
$namespacedCommands[$key][$name] = $command;
}
ksort($namespacedCommands);
$namespacedCommands = array_merge($globalCommands, $namespacedCommands);
foreach ($namespacedCommands as &$commandsSet) {
ksort($commandsSet);

View File

@ -61,4 +61,36 @@ EOF;
$this->assertEquals($output, $commandTester->getDisplay(true));
}
public function testExecuteListsCommandsNameAndNamespaceRaw()
{
require_once realpath(__DIR__.'/../Fixtures/Foo6Command.php');
$application = new Application();
$application->add(new \Foo6Command());
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(array('command' => $command->getName()));
$output = <<<EOF
Console Tool
Usage:
[options] command [arguments]
Options:
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.
--version (-V) Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction (-n) Do not ask any interactive question.
Available commands:
help Displays help for a command
list Lists commands
<fg=blue>foo
<fg=blue>foo:bar</fg=blue>
EOF;
$this->assertEquals($output, trim($commandTester->getDisplay(true)));
}
}

View File

@ -0,0 +1,13 @@
<?php
use Symfony\Component\Console\Command\Command;
class Foo6Command extends Command
{
protected function configure()
{
$this->setName('<fg=blue>foo:bar</fg=blue>');
}
}