diff --git a/docs/en/appendices/5-5-migration-guide.md b/docs/en/appendices/5-5-migration-guide.md index 132f91a59f..11ab2e823a 100644 --- a/docs/en/appendices/5-5-migration-guide.md +++ b/docs/en/appendices/5-5-migration-guide.md @@ -43,6 +43,15 @@ bin/cake upgrade rector --rules cakephp55 `BadRequestException` (HTTP 400). See [HTTP Method Overrides](../controllers/request-response#http-method-overrides). +### Console + +- `--quiet` now also skips options defined with `prompt`. Previously these + were asked while arguments were parsed, before `--quiet` took effect. A + required option left without a value now fails with the usual missing option + error instead of waiting for input. +- Commands are switched to non-interactive mode before `initialize()` runs, so + prompts in `initialize()` respect `--quiet` and `--no-interaction` too. + ## Deprecations ### Database @@ -65,6 +74,15 @@ bin/cake upgrade rector --rules cakephp55 the path expression is used if not set. - `FunctionsBuilder::jsonExists()` was added. +### Console + +- `ConsoleIo::isInteractive()` was added. +- `--no-interaction` was added to the default command options. It disables + prompts, which answer with their default value, while keeping the normal + output level. Unlike `--quiet` it does not hide output. If your application + already defines a `no-interaction` option, you can remove it, or keep it. + The option definition in your application replaces the default one. + ### TestSuite - `Cake\TestSuite\Fixture\DeleteStrategy` was added. This fixture strategy diff --git a/docs/en/console-commands/input-output.md b/docs/en/console-commands/input-output.md index e70f28ceff..af71999789 100644 --- a/docs/en/console-commands/input-output.md +++ b/docs/en/console-commands/input-output.md @@ -278,6 +278,20 @@ $selection = $io->askChoice('Red or Green?', ['R', 'G'], 'R'); Selection validation is case-insensitive. +When a command runs with `--quiet` or `--no-interaction`, prompts are not +shown and `ask()` and `askChoice()` return their default value. Use +`$io->isInteractive()` to check whether prompts are enabled, for example to +skip a confirmation step. Options defined with `prompt` are not asked either; +a required option without a value then fails with a missing option error. + +```text +bin/cake my_command --no-interaction +``` + +::: info Added in version 5.5.0 +`ConsoleIo::isInteractive()` and the `--no-interaction` option were added. +::: + ## Creating Files `method` Cake\\Console\\ConsoleIo::**createFile**(string $path, string $contents, bool $forceOverwrite = false): bool @@ -409,6 +423,9 @@ You can control the output level of commands, by using the `--quiet` and `--verbose` options. These options are added by default, and allow you to consistently control output levels inside your CakePHP commands. +`--quiet` also disables interactive prompts. To disable prompts but keep the +normal output, use `--no-interaction` instead. + The `--quiet` and `--verbose` options also control how logging data is output to stdout/stderr. Normally info and higher log messages are output to stdout/stderr. When `--verbose` is used, debug logs will be output to stdout.