瀏覽代碼

Allow custom script descriptions.

Thom Toogood 7 年之前
父節點
當前提交
bf880ad5e0
共有 3 個文件被更改,包括 22 次插入3 次删除
  1. 16 0
      doc/articles/scripts.md
  2. 4 2
      src/Composer/Command/ScriptAliasCommand.php
  3. 2 1
      src/Composer/Console/Application.php

+ 16 - 0
doc/articles/scripts.md

@@ -271,3 +271,19 @@ resolve to whatever php process is currently being used:
 One limitation of this is that you can not call multiple commands in
 One limitation of this is that you can not call multiple commands in
 a row like `@php install && @php foo`. You must split them up in a
 a row like `@php install && @php foo`. You must split them up in a
 JSON array of commands.
 JSON array of commands.
+
+## Custom descriptions.
+
+You can set custom script descriptions with the following extra in your composer.json:
+
+ ```json
+ {
+     "extra": {
+        "scripts-description": {
+            "test": "Run all tests!"
+        }
+     }
+ }
+ ```
+
+> **Note:** You can only set custom descriptions of custom commands.

+ 4 - 2
src/Composer/Command/ScriptAliasCommand.php

@@ -23,10 +23,12 @@ use Symfony\Component\Console\Output\OutputInterface;
 class ScriptAliasCommand extends BaseCommand
 class ScriptAliasCommand extends BaseCommand
 {
 {
     private $script;
     private $script;
+    private $description;
 
 
-    public function __construct($script)
+    public function __construct($script, $description)
     {
     {
         $this->script = $script;
         $this->script = $script;
+        $this->description = empty($description) ? 'Runs the '.$script.' script as defined in composer.json.' : $description;
 
 
         parent::__construct();
         parent::__construct();
     }
     }
@@ -35,7 +37,7 @@ class ScriptAliasCommand extends BaseCommand
     {
     {
         $this
         $this
             ->setName($this->script)
             ->setName($this->script)
-            ->setDescription('Runs the '.$this->script.' script as defined in composer.json.')
+            ->setDescription($this->description)
             ->setDefinition(array(
             ->setDefinition(array(
                 new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'),
                 new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'),
                 new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'),
                 new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'),

+ 2 - 1
src/Composer/Console/Application.php

@@ -228,7 +228,8 @@ class Application extends BaseApplication
                             if ($this->has($script)) {
                             if ($this->has($script)) {
                                 $io->writeError('<warning>A script named '.$script.' would override a Composer command and has been skipped</warning>');
                                 $io->writeError('<warning>A script named '.$script.' would override a Composer command and has been skipped</warning>');
                             } else {
                             } else {
-                                $this->add(new Command\ScriptAliasCommand($script));
+                                $description = isset($composer['extra']['scripts-description'][$script]) ? $composer['extra']['scripts-description'][$script]:NULL;
+                                $this->add(new Command\ScriptAliasCommand($script, $description));
                             }
                             }
                         }
                         }
                     }
                     }