Automatically run suggestions for mistyped commands#6122
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull Request Overview
This PR implements an interactive command autocorrection feature for WP-CLI that suggests corrections for misspelled commands. The system supports three modes controlled via the WP_CLI_AUTOCORRECT environment variable: 'none' (default), 'confirm' (interactive), and 'auto' (automatic correction without confirmation).
Key changes include:
- Added
$autocorrectparameter tofind_command_to_run()method to enable correction behavior - Modified error handling to show warnings and prompt for confirmation when suggestions are available
- Added logic to execute suggested commands automatically or after user confirmation
- Updated tests to verify the new interactive confirmation flow
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| php/WP_CLI/Runner.php | Implements autocorrect logic with three modes, adds confirmation prompts, and handles recursive command resolution |
| php/commands/src/Help_Command.php | Passes autocorrect parameter when finding help commands |
| features/runner.feature | Tests interactive confirmation for 'network option' suggestion |
| features/help.feature | Tests autocorrect behavior for various help command typos |
| features/command.feature | Tests autocorrect modes (none, confirm, auto) with various command typos |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Fixes #6142
When a command is mistyped and a suggestion is presented, WP-CLI now prompts for confirmation to directly run this suggested command.
If you confirm, it will run the suggested command. If not, it exits (as it does today).
The
WP_CLI_AUTOCORRECTenv var can be used to enable this by default.Example: