[Console] Fix help text for single command applications
This commit is contained in:
parent
f82beb51de
commit
7058f555b5
@ -74,7 +74,7 @@ class Application
|
|||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
private $terminal;
|
private $terminal;
|
||||||
private $defaultCommand;
|
private $defaultCommand;
|
||||||
private $singleCommand;
|
private $singleCommand = false;
|
||||||
private $initialized;
|
private $initialized;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1162,6 +1162,14 @@ class Application
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public function isSingleCommand()
|
||||||
|
{
|
||||||
|
return $this->singleCommand;
|
||||||
|
}
|
||||||
|
|
||||||
private function splitStringByWidth($string, $width)
|
private function splitStringByWidth($string, $width)
|
||||||
{
|
{
|
||||||
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
|
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
|
||||||
|
@ -533,6 +533,7 @@ class Command
|
|||||||
public function getProcessedHelp()
|
public function getProcessedHelp()
|
||||||
{
|
{
|
||||||
$name = $this->name;
|
$name = $this->name;
|
||||||
|
$isSingleCommand = $this->application && $this->application->isSingleCommand();
|
||||||
|
|
||||||
$placeholders = array(
|
$placeholders = array(
|
||||||
'%command.name%',
|
'%command.name%',
|
||||||
@ -540,7 +541,7 @@ class Command
|
|||||||
);
|
);
|
||||||
$replacements = array(
|
$replacements = array(
|
||||||
$name,
|
$name,
|
||||||
$_SERVER['PHP_SELF'].' '.$name,
|
$isSingleCommand ? $_SERVER['PHP_SELF'] : $_SERVER['PHP_SELF'].' '.$name,
|
||||||
);
|
);
|
||||||
|
|
||||||
return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription());
|
return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription());
|
||||||
|
@ -166,6 +166,14 @@ class CommandTest extends TestCase
|
|||||||
$command = new \TestCommand();
|
$command = new \TestCommand();
|
||||||
$command->setHelp('');
|
$command->setHelp('');
|
||||||
$this->assertContains('description', $command->getProcessedHelp(), '->getProcessedHelp() falls back to the description');
|
$this->assertContains('description', $command->getProcessedHelp(), '->getProcessedHelp() falls back to the description');
|
||||||
|
|
||||||
|
$command = new \TestCommand();
|
||||||
|
$command->setHelp('The %command.name% command does... Example: php %command.full_name%.');
|
||||||
|
$application = new Application();
|
||||||
|
$application->add($command);
|
||||||
|
$application->setDefaultCommand('namespace:name', true);
|
||||||
|
$this->assertContains('The namespace:name command does...', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.name% correctly in single command applications');
|
||||||
|
$this->assertNotContains('%command.full_name%', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.full_name% in single command applications');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetSetAliases()
|
public function testGetSetAliases()
|
||||||
|
Reference in New Issue
Block a user