Skip to content

Commit

Permalink
[Console] fixed previous merge
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 18, 2011
1 parent a13d227 commit 3f4d718
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
27 changes: 17 additions & 10 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -626,17 +626,30 @@ static public function getAbbreviations($names)
/**
* 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(), '');
Expand All @@ -646,12 +659,6 @@ public function asText($namespace = null, $raw = false)
$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) {
Expand Down
Expand Up @@ -28,6 +28,11 @@ public function testExecute()
$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');
}
}

0 comments on commit 3f4d718

Please sign in to comment.