Skip to content

Commit d529933

Browse files
authored
Merge pull request #274 from wp-cli/copilot/update-documentation-hello-world
2 parents 9f202d4 + e417370 commit d529933

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

features/scaffold-package.feature

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,37 @@ Feature: Scaffold WP-CLI commands
275275
And the {PACKAGE_PATH}/local/wp-cli/foo/phpcs.xml.dist file should exist
276276
And the {PACKAGE_PATH}/local/wp-cli/foo/.github/PULL_REQUEST_TEMPLATE file should not exist
277277
And the {PACKAGE_PATH}/local/wp-cli/foo/.github/ISSUE_TEMPLATE file should not exist
278+
279+
Scenario: Scaffolded package includes autoloader documentation
280+
Given an empty directory
281+
282+
When I run `wp package path`
283+
Then save STDOUT as {PACKAGE_PATH}
284+
285+
When I run `wp scaffold package wp-cli/foo --skip-tests --skip-readme --skip-github --skip-install`
286+
Then STDOUT should contain:
287+
"""
288+
Success: Created package files
289+
"""
290+
And STDOUT should contain:
291+
"""
292+
Next steps:
293+
"""
294+
And STDOUT should contain:
295+
"""
296+
composer dump-autoload
297+
"""
298+
299+
When I run `cat {PACKAGE_PATH}/local/wp-cli/foo/src/HelloWorldCommand.php`
300+
Then STDOUT should contain:
301+
"""
302+
IMPORTANT: After modifying this file or adding new command classes, you need to
303+
"""
304+
And STDOUT should contain:
305+
"""
306+
composer dump-autoload --working-dir=$(wp package path)
307+
"""
308+
And STDOUT should contain:
309+
"""
310+
https://getcomposer.org/doc/01-basic-usage.md#autoloading
311+
"""

src/ScaffoldPackageCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ public function package( $args, $assoc_args ) {
153153
if ( ! Utils\get_flag_value( $assoc_args, 'skip-install' ) ) {
154154
WP_CLI::runcommand( "package install {$package_dir}", array( 'launch' => false ) );
155155
}
156+
157+
// Display next steps guidance for users.
158+
WP_CLI::log( '' );
159+
WP_CLI::log( 'Next steps:' );
160+
WP_CLI::log( " * Edit {$package_dir}/src/HelloWorldCommand.php to customize your command" );
161+
WP_CLI::log( ' * After making changes, regenerate the autoloader with:' );
162+
WP_CLI::log( " composer dump-autoload --working-dir={$package_dir}" );
156163
}
157164

158165
/**

templates/HelloWorldCommand.mustache

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ namespace WP_CLI\HelloWorld;
55
use WP_CLI;
66
use WP_CLI_Command;
77

8+
/**
9+
* HelloWorld command implementation.
10+
*
11+
* IMPORTANT: After modifying this file or adding new command classes, you need to
12+
* regenerate the autoloader so your changes are recognized:
13+
*
14+
* composer dump-autoload --working-dir=$(wp package path)
15+
*
16+
* Alternatively, you can run `wp package update` to update your package and
17+
* regenerate the autoloader.
18+
*
19+
* Learn more about Composer autoloading:
20+
* https://getcomposer.org/doc/01-basic-usage.md#autoloading
21+
*/
822
class HelloWorldCommand extends WP_CLI_Command {
923
1024
/**

0 commit comments

Comments
 (0)