浏览代码

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.

Jonathan H. Wage 15 年之前
父节点
当前提交
0c78e9f121
共有 1 个文件被更改,包括 23 次插入1 次删除
  1. 23 1
      src/Symfony/Components/Console/Command/Command.php

+ 23 - 1
src/Symfony/Components/Console/Command/Command.php

@@ -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";