From ab3f66916a169a8e5b02dc23c7a3448ddb99f040 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 3 Nov 2026 14:39:44 +0800 Subject: [PATCH] docs: use `$this->getOutput()` and `$this->getPrompt()` in the modern command samples --- user_guide_src/source/cli/cli_modern_commands.rst | 3 +++ user_guide_src/source/cli/cli_modern_commands/001.php | 3 +-- user_guide_src/source/cli/cli_modern_commands/004.php | 5 ++--- user_guide_src/source/cli/cli_modern_commands/010.php | 5 ++--- user_guide_src/source/cli/cli_modern_commands/012.php | 4 +--- user_guide_src/source/cli/cli_modern_commands/015.php | 3 +-- user_guide_src/source/cli/cli_modern_commands/017.php | 3 +-- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/user_guide_src/source/cli/cli_modern_commands.rst b/user_guide_src/source/cli/cli_modern_commands.rst index 5477dffb02f7..5f0280030012 100644 --- a/user_guide_src/source/cli/cli_modern_commands.rst +++ b/user_guide_src/source/cli/cli_modern_commands.rst @@ -520,6 +520,9 @@ definitions rather than class properties and ad-hoc lookups. ``$this->showError($e)`` Becomes ``$this->renderThrowable($e)``. +``CLI::write()``, ``CLI::error()``, and the other writers + Use the same methods on ``$this->getOutput()``. See :ref:`modern-commands-writing-output`. + ``showHelp()`` override Gone. The built-in ``help`` command builds the help output itself from the declared arguments, options, and usages. diff --git a/user_guide_src/source/cli/cli_modern_commands/001.php b/user_guide_src/source/cli/cli_modern_commands/001.php index 0033a19b122b..302ddae19c6d 100644 --- a/user_guide_src/source/cli/cli_modern_commands/001.php +++ b/user_guide_src/source/cli/cli_modern_commands/001.php @@ -4,14 +4,13 @@ use CodeIgniter\CLI\AbstractCommand; use CodeIgniter\CLI\Attributes\Command; -use CodeIgniter\CLI\CLI; #[Command(name: 'app:greet', description: 'Prints a greeting.', group: 'App')] class AppGreet extends AbstractCommand { protected function execute(array $arguments, array $options): int { - CLI::write('Hello!', 'green'); + $this->getOutput()->write('Hello!', 'green'); return EXIT_SUCCESS; } diff --git a/user_guide_src/source/cli/cli_modern_commands/004.php b/user_guide_src/source/cli/cli_modern_commands/004.php index 5c9340d07f41..e1764f6442c6 100644 --- a/user_guide_src/source/cli/cli_modern_commands/004.php +++ b/user_guide_src/source/cli/cli_modern_commands/004.php @@ -4,7 +4,6 @@ use CodeIgniter\CLI\AbstractCommand; use CodeIgniter\CLI\Attributes\Command; -use CodeIgniter\CLI\CLI; use CodeIgniter\CLI\Input\Option; #[Command(name: 'logs:clear', description: 'Clears logs.', group: 'Housekeeping')] @@ -27,7 +26,7 @@ protected function interact(array &$arguments, array &$options): void return; } - if (CLI::prompt('Delete the logs?', ['n', 'y']) === 'n') { + if ($this->getPrompt()->ask('Delete the logs?', ['n', 'y']) === 'n') { return; } @@ -39,7 +38,7 @@ protected function interact(array &$arguments, array &$options): void protected function execute(array $arguments, array $options): int { if ($this->getValidatedOption('force') === false) { - CLI::error('Aborted.'); + $this->getOutput()->error('Aborted.'); return EXIT_ERROR; } diff --git a/user_guide_src/source/cli/cli_modern_commands/010.php b/user_guide_src/source/cli/cli_modern_commands/010.php index 3f2c63764d6a..3d8740250558 100644 --- a/user_guide_src/source/cli/cli_modern_commands/010.php +++ b/user_guide_src/source/cli/cli_modern_commands/010.php @@ -4,7 +4,6 @@ use CodeIgniter\CLI\AbstractCommand; use CodeIgniter\CLI\Attributes\Command; -use CodeIgniter\CLI\CLI; use CodeIgniter\CLI\Input\Argument; use CodeIgniter\CLI\Input\Option; use Throwable; @@ -23,7 +22,7 @@ protected function configure(): void protected function interact(array &$arguments, array &$options): void { if ($arguments === []) { - $arguments[] = CLI::prompt('What should I publish?', null, 'required'); + $arguments[] = $this->getPrompt()->ask('What should I publish?', null, 'required'); } } @@ -50,6 +49,6 @@ private function publish(string $target): void // ... unset($force, $dryRun); - CLI::write(sprintf('publishing %s', $target), 'green'); + $this->getOutput()->write(sprintf('publishing %s', $target), 'green'); } } diff --git a/user_guide_src/source/cli/cli_modern_commands/012.php b/user_guide_src/source/cli/cli_modern_commands/012.php index 0963ccccc08c..48136eb2cfe5 100644 --- a/user_guide_src/source/cli/cli_modern_commands/012.php +++ b/user_guide_src/source/cli/cli_modern_commands/012.php @@ -1,12 +1,10 @@ callSilently('cache:clear'); if ($exitCode === EXIT_SUCCESS) { - CLI::write('Cache cleared as part of deploy step.', 'green'); + $this->getOutput()->write('Cache cleared as part of deploy step.', 'green'); } diff --git a/user_guide_src/source/cli/cli_modern_commands/015.php b/user_guide_src/source/cli/cli_modern_commands/015.php index 297e3b2eeb4f..2c1ca3f7e51f 100644 --- a/user_guide_src/source/cli/cli_modern_commands/015.php +++ b/user_guide_src/source/cli/cli_modern_commands/015.php @@ -4,7 +4,6 @@ use CodeIgniter\CLI\AbstractCommand; use CodeIgniter\CLI\Attributes\Command; -use CodeIgniter\CLI\CLI; use CodeIgniter\CLI\Input\Argument; use CodeIgniter\CLI\PromptsForMissingInputInterface; @@ -27,7 +26,7 @@ protected function getArgumentPromptLabels(): array protected function execute(array $arguments, array $options): int { - CLI::write(sprintf('Hello, %s!', $arguments['name']), 'green'); + $this->getOutput()->write(sprintf('Hello, %s!', $arguments['name']), 'green'); return EXIT_SUCCESS; } diff --git a/user_guide_src/source/cli/cli_modern_commands/017.php b/user_guide_src/source/cli/cli_modern_commands/017.php index d402ea75f6e1..dbea0d5523ab 100644 --- a/user_guide_src/source/cli/cli_modern_commands/017.php +++ b/user_guide_src/source/cli/cli_modern_commands/017.php @@ -4,7 +4,6 @@ use CodeIgniter\CLI\AbstractCommand; use CodeIgniter\CLI\Attributes\Command; -use CodeIgniter\CLI\CLI; #[Command( name: 'app:status', @@ -16,7 +15,7 @@ class AppStatus extends AbstractCommand { protected function execute(array $arguments, array $options): int { - CLI::write(json_encode(['status' => 'ok'], JSON_THROW_ON_ERROR)); + $this->getOutput()->write(json_encode(['status' => 'ok'], JSON_THROW_ON_ERROR)); return EXIT_SUCCESS; }