Skip to content

Commit 0b98c7e

Browse files
authored
docs: use $this->getOutput() and $this->getPrompt() in the modern command samples (#10711)
1 parent c54f555 commit 0b98c7e

7 files changed

Lines changed: 11 additions & 15 deletions

File tree

‎user_guide_src/source/cli/cli_modern_commands.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ expressed through an attribute and explicit definitions rather than class proper
473473
``$this->showError($e)``
474474
Becomes ``$this->renderThrowable($e)``.
475475

476+
``CLI::write()``, ``CLI::error()``, and the other writers
477+
Use the same methods on ``$this->getOutput()``. See :ref:`modern-commands-writing-output`.
478+
476479
``showHelp()`` override
477480
Gone. The built-in ``help`` command builds the help output itself from the declared arguments, options, and usages.
478481

‎user_guide_src/source/cli/cli_modern_commands/001.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
use CodeIgniter\CLI\AbstractCommand;
66
use CodeIgniter\CLI\Attributes\Command;
7-
use CodeIgniter\CLI\CLI;
87

98
#[Command(name: 'app:greet', description: 'Prints a greeting.', group: 'App')]
109
class AppGreet extends AbstractCommand
1110
{
1211
protected function execute(array $arguments, array $options): int
1312
{
14-
CLI::write('Hello!', 'green');
13+
$this->getOutput()->write('Hello!', 'green');
1514

1615
return EXIT_SUCCESS;
1716
}

‎user_guide_src/source/cli/cli_modern_commands/004.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use CodeIgniter\CLI\AbstractCommand;
66
use CodeIgniter\CLI\Attributes\Command;
7-
use CodeIgniter\CLI\CLI;
87
use CodeIgniter\CLI\Input\Option;
98

109
#[Command(name: 'logs:clear', description: 'Clears logs.', group: 'Housekeeping')]
@@ -27,7 +26,7 @@ protected function interact(array &$arguments, array &$options): void
2726
return;
2827
}
2928

30-
if (CLI::prompt('Delete the logs?', ['n', 'y']) === 'n') {
29+
if ($this->getPrompt()->ask('Delete the logs?', ['n', 'y']) === 'n') {
3130
return;
3231
}
3332

@@ -39,7 +38,7 @@ protected function interact(array &$arguments, array &$options): void
3938
protected function execute(array $arguments, array $options): int
4039
{
4140
if ($this->getValidatedOption('force') === false) {
42-
CLI::error('Aborted.');
41+
$this->getOutput()->error('Aborted.');
4342

4443
return EXIT_ERROR;
4544
}

‎user_guide_src/source/cli/cli_modern_commands/010.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use CodeIgniter\CLI\AbstractCommand;
66
use CodeIgniter\CLI\Attributes\Command;
7-
use CodeIgniter\CLI\CLI;
87
use CodeIgniter\CLI\Input\Argument;
98
use CodeIgniter\CLI\Input\Option;
109
use Throwable;
@@ -23,7 +22,7 @@ protected function configure(): void
2322
protected function interact(array &$arguments, array &$options): void
2423
{
2524
if ($arguments === []) {
26-
$arguments[] = CLI::prompt('What should I publish?', null, 'required');
25+
$arguments[] = $this->getPrompt()->ask('What should I publish?', null, 'required');
2726
}
2827
}
2928

@@ -50,6 +49,6 @@ private function publish(string $target): void
5049
// ...
5150
unset($force, $dryRun);
5251

53-
CLI::write(sprintf('publishing %s', $target), 'green');
52+
$this->getOutput()->write(sprintf('publishing %s', $target), 'green');
5453
}
5554
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<?php
22

3-
use CodeIgniter\CLI\CLI;
4-
53
// Inside execute():
64

75
// Run `cache:clear` without leaking its own output; emit our own message instead.
86
$exitCode = $this->callSilently('cache:clear');
97

108
if ($exitCode === EXIT_SUCCESS) {
11-
CLI::write('Cache cleared as part of deploy step.', 'green');
9+
$this->getOutput()->write('Cache cleared as part of deploy step.', 'green');
1210
}

‎user_guide_src/source/cli/cli_modern_commands/015.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use CodeIgniter\CLI\AbstractCommand;
66
use CodeIgniter\CLI\Attributes\Command;
7-
use CodeIgniter\CLI\CLI;
87
use CodeIgniter\CLI\Input\Argument;
98
use CodeIgniter\CLI\PromptsForMissingInputInterface;
109

@@ -27,7 +26,7 @@ protected function getArgumentPromptLabels(): array
2726

2827
protected function execute(array $arguments, array $options): int
2928
{
30-
CLI::write(sprintf('Hello, %s!', $arguments['name']), 'green');
29+
$this->getOutput()->write(sprintf('Hello, %s!', $arguments['name']), 'green');
3130

3231
return EXIT_SUCCESS;
3332
}

‎user_guide_src/source/cli/cli_modern_commands/017.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use CodeIgniter\CLI\AbstractCommand;
66
use CodeIgniter\CLI\Attributes\Command;
7-
use CodeIgniter\CLI\CLI;
87

98
#[Command(
109
name: 'app:status',
@@ -16,7 +15,7 @@ class AppStatus extends AbstractCommand
1615
{
1716
protected function execute(array $arguments, array $options): int
1817
{
19-
CLI::write(json_encode(['status' => 'ok'], JSON_THROW_ON_ERROR));
18+
$this->getOutput()->write(json_encode(['status' => 'ok'], JSON_THROW_ON_ERROR));
2019

2120
return EXIT_SUCCESS;
2221
}

0 commit comments

Comments
 (0)