Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions features/scaffold-package.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
7 changes: 7 additions & 0 deletions src/ScaffoldPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}" );
Comment on lines +157 to +162
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Next steps" guidance should only be displayed when files were successfully created. Currently, it will be shown even when all files are skipped (when files_written is empty). Consider wrapping the next steps output in a condition that checks if files were actually written, similar to how the success message is handled on line 137.

Suggested change
// 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}" );
if ( ! empty( $files_written ) ) {
// 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}" );
}

Copilot uses AI. Check for mistakes.
}

/**
Expand Down
14 changes: 14 additions & 0 deletions templates/HelloWorldCommand.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down