[Console] fixed previous merge
This commit is contained in:
parent
a13d2270ed
commit
3f4d718c5b
@ -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) {
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user