global commands are always first in command list
This commit is contained in:
parent
2455b69bf9
commit
70f2b3eb8c
@ -134,15 +134,17 @@ class ApplicationDescription
|
|||||||
private function sortCommands(array $commands)
|
private function sortCommands(array $commands)
|
||||||
{
|
{
|
||||||
$namespacedCommands = array();
|
$namespacedCommands = array();
|
||||||
|
$globalCommands = array();
|
||||||
foreach ($commands as $name => $command) {
|
foreach ($commands as $name => $command) {
|
||||||
$key = $this->application->extractNamespace($name, 1);
|
$key = $this->application->extractNamespace($name, 1);
|
||||||
if (!$key) {
|
if (!$key) {
|
||||||
$key = '_global';
|
$globalCommands['_global'][$name] = $command;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
$namespacedCommands[$key][$name] = $command;
|
$namespacedCommands[$key][$name] = $command;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ksort($namespacedCommands);
|
ksort($namespacedCommands);
|
||||||
|
$namespacedCommands = array_merge($globalCommands, $namespacedCommands);
|
||||||
|
|
||||||
foreach ($namespacedCommands as &$commandsSet) {
|
foreach ($namespacedCommands as &$commandsSet) {
|
||||||
ksort($commandsSet);
|
ksort($commandsSet);
|
||||||
|
@ -61,4 +61,36 @@ EOF;
|
|||||||
|
|
||||||
$this->assertEquals($output, $commandTester->getDisplay(true));
|
$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
src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php
Normal file
13
src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php
Normal 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>');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user