Skip to content

feat: move the CLI prompts into a Prompt class - #10655

Open
paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:cli-prompt
Open

paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:cli-prompt

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description
Follow-up to #10628 and #10643. The output already lives in instance classes, and this moves the prompts there too.

  • CodeIgniter\CLI\Prompt is built on an Output, and reads and writes only through it. It has ask(), askByKey() and askByMultipleKeys(), which hold the old logic and are fully typed.
  • The validation is injectable through the constructor. Without one, it uses single_service('validation'), created only when a prompt has rules.
  • CLI::prompt(), promptByKey() and promptByMultipleKeys() delegate to it, and their signatures are unchanged.
  • CLI::getPrompt() and AbstractCommand::getPrompt() return a Prompt on the shared output and on the run's output.
  • AbstractCommand::getPrompt() is overridable. The prompts for missing arguments and the generators' confirmation go through it, so a Prompt subclass answers those too.
  • askByMultipleKeys() has the missing-key fix from fix: reject missing keys in CLI::promptByMultipleKeys() #10654. An answer must name existing keys, not merely keys no larger than the last one.

Behaviour changes, listed in the changelog and the upgrade guide:

  • A CLI subclass overriding validate() no longer affects the prompts. Extend Prompt and override its validate() instead.
  • An override of CLI::prompt() no longer affects promptByKey() or promptByMultipleKeys().
  • Rules, $options, or a promptByKey() text of the wrong type now throw a TypeError.
  • CLI::validate() is deprecated and triggers a deprecation notice.

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

@carson-codeigniter4 carson-codeigniter4 Bot added the 4.8 PRs that target the `4.8` branch. label Oct 23, 2026
@paulbalandan
paulbalandan requested a balanced review from Copilot October 23, 2026 10:17

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI 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.

🟡 Changes recommended

Prompt default selection, injected-terminal wrapping, and Windows test portability need correction before approval.

3 open issues

Review effort: Balanced

Comment thread system/CLI/Prompt.php Outdated
Comment thread system/CLI/Prompt.php Outdated
Comment thread tests/system/CLI/PromptTest.php
@michalsn

Copy link
Copy Markdown
Member

@paulbalandan, feel free to ping me if you have anything you would like me to review with Copilot.

@paulbalandan

Copy link
Copy Markdown
Member Author

@paulbalandan, feel free to ping me if you have anything you would like me to review with Copilot.

I'm not sure what happened, but I still have some AI credits left 😅

This branch has not been deployed

No deployments
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants