diff --git a/doc/articles/scripts.md b/doc/articles/scripts.md index e5c9be0c6..fda45f22d 100644 --- a/doc/articles/scripts.md +++ b/doc/articles/scripts.md @@ -278,16 +278,14 @@ JSON array of commands. ## Custom descriptions. -You can set custom script descriptions with the following extra in your composer.json: +You can set custom script descriptions with the following in your `composer.json`: - ```json - { - "extra": { - "scripts-description": { - "test": "Run all tests!" - } - } - } - ``` +```json +{ + "scripts-description": { + "test": "Run all tests!" + } +} +``` > **Note:** You can only set custom descriptions of custom commands. diff --git a/res/composer-schema.json b/res/composer-schema.json index b98348222..0ae737444 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -447,6 +447,10 @@ } } }, + "scripts-description": { + "type": ["object"], + "description": "Descriptions for scripts listeners, shown in console help." + }, "support": { "type": "object", "properties": { diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index d8ab8eb76..20975a10a 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -228,7 +228,15 @@ class Application extends BaseApplication if ($this->has($script)) { $io->writeError('A script named '.$script.' would override a Composer command and has been skipped'); } else { - $description = isset($composer['extra']['scripts-description'][$script]) ? $composer['extra']['scripts-description'][$script] : null; + $description = null; + + if (isset($composer['scripts-description'][$script])) { + $description = $composer['scripts-description'][$script]; + } elseif (isset($composer['extra']['scripts-description'][$script])) { + $io->writeError('You are using "scripts-description" in "extra" which is deprecated. Move "scripts-description" to the topmost level next to "scripts" instead.'); + $description = $composer['extra']['scripts-description'][$script]; + } + $this->add(new Command\ScriptAliasCommand($script, $description)); } }