Add hints for commands that are not registered - #6386
Draft
swissspidy wants to merge 1 commit into
Draft
Conversation
The "is not a registered wp command" error says nothing about why a command is missing or how to get it. That is fine for typos, but not for commands that exist yet are simply unavailable in the installation at hand, such as `wp package` in a Composer-based installation. Composer packages can now declare guidance for such commands through an `extra.command-hints` section in their `composer.json`. The hint is read from the installed packages and the root package, and appended to the error when the command turns out to be unavailable. A new `unregistered_command_hint` filter allows the same at runtime. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G27BNpnRNerEeSGjvefzBf
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
'x' is not a registered wp commandsays nothing about why a command is missing or how to get it. That is fine for typos, where the "Did you mean" suggestion carries the weight, but not for commands that exist and are simply unavailable in the installation at hand.The motivating case is
wp package. Since wp-cli/wp-cli-bundle#846 movedwp-cli/package-commandtorequire-dev, it ships in the Phar but is absent from Composer-based installations. Those users currently get:…with no indication that the command exists, that their install method is the reason, or that
composer require wp-cli/package-commandfixes it.Approach
Packages can declare guidance for commands they know about through an
extra.command-hintssection in theircomposer.json:Metadata rather than code is deliberate: wp-cli-bundle has no
autoloadsection of its own, so declaring this incomposer.jsonis the only way it can speak. It also follows the existingextra.commandsconvention, and keeps the framework free of any hardcoded knowledge about which package provides what.Changes
WP_CLI\CommandHintscollects hints fromvendor/composer/installed.jsonand the rootcomposer.json, with the root taking precedence. Malformed entries (non-string keys or values, blank strings) are skipped.Runner::find_command_to_run()appends a matching hint to the error, on both the top-level and subcommand branches.wp package install foofails on the top-levelpackagelookup, so a single hint covers every subcommand.unregistered_command_hintfilter (2 args) lets a project supply or override guidance at runtime without Composer metadata.Disk is only touched on the failure path, and hints are cached per process. A hint never displaces the existing "Did you mean" suggestion, and never appears for a command that is registered — so Phar users see no change at all.
Companion PR that declares the actual metadata: wp-cli/wp-cli-bundle (branch
claude/wp-cli-package-composer-guidance-rve6ct). That one is inert without this change; this one is a no-op without a package that declares hints, so they can land in either order.Result
Testing
tests/CommandHintsTest.phpcovers collection, root-package precedence, and rejection of malformed entries, against fixtures intests/data/command-hints/. A Behat scenario infeatures/command.featurecovers the filter end to end on both error branches, and asserts no hint leaks onto an unrelated unknown command.composer testhas not been run. The environment this was authored in has GitHub access scoped to two repos, so dist downloads for phpcs, phpstan, phpunit and wp-cli-tests all failed authentication and left their vendor directories empty. What was verified:php -lon every changed file, plus a standalone harness drivingCommandHintsagainst a simulated Composer project built from the real bundlecomposer.json— that confirmed the output above, root-package precedence, malformed-entry rejection, and the filter override. The PHPUnit assertions mirror that harness exactly but have not been executed, and neither PHPCS nor PHPStan (level 9) has seen the new code. Worth a close look at CI.Generated by Claude Code