Skip to content

Commit 77e8c86

Browse files
Bundled commands should mention they're included with WP-CLI
1 parent fedf3ff commit 77e8c86

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

features/scaffold-package-readme.feature

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,38 @@ Feature: Scaffold a README.md file for an existing package
200200
"""
201201
Error: Missing one or more commands defined in composer.json -> extras -> commands.
202202
"""
203+
204+
Scenario: README for a bundled command
205+
Given an empty directory
206+
And a foo/composer.json file:
207+
"""
208+
{
209+
"name": "runcommand/profile",
210+
"authors": [],
211+
"minimum-stability": "dev",
212+
"autoload": {
213+
"files": [ "command.php" ]
214+
},
215+
"require": {
216+
},
217+
"require-dev": {
218+
"wp-cli/wp-cli": "*",
219+
"behat/behat": "~2.5"
220+
},
221+
"extra": {
222+
"bundled": true
223+
}
224+
}
225+
"""
226+
227+
When I run `wp scaffold package-readme foo`
228+
Then the foo/README.md file should exist
229+
And the foo/README.md file should contain:
230+
"""
231+
runcommand/profile
232+
==================
233+
"""
234+
And the foo/README.md file should contain:
235+
"""
236+
This package is included with WP-CLI itself
237+
"""

src/ScaffoldPackageCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,15 @@ public function package_readme( $args, $assoc_args ) {
300300
'heading' => $section_heading,
301301
);
302302
}
303+
$bundled = ! empty( $composer_obj['extra']['bundled'] );
303304
foreach( array( 'using', 'installing', 'contributing' ) as $key ) {
304305
if ( isset( $readme_sections[ $key ] ) ) {
305-
$readme_sections[ $key ]['body'] = dirname( dirname( __FILE__ ) ) . '/templates/readme-' . $key . '.mustache';
306+
$file = dirname( dirname( __FILE__ ) ) . '/templates/readme-' . $key . '.mustache';
307+
if ( $bundled
308+
&& file_exists( dirname( dirname( __FILE__ ) ) . '/templates/readme-' . $key . '-bundled.mustache' ) ) {
309+
$file = dirname( dirname( __FILE__ ) ) . '/templates/readme-' . $key . '-bundled.mustache';
310+
}
311+
$readme_sections[ $key ]['body'] = $file;
306312
}
307313
}
308314

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This package is included with WP-CLI itself, no additional installation necessary.
2+
3+
To install the latest version of this package over what's included in WP-CLI, run:
4+
5+
wp package install git@github.com:{{package_name}}.git

0 commit comments

Comments
 (0)