Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions user_guide_src/source/cli/cli_modern_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 1 addition & 2 deletions user_guide_src/source/cli/cli_modern_commands/001.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions user_guide_src/source/cli/cli_modern_commands/004.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions user_guide_src/source/cli/cli_modern_commands/010.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
}
}

Expand All @@ -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');
}
}
4 changes: 1 addition & 3 deletions user_guide_src/source/cli/cli_modern_commands/012.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php

use CodeIgniter\CLI\CLI;

// Inside execute():

// Run `cache:clear` without leaking its own output; emit our own message instead.
$exitCode = $this->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');
}
3 changes: 1 addition & 2 deletions user_guide_src/source/cli/cli_modern_commands/015.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions user_guide_src/source/cli/cli_modern_commands/017.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;

#[Command(
name: 'app:status',
Expand All @@ -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;
}
Expand Down