Skip to content

Conversation

@swissspidy
Copy link
Member

@swissspidy swissspidy commented Oct 1, 2025

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_AUTOCORRECT env var can be used to enable this by default.

Example:

$ wp i18n make-mot
Warning: 'make-mot' is not a registered subcommand of 'i18n'. See 'wp help i18n' for available subcommands.
Did you mean 'make-mo'? [y/n]
# runs `wp i18n make-mo`

$ wp i18 make-pot
Warning: 'i18' is not a registered wp command. See 'wp help' for available commands.
Did you mean 'i18n'? [y/n]
# runs `wp i18n make-pot`

$ WP_CLI_AUTOCORRECT=1 bin/wp hel i18n make-po
# will show help for `i18n make-mo` command

@codecov
Copy link

codecov bot commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 96.22642% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Runner.php 96.15% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy changed the title Run suggestions for mistyped commands Automatically run suggestions for mistyped commands Oct 1, 2025
@swissspidy swissspidy marked this pull request as ready for review October 1, 2025 19:35
@swissspidy swissspidy requested a review from a team as a code owner October 1, 2025 19:35
@swissspidy swissspidy requested a review from Copilot November 2, 2025 17:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 $autocorrect parameter to find_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.

@schlessera schlessera merged commit 7c29c4a into main Dec 9, 2025
54 checks passed
@schlessera schlessera deleted the add/autocorrect branch December 9, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run the mistyped suggestion

3 participants