Skip to content

Commit 4d2ddd6

Browse files
Copilotswissspidy
andcommitted
Add command alias support to README generation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent bb31b88 commit 4d2ddd6

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

features/scaffold-package-readme.feature

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,37 @@ Feature: Scaffold a README.md file for an existing package
352352
"""
353353
This package is included with WP-CLI itself
354354
"""
355+
356+
Scenario: README includes command aliases
357+
Given an empty directory
358+
And a foo/composer.json file:
359+
"""
360+
{
361+
"name": "wp-cli/alias-test",
362+
"description": "Test package for command aliases",
363+
"license": "MIT",
364+
"authors": [],
365+
"minimum-stability": "dev",
366+
"autoload": {
367+
"files": [ "command.php" ]
368+
},
369+
"require": {
370+
"wp-cli/wp-cli": "^2.12"
371+
},
372+
"require-dev": {
373+
"wp-cli/wp-cli-tests": "^5.0.0"
374+
},
375+
"extra": {
376+
"commands": [
377+
"scaffold post-type"
378+
]
379+
}
380+
}
381+
"""
382+
383+
When I run `wp scaffold package-readme foo`
384+
Then the foo/README.md file should exist
385+
And the foo/README.md file should contain:
386+
"""
387+
**Alias:** `cpt`
388+
"""

src/ScaffoldPackageCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,19 @@ public function package_readme( $args, $assoc_args ) {
346346
// definition lists
347347
$longdesc = preg_replace_callback( '/([^\n]+)\n: (.+?)(\n\n|$)/s', [ __CLASS__, 'rewrap_param_desc' ], $longdesc );
348348

349-
$readme_args['commands'][] = [
349+
$command_data = [
350350
'name' => "wp {$command}",
351351
'shortdesc' => isset( $parent_command['description'] ) ? $parent_command['description'] : '',
352352
'synopsis' => "wp {$command}" . ( empty( $parent_command['subcommands'] ) ? ( isset( $parent_command['synopsis'] ) ? " {$parent_command['synopsis']}" : '' ) : '' ),
353353
'longdesc' => $longdesc,
354354
];
355+
356+
// Add alias if present.
357+
if ( ! empty( $parent_command['alias'] ) ) {
358+
$command_data['alias'] = $parent_command['alias'];
359+
}
360+
361+
$readme_args['commands'][] = $command_data;
355362
}
356363
$readme_args['has_commands'] = true;
357364
$readme_args['has_multiple_commands'] = count( $readme_args['commands'] ) > 1;

templates/readme-using.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ This package implements the following commands:
1515
{{synopsis}}
1616
~~~
1717

18+
{{#alias}}
19+
**Alias:** `{{alias}}`
20+
21+
{{/alias}}
1822
{{longdesc}}
1923

2024
{{/commands}}

0 commit comments

Comments
 (0)