diff --git a/features/scaffold-package-readme.feature b/features/scaffold-package-readme.feature index 32b6722..4b64bab 100644 --- a/features/scaffold-package-readme.feature +++ b/features/scaffold-package-readme.feature @@ -352,3 +352,37 @@ Feature: Scaffold a README.md file for an existing package """ This package is included with WP-CLI itself """ + + Scenario: README includes command aliases + Given an empty directory + And a foo/composer.json file: + """ + { + "name": "wp-cli/alias-test", + "description": "Test package for command aliases", + "license": "MIT", + "authors": [], + "minimum-stability": "dev", + "autoload": { + "files": [ "command.php" ] + }, + "require": { + "wp-cli/wp-cli": "^2.12" + }, + "require-dev": { + "wp-cli/wp-cli-tests": "^5.0.0" + }, + "extra": { + "commands": [ + "scaffold post-type" + ] + } + } + """ + + When I run `wp scaffold package-readme foo` + Then the foo/README.md file should exist + And the foo/README.md file should contain: + """ + **Alias:** `cpt` + """ diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index 7a854a9..8f1f2a7 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -346,12 +346,19 @@ public function package_readme( $args, $assoc_args ) { // definition lists $longdesc = preg_replace_callback( '/([^\n]+)\n: (.+?)(\n\n|$)/s', [ __CLASS__, 'rewrap_param_desc' ], $longdesc ); - $readme_args['commands'][] = [ + $command_data = [ 'name' => "wp {$command}", 'shortdesc' => isset( $parent_command['description'] ) ? $parent_command['description'] : '', 'synopsis' => "wp {$command}" . ( empty( $parent_command['subcommands'] ) ? ( isset( $parent_command['synopsis'] ) ? " {$parent_command['synopsis']}" : '' ) : '' ), 'longdesc' => $longdesc, ]; + + // Add alias if present. + if ( ! empty( $parent_command['alias'] ) ) { + $command_data['alias'] = $parent_command['alias']; + } + + $readme_args['commands'][] = $command_data; } $readme_args['has_commands'] = true; $readme_args['has_multiple_commands'] = count( $readme_args['commands'] ) > 1; diff --git a/templates/readme-using.mustache b/templates/readme-using.mustache index 8751d82..1377e56 100644 --- a/templates/readme-using.mustache +++ b/templates/readme-using.mustache @@ -15,6 +15,10 @@ This package implements the following commands: {{synopsis}} ~~~ +{{#alias}} +**Alias:** `{{alias}}` + +{{/alias}} {{longdesc}} {{/commands}}