feat: add non-interactive session checking to modern commands#10134
feat: add non-interactive session checking to modern commands#10134paulbalandan wants to merge 3 commits intocodeigniter4:4.8from
Conversation
23fd7fd to
409db29
Compare
409db29 to
6cfa8ce
Compare
There was a problem hiding this comment.
Pull request overview
Adds a first-class non-interactive mode to CodeIgniter’s modern AbstractCommand CLI framework so commands don’t hang on prompts in CI/cron/piped executions, and propagates that state through sub-command calls.
Changes:
- Injects a default
--no-interaction/-Noption into all modern commands and skipsinteract()when non-interactive. - Adds
AbstractCommand::isInteractive()/setInteractive()plus interactive-state propagation semantics for$this->call(..., ?bool $noInteractionOverride). - Updates docs/changelog and expands system tests (including
logs:clearbehavior) to cover the new mode.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| user_guide_src/source/cli/cli_modern_commands.rst | Documents --no-interaction, interactive state precedence, and call() propagation/override semantics. |
| user_guide_src/source/changelogs/v4.8.0.rst | Adds changelog entry describing the new flag and APIs. |
| system/CLI/AbstractCommand.php | Implements interactive-state tracking, default option injection, call() override param, and propagation logic. |
| system/Commands/Housekeeping/ClearLogs.php | Adjusts abort messaging to show the --force hint only in non-interactive mode. |
| tests/system/CLI/AbstractCommandTest.php | Adds coverage for skipping interact(), isInteractive() behavior, and call() propagation/override cases. |
| tests/system/Commands/Housekeeping/ClearLogsTest.php | Adds data-driven test verifying non-interactive abort output includes the --force hint. |
| tests/system/Commands/HelpCommandTest.php | Updates expected help output to include -N, --no-interaction. |
| tests/_support/Commands/Modern/InteractiveStateProbeCommand.php | New fixture command to record whether interact() ran and what interactive state was observed. |
| tests/_support/Commands/Modern/ParentCallsInteractFixtureCommand.php | New fixture command to exercise call() interactive propagation and override behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
michalsn
left a comment
There was a problem hiding this comment.
I think we can "leak" the interactive state across repeated run() calls on the same command instance. This is not a problem for normal command usage, so I'm not sure if we should bother... although it can affect tests or other code that manually reuses a command object, like:
$cmd = new MyCommand();
$cmd->run([], ['no-interaction' => null]);
$cmd->run([], []);|
Fixed. The flag becomes a per-run switch. Only |
Description
Adds a non-interactive session capability to the modern
AbstractCommandframework introduced in #10120. Previouslyinteract()always fired, so modern commands could hang onCLI::prompt()when run in CI, cron, or piped contexts.This PR adds:
--no-interaction/-N.AbstractCommand:isInteractive(): boolandsetInteractive(bool): static.$this->call(...); a caller-supplied flag wins over propagation.?bool $noInteractionOverrideparameter oncall():null(default) propagates,trueforces non-interactive,falsestrips any inherited--no-interactionso the child resolves its own state.logs:clearnow shows its--forcehint only in non-interactive mode, resolving an existing@todo.Note
The shortcut is
-N(capital) rather than-nbecause several legacy migration commands:migrate,migrate:refresh,migrate:rollbackalready use-nas the shortcut for--namespace. Capital-Nleaves that shortcut free if any of those commands are later migrated toAbstractCommand.Checklist: