Skip to content

feat: add AbstractCommand::callSilently()#10177

Open
paulbalandan wants to merge 1 commit intocodeigniter4:4.8from
paulbalandan:call-silent
Open

feat: add AbstractCommand::callSilently()#10177
paulbalandan wants to merge 1 commit intocodeigniter4:4.8from
paulbalandan:call-silent

Conversation

@paulbalandan
Copy link
Copy Markdown
Member

Description
Extracted from michalsn's review on #10174.

Adds AbstractCommand::callSilently($command, $arguments, $options, $noInteractionOverride = true) to invoke another modern command with its output discarded, so the parent can emit its own consolidated message.

Two small supporting pieces:

  • CodeIgniter\CLI\NullInputOutput — an InputOutput sink that discards writes and returns an empty string from input().
  • CLI::getInputOutput() (@internal) — getter symmetric to the existing setInputOutput() / resetInputOutput() pair.

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

@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label May 9, 2026
Comment on lines +515 to +530
protected function callSilently(string $command, array $arguments = [], array $options = [], ?bool $noInteractionOverride = true): int
{
$priorIo = CLI::getInputOutput();

CLI::setInputOutput(new NullInputOutput());

try {
return $this->call($command, $arguments, $options, $noInteractionOverride);
} finally {
if ($priorIo instanceof InputOutput) {
CLI::setInputOutput($priorIo);
} else {
CLI::resetInputOutput();
}
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder... should we also restore the CLI::$lastWrite state? Or this isn't really important? Honestly, I can't decide.

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.

2 participants