From 8c6325a62eca9a77b7018441d85f1404bfe9ab48 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 17:46:15 +0000 Subject: [PATCH 1/4] Initial plan From 0c426ffe4cacb742d038afc49584df3ccda72bfe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 17:48:49 +0000 Subject: [PATCH 2/4] Add autoloader documentation to scaffolded packages Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/scaffold-package.feature | 34 ++++++++++++++++++++++++++++ src/ScaffoldPackageCommand.php | 11 +++++++++ templates/HelloWorldCommand.mustache | 14 ++++++++++++ 3 files changed, 59 insertions(+) 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..c46d019 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -152,6 +152,17 @@ 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 ) ); + 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}" ); + } else { + 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 { /** From da65e56fed8e452bedaef0313d17b0437abf9d24 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 17:52:42 +0000 Subject: [PATCH 3/4] Fix code style issues in ScaffoldPackageCommand.php Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/ScaffoldPackageCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index c46d019..566d1fa 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -153,15 +153,15 @@ 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 ) ); WP_CLI::log( '' ); - WP_CLI::log( "Next steps:" ); + 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( ' * After making changes, regenerate the autoloader with:' ); WP_CLI::log( " composer dump-autoload --working-dir={$package_dir}" ); } else { WP_CLI::log( '' ); - WP_CLI::log( "Next steps:" ); + 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( ' * After making changes, regenerate the autoloader with:' ); WP_CLI::log( " composer dump-autoload --working-dir={$package_dir}" ); } } From e4173703adb0f1c2e625c6999a3b182386d524c8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 17:53:55 +0000 Subject: [PATCH 4/4] Remove code duplication in next steps guidance Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/ScaffoldPackageCommand.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index 566d1fa..334026c 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -152,18 +152,14 @@ 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 ) ); - 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}" ); - } else { - 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}" ); } + + // 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}" ); } /**