Skip to content

fix: stop prompts from asking forever when the input ends - #10658

Open
paulbalandan wants to merge 1 commit into
codeigniter4:developfrom
paulbalandan:prompt-end-of-input
Open

paulbalandan wants to merge 1 commit into
codeigniter4:developfrom
paulbalandan:prompt-end-of-input

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description
InputOutput::input() returns '' both for an empty line and for the end of the input. So when piped or redirected input runs out before a valid answer, a prompt that asks again loops forever:

  • CLI::prompt() and CLI::promptByKey() whose default fails the validation rules
  • CLI::promptByMultipleKeys() whose options have string keys

For example, CLI::prompt('Name', null, 'required') < /dev/null never returns.

  • Added InputOutput::isAtEnd(). It reports whether the last input() found the end of an input other than a terminal. input() still returns '', so existing callers see no change.
  • The prompts check it before asking again, and throw a CLIException (new CLI.inputEnded language string) in place of looping.
  • At a terminal, Ctrl+D ends only the current read, so it still asks again, as settled in fix: return an empty string when readline() reaches end-of-file #10542.
  • MockInputOutput::isAtEnd() returns true once its scripted answers have run out. A scripted '' before the last answer stays an empty line.

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 bug Verified issues on the current code behavior or pull requests that will fix them label Oct 25, 2026

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

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant