[Console] fixed previous merge

This commit is contained in:
Fabien Potencier 2011-12-18 14:32:45 +01:00
parent a13d2270ed
commit 3f4d718c5b
2 changed files with 23 additions and 11 deletions

View File

@ -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[] = '<comment>Available commands:</comment>';
}
$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) {

View File

@ -28,6 +28,11 @@ class ListCommandTest extends \PHPUnit_Framework_TestCase
$this->assertRegExp('/<command id="list" name="list">/', $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 = <<<EOF
help Displays help for a command
list Lists commands
EOF;
$this->assertEquals($output, $commandTester->getDisplay(), 'boo');
}
}