From 4f6133921ad1f5f03502f7d5393a9e996e99730b Mon Sep 17 00:00:00 2001 From: spdionis Date: Tue, 18 Nov 2014 02:17:03 +0200 Subject: [PATCH 1/4] global commands are always first in command list --- .../Console/Descriptor/ApplicationDescription.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php index cdf1493c40217..33fd35e6e0c61 100644 --- a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php +++ b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php @@ -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 &$commands) { ksort($commands); From 1591f7844add2b54a70ff4dbc948a7eae4a2d4e2 Mon Sep 17 00:00:00 2001 From: spdionis Date: Fri, 21 Nov 2014 02:31:17 +0200 Subject: [PATCH 2/4] output command and namespace without styling --- .../Component/Console/Descriptor/TextDescriptor.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php index 72c485bbe9615..798d5820c7e7f 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -195,13 +195,15 @@ protected function describeApplication(Application $application, array $options // add commands by namespace foreach ($description->getNamespaces() as $namespace) { if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { - $this->writeText("\n"); - $this->writeText(''.$namespace['id'].'', $options); + $this->writeText("\n", $options); + $this->writeText($namespace['id'], array_merge($options, array('raw_output' => true))); + $this->writeText("", $options); } foreach ($namespace['commands'] as $name) { - $this->writeText("\n"); - $this->writeText(sprintf(" %-${width}s %s", $name, $description->getCommand($name)->getDescription()), $options); + $this->writeText("\n ", $options); + $this->writeText(sprintf("%-${width}s", $name), array_merge($options, array('raw_output' => true))); + $this->writeText(sprintf(" %s", $description->getCommand($name)->getDescription()), $options); } } From 823407a2c8db3b8bfa97dd49a77c81efa09e51ca Mon Sep 17 00:00:00 2001 From: spdionis Date: Sun, 29 Mar 2015 17:13:55 +0300 Subject: [PATCH 3/4] add test for command ordering and raw output --- .../Console/Tests/Command/ListCommandTest.php | 32 +++++++++++++++++++ .../Console/Tests/Fixtures/Foo6Command.php | 13 ++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php diff --git a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php index fbb9feeb68731..cfc1b99dd3a98 100644 --- a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php @@ -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 = <<foo + foo:bar +EOF; + + $this->assertEquals($output, trim($commandTester->getDisplay(true))); + } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php b/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php new file mode 100644 index 0000000000000..78fa91eaa8931 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php @@ -0,0 +1,13 @@ +setName('foo:bar'); + } + +} \ No newline at end of file From 942c34eddf2a1dcbe93650394c9e2fdd2dc93de0 Mon Sep 17 00:00:00 2001 From: spdionis Date: Sun, 29 Mar 2015 18:03:50 +0300 Subject: [PATCH 4/4] make test less fragile --- .../Console/Tests/Command/ListCommandTest.php | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php index cfc1b99dd3a98..9e099eb4eec4d 100644 --- a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php @@ -69,28 +69,9 @@ public function testExecuteListsCommandsNameAndNamespaceRaw() $application->add(new \Foo6Command()); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName())); - $output = <<foo - foo:bar -EOF; + $regex = '/Available commands:\s*help\s*.*\s*list.*\s*foo\s*foo:bar<\/fg=blue>/'; - $this->assertEquals($output, trim($commandTester->getDisplay(true))); + $this->assertRegExp($regex, $commandTester->getDisplay(true)); } }