Skip to content

Commit

Permalink
global commands are always first in command list
Browse files Browse the repository at this point in the history
  • Loading branch information
spdionis authored and fabpot committed Oct 5, 2015
1 parent 2455b69 commit 70f2b3e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Expand Up @@ -134,15 +134,17 @@ private function inspectApplication()
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);
Expand Down
32 changes: 32 additions & 0 deletions src/Symfony/Component/Console/Tests/Command/ListCommandTest.php
Expand Up @@ -61,4 +61,36 @@ public function testExecuteListsCommandsWithNamespaceArgument()

$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)));
}
}
13 changes: 13 additions & 0 deletions src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php
@@ -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>');
}

}

0 comments on commit 70f2b3e

Please sign in to comment.