Skip to content

Commit 70f2b3e

Browse files
spdionisfabpot
authored andcommitted
global commands are always first in command list
1 parent 2455b69 commit 70f2b3e

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

src/Symfony/Component/Console/Descriptor/ApplicationDescription.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,17 @@ private function inspectApplication()
134134
private function sortCommands(array $commands)
135135
{
136136
$namespacedCommands = array();
137+
$globalCommands = array();
137138
foreach ($commands as $name => $command) {
138139
$key = $this->application->extractNamespace($name, 1);
139140
if (!$key) {
140-
$key = '_global';
141+
$globalCommands['_global'][$name] = $command;
142+
} else {
143+
$namespacedCommands[$key][$name] = $command;
141144
}
142-
143-
$namespacedCommands[$key][$name] = $command;
144145
}
145146
ksort($namespacedCommands);
147+
$namespacedCommands = array_merge($globalCommands, $namespacedCommands);
146148

147149
foreach ($namespacedCommands as &$commandsSet) {
148150
ksort($commandsSet);

src/Symfony/Component/Console/Tests/Command/ListCommandTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,36 @@ public function testExecuteListsCommandsWithNamespaceArgument()
6161

6262
$this->assertEquals($output, $commandTester->getDisplay(true));
6363
}
64+
65+
public function testExecuteListsCommandsNameAndNamespaceRaw()
66+
{
67+
require_once realpath(__DIR__.'/../Fixtures/Foo6Command.php');
68+
$application = new Application();
69+
$application->add(new \Foo6Command());
70+
$commandTester = new CommandTester($command = $application->get('list'));
71+
$commandTester->execute(array('command' => $command->getName()));
72+
$output = <<<EOF
73+
Console Tool
74+
75+
Usage:
76+
[options] command [arguments]
77+
78+
Options:
79+
--help (-h) Display this help message.
80+
--quiet (-q) Do not output any message.
81+
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.
82+
--version (-V) Display this application version.
83+
--ansi Force ANSI output.
84+
--no-ansi Disable ANSI output.
85+
--no-interaction (-n) Do not ask any interactive question.
86+
87+
Available commands:
88+
help Displays help for a command
89+
list Lists commands
90+
<fg=blue>foo
91+
<fg=blue>foo:bar</fg=blue>
92+
EOF;
93+
94+
$this->assertEquals($output, trim($commandTester->getDisplay(true)));
95+
}
6496
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
4+
use Symfony\Component\Console\Command\Command;
5+
6+
class Foo6Command extends Command
7+
{
8+
protected function configure()
9+
{
10+
$this->setName('<fg=blue>foo:bar</fg=blue>');
11+
}
12+
13+
}

0 commit comments

Comments
 (0)