Skip to content

feat: offer to run a suggested command when the typed name is not found - #10538

Open
paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:command-suggestion-confirm
Open

feat: offer to run a suggested command when the typed name is not found#10538
paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:command-suggestion-confirm

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description

When a command name is not found, spark already lists the closest matches. On an interactive run it now also offers to run one of them.

Single match:

$ php spark cache:clea

Command "cache:clea" not found.

Run "cache:clear" instead? [y, n]: y
Cache cleared using the "file" driver.

Several matches:

$ php spark clear

Command "clear" not found.

Select a command to run instead:
  [0]  cache:clear
  [1]  debugbar:clear
  [2]  logs:clear
  [3]  none of these

[0, 1, 2, 3]: 0
Cache cleared using the "file" driver.

Declining (n, or none of these) runs nothing and exits with EXIT_ERROR. The chosen command receives the original arguments and options.

Non-interactive runs (--no-interaction / -N, piped input, or a NullInputOutput sink) are unchanged:

$ php spark cache:clea -N

Command "cache:clea" not found.

Did you mean this?
    cache:clear

Note: Commands::getCommandAlternatives() is now public (recorded under Method Scope Changes).

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Sep 9, 2026
@paulbalandan paulbalandan added the enhancement PRs that improve existing functionalities label Sep 9, 2026

@neznaika0 neznaika0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice feature

Comment thread system/CLI/Console.php
return CLI::prompt(lang('CLI.altCommandRun', [$alternatives[0]]), ['y', 'n']) === 'y' ? $alternatives[0] : null;
}

$chosen = (int) CLI::promptByKey(lang('CLI.altCommandSelect'), [...$alternatives, lang('CLI.altCommandNone')]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible to specify Y/n by default?

Run "cache:clear" instead? [Y, n]:  (click "Enter" as "Yes")
    Cache cleared using the "file" driver.


- Added new language keys:
- ``Cache.unsupportedLockStore`` (``CacheException::forUnsupportedLockStore()``)
- ``CLI.commandAlias`` and ``CLI.helpAliases`` (command alias rendering in ``list`` and ``help``)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add changelog.

- ``CLI.altCommandNone``, ``CLI.altCommandRun`` and ``CLI.altCommandSelect`` (correcting a mistyped command)

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good!

I think we should also mention the method's visibility change in the upgrade notes. Something short, like:

If you extend CodeIgniter\CLI\Commands and override getCommandAlternatives(), change the override's visibility from protected to public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch. enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants