Adding feature to Command help that allows you to use %command.name% and %command.full_name% patterns so you don't have to hardcode the command name in help text.

This commit is contained in:
Jonathan H. Wage 2010-04-16 13:15:23 -04:00 committed by Fabien Potencier
parent 27057fe6ae
commit 0c78e9f121
1 changed files with 23 additions and 1 deletions

View File

@ -381,6 +381,28 @@ class Command
return $this->help;
}
/**
* Returns the processed help for the command replacing the %command.name% and
* %command.full_name% patterns with the real values dynamically.
*
* @return string The processed help for the command
*/
public function getProcessedHelp()
{
$name = $this->namespace.':'.$this->name;
$placeholders = array(
'%command.name%',
'%command.full_name%'
);
$replacements = array(
$name,
$_SERVER['PHP_SELF'].' '.$name
);
return str_replace($placeholders, $replacements, $this->getHelp());
}
/**
* Sets the aliases for the command.
*
@ -463,7 +485,7 @@ class Command
$messages[] = $this->definition->asText();
if ($help = $this->getHelp())
if ($help = $this->getProcessedHelp())
{
$messages[] = '<comment>Help:</comment>';
$messages[] = ' '.implode("\n ", explode("\n", $help))."\n";