diff --git a/features/scaffold-package.feature b/features/scaffold-package.feature index a445b12..07f2ef2 100644 --- a/features/scaffold-package.feature +++ b/features/scaffold-package.feature @@ -275,3 +275,37 @@ Feature: Scaffold WP-CLI commands And the {PACKAGE_PATH}/local/wp-cli/foo/phpcs.xml.dist file should exist And the {PACKAGE_PATH}/local/wp-cli/foo/.github/PULL_REQUEST_TEMPLATE file should not exist And the {PACKAGE_PATH}/local/wp-cli/foo/.github/ISSUE_TEMPLATE file should not exist + + Scenario: Scaffolded package includes autoloader documentation + Given an empty directory + + When I run `wp package path` + Then save STDOUT as {PACKAGE_PATH} + + When I run `wp scaffold package wp-cli/foo --skip-tests --skip-readme --skip-github --skip-install` + Then STDOUT should contain: + """ + Success: Created package files + """ + And STDOUT should contain: + """ + Next steps: + """ + And STDOUT should contain: + """ + composer dump-autoload + """ + + When I run `cat {PACKAGE_PATH}/local/wp-cli/foo/src/HelloWorldCommand.php` + Then STDOUT should contain: + """ + IMPORTANT: After modifying this file or adding new command classes, you need to + """ + And STDOUT should contain: + """ + composer dump-autoload --working-dir=$(wp package path) + """ + And STDOUT should contain: + """ + https://getcomposer.org/doc/01-basic-usage.md#autoloading + """ diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index 2027f0e..334026c 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -153,6 +153,13 @@ public function package( $args, $assoc_args ) { if ( ! Utils\get_flag_value( $assoc_args, 'skip-install' ) ) { WP_CLI::runcommand( "package install {$package_dir}", array( 'launch' => false ) ); } + + // Display next steps guidance for users. + WP_CLI::log( '' ); + WP_CLI::log( 'Next steps:' ); + WP_CLI::log( " * Edit {$package_dir}/src/HelloWorldCommand.php to customize your command" ); + WP_CLI::log( ' * After making changes, regenerate the autoloader with:' ); + WP_CLI::log( " composer dump-autoload --working-dir={$package_dir}" ); } /** diff --git a/templates/HelloWorldCommand.mustache b/templates/HelloWorldCommand.mustache index 1d77d7e..ea70654 100644 --- a/templates/HelloWorldCommand.mustache +++ b/templates/HelloWorldCommand.mustache @@ -5,6 +5,20 @@ namespace WP_CLI\HelloWorld; use WP_CLI; use WP_CLI_Command; +/** + * HelloWorld command implementation. + * + * IMPORTANT: After modifying this file or adding new command classes, you need to + * regenerate the autoloader so your changes are recognized: + * + * composer dump-autoload --working-dir=$(wp package path) + * + * Alternatively, you can run `wp package update` to update your package and + * regenerate the autoloader. + * + * Learn more about Composer autoloading: + * https://getcomposer.org/doc/01-basic-usage.md#autoloading + */ class HelloWorldCommand extends WP_CLI_Command { /**