Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions features/scaffold-package-readme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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`
"""
9 changes: 8 additions & 1 deletion src/ScaffoldPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions templates/readme-using.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ This package implements the following commands:
{{synopsis}}
~~~

{{#alias}}
**Alias:** `{{alias}}`

{{/alias}}
{{longdesc}}

{{/commands}}
Expand Down