From 3f4d718c5b4d6b53bdcf66c0b39fad1ce8307218 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 18 Dec 2011 14:32:45 +0100 Subject: [PATCH] [Console] fixed previous merge --- src/Symfony/Component/Console/Application.php | 27 ++++++++++++------- .../Console/Command/ListCommandTest.php | 7 ++++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index f7648728f8..a5dc91c92c 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -626,17 +626,30 @@ class Application /** * Returns a text representation of the Application. * - * @param string $namespace An optional namespace name - * @param boolean $raw Whether to return raw command list + * @param string $namespace An optional namespace name + * @param boolean $raw Whether to return raw command list * * @return string A string representing the Application */ public function asText($namespace = null, $raw = false) { $commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands; - + + $width = 0; + foreach ($commands as $command) { + $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width; + } + $width += 2; + if ($raw) { - return array_keys($commands); + $messages = array(); + foreach ($this->sortCommands($commands) as $space => $commands) { + foreach ($commands as $name => $command) { + $messages[] = sprintf("%-${width}s %s", $name, $command->getDescription()); + } + } + + return implode("\n", $messages); } $messages = array($this->getHelp(), ''); @@ -646,12 +659,6 @@ class Application $messages[] = 'Available commands:'; } - $width = 0; - foreach ($commands as $command) { - $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width; - } - $width += 2; - // add commands by namespace foreach ($this->sortCommands($commands) as $space => $commands) { if (!$namespace && '_global' !== $space) { diff --git a/tests/Symfony/Tests/Component/Console/Command/ListCommandTest.php b/tests/Symfony/Tests/Component/Console/Command/ListCommandTest.php index 677e66005b..b08d25a072 100644 --- a/tests/Symfony/Tests/Component/Console/Command/ListCommandTest.php +++ b/tests/Symfony/Tests/Component/Console/Command/ListCommandTest.php @@ -28,6 +28,11 @@ class ListCommandTest extends \PHPUnit_Framework_TestCase $this->assertRegExp('//', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed'); $commandTester->execute(array('command' => $command->getName(), '--raw' => true)); - $this->assertRegExp('/help\n/', $commandTester->getDisplay(), 'boo'); + $output = <<assertEquals($output, $commandTester->getDisplay(), 'boo'); } }