Skip to content

Commit

Permalink
Adding feature to Command help that allows you to use %command.name% …
Browse files Browse the repository at this point in the history
…and %command.full_name% patterns so you don't have to hardcode the command name in help text.
  • Loading branch information
jwage authored and fabpot committed Apr 23, 2010
1 parent 27057fe commit 0c78e9f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Symfony/Components/Console/Command/Command.php
Expand Up @@ -381,6 +381,28 @@ public function getHelp()
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.
*
Expand Down Expand Up @@ -463,7 +485,7 @@ public function asText()

$messages[] = $this->definition->asText();

if ($help = $this->getHelp())
if ($help = $this->getProcessedHelp())
{
$messages[] = '<comment>Help:</comment>';
$messages[] = ' '.implode("\n ", explode("\n", $help))."\n";
Expand Down

0 comments on commit 0c78e9f

Please sign in to comment.