Skip to content

Add ConsoleIo::isInteractive() and --no-interaction option - #19821

Merged
LordSimal merged 2 commits into
5.nextfrom
console-no-interaction
Nov 25, 2026
Merged

LordSimal merged 2 commits into
5.nextfrom
console-no-interaction

Conversation

@dereuromark

@dereuromark dereuromark commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

--quiet does two things: it lowers the output level and turns prompts off (setInteractive(false), so ask()/askChoice() return their defaults). You can't get one without the other. There is also no getter for the interactive state, so commands that want to skip a confirmation check the output level instead. cakephp/migrations SeedCommand does $io->level() > ConsoleIo::QUIET.

This adds:

  • ConsoleIo::isInteractive(): bool
  • --no-interaction, a default option that disables prompts but leaves output at the normal level. It is long-only because -n is already taken by plugins (bake fixture -n, cakephp-setup db_backup create -n). A command that defines its own no-interaction option still overrides it, since addOption() replaces same-named options.

--quiet keeps its current behavior. The interactive flag is now set before initialize(), not after it, so a prompt in initialize() respects --quiet and --no-interaction too.

bin/cake some_command --no-interaction
# before: Error: Unknown option `no-interaction`.
# after:  prompts answer with their default, normal output stays visible

Options declared with 'prompt' => ... are asked while argv is parsed, before the command applies either flag. The parser now checks --quiet and --no-interaction after reading argv and skips those prompts; a required option left without a value fails with the usual missing-option error. This also changes --quiet, which used to still ask these prompts.

Open question for review: should core also get a --yes / ConsoleIo::confirm() for "assume yes" confirmations? cakephp/migrations#1128 adds a command-level --yes for now.

Docs: cakephp/docs#8394

--quiet both lowers the output level and disables prompts. There was no
way to run a command non-interactively with normal output, and no getter
for the interactive state, so commands checked the output level instead.

--no-interaction is a long-only default option (-n is used by plugins)
that disables prompts without changing the output level. The interactive
state is now set before initialize(), so prompts there respect it too.
@dereuromark
dereuromark marked this pull request as ready for review November 20, 2026 17:42
Comment thread src/Console/BaseCommand.php Resolved
Comment thread src/Console/ConsoleOptionParser.php Resolved
Option prompts run inside ConsoleOptionParser::parse(), before the
command applies either flag, so a 'prompt' option could still block
an automated run. The parser now checks the flags after reading argv
and skips the prompt; a required option left empty fails with the
usual missing-option error. Skipping instead of asking non-interactively
also avoids askChoice() looping forever without a default.
@LordSimal
LordSimal merged commit eab3e7d into 5.next Nov 25, 2026
20 checks passed
@LordSimal
LordSimal deleted the console-no-interaction branch November 25, 2026 18:12
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.

4 participants