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
8 changes: 4 additions & 4 deletions system/Commands/Cache/ClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use CodeIgniter\Autoloader\FileLocatorCached;
use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Input\Argument;
use Config\Cache;

Expand All @@ -39,17 +38,18 @@ protected function execute(array $arguments, array $options): int
{
$driver = $arguments['driver'];
$config = config(Cache::class);
$output = $this->getOutput();

if (! array_key_exists($driver, $config->validHandlers)) {
CLI::error(lang('Cache.invalidHandler', [$driver]));
$output->error(lang('Cache.invalidHandler', [$driver]));

return EXIT_ERROR;
}

$config->handler = $driver;

if (! service('cache', $config)->clean()) {
CLI::error(sprintf('Error occurred while clearing the cache using the "%s" driver.', $driver));
$output->error(sprintf('Error occurred while clearing the cache using the "%s" driver.', $driver));

return EXIT_ERROR;
}
Expand All @@ -60,7 +60,7 @@ protected function execute(array $arguments, array $options): int
$locator->deleteCache();
}

CLI::write(sprintf('Cache cleared using the "%s" driver.', $driver), 'green');
$output->write(sprintf('Cache cleared using the "%s" driver.', $driver), 'green');

return EXIT_SUCCESS;
}
Expand Down
17 changes: 9 additions & 8 deletions system/Commands/Cache/InfoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Table;
use CodeIgniter\I18n\Time;
use Config\Cache;

Expand All @@ -28,9 +28,10 @@ class InfoCache extends AbstractCommand
protected function execute(array $arguments, array $options): int
{
$config = config(Cache::class);
$output = $this->getOutput();

if ($config->handler !== 'file') {
CLI::error(sprintf(
$output->error(sprintf(
'This command only supports the file cache handler. The configured handler is "%s".',
$config->handler,
));
Expand All @@ -52,12 +53,12 @@ protected function execute(array $arguments, array $options): int
];
}

CLI::table($tbody, [
CLI::color('Name', 'green'),
CLI::color('Server Path', 'green'),
CLI::color('Size', 'green'),
CLI::color('Date', 'green'),
]);
$output->write((new Table($tbody, [
$output->color('Name', 'green'),
$output->color('Server Path', 'green'),
$output->color('Size', 'green'),
$output->color('Date', 'green'),
]))->render());

return EXIT_SUCCESS;
}
Expand Down
8 changes: 4 additions & 4 deletions system/Commands/Housekeeping/ClearDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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

/**
* Clears all debugbar JSON files.
Expand All @@ -27,15 +26,16 @@ protected function execute(array $arguments, array $options): int
{
helper('filesystem');

$path = clean_path(WRITEPATH . 'debugbar');
$path = clean_path(WRITEPATH . 'debugbar');
$output = $this->getOutput();

if (! delete_files(WRITEPATH . 'debugbar', htdocs: true)) {
CLI::error(sprintf('Error deleting the debugbar JSON files in "%s".', $path));
$output->error(sprintf('Error deleting the debugbar JSON files in "%s".', $path));

return EXIT_ERROR;
}

CLI::write(sprintf('Cleared debugbar JSON files in "%s".', $path), 'green');
$output->write(sprintf('Cleared debugbar JSON files in "%s".', $path), 'green');

return EXIT_SUCCESS;
}
Expand Down
13 changes: 7 additions & 6 deletions system/Commands/Housekeeping/ClearLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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

/**
Expand All @@ -39,7 +38,7 @@ protected function interact(array &$arguments, array &$options): void
return;
}

if (CLI::prompt(sprintf('Delete all log files in %s?', clean_path(WRITEPATH . 'logs')), ['n', 'y']) === 'n') {
if ($this->getPrompt()->ask(sprintf('Delete all log files in %s?', clean_path(WRITEPATH . 'logs')), ['n', 'y']) === 'n') {
return;
}

Expand All @@ -48,27 +47,29 @@ protected function interact(array &$arguments, array &$options): void

protected function execute(array $arguments, array $options): int
{
$output = $this->getOutput();

if ($options['force'] === false) {
if ($this->isInteractive()) {
CLI::write('Log deletion cancelled.', 'yellow');
$output->write('Log deletion cancelled.', 'yellow');

return EXIT_SUCCESS;
}

CLI::error('Log deletion aborted: pass --force to delete log files in non-interactive mode.');
$output->error('Log deletion aborted: pass --force to delete log files in non-interactive mode.');

return EXIT_ERROR;
}

helper('filesystem');

if (! delete_files(WRITEPATH . 'logs', htdocs: true)) {
CLI::error(sprintf('Failed to delete log files in %s.', clean_path(WRITEPATH . 'logs')));
$output->error(sprintf('Failed to delete log files in %s.', clean_path(WRITEPATH . 'logs')));

return EXIT_ERROR;
}

CLI::write(sprintf('Log files in %s cleared.', clean_path(WRITEPATH . 'logs')), 'green');
$output->write(sprintf('Log files in %s cleared.', clean_path(WRITEPATH . 'logs')), 'green');

return EXIT_SUCCESS;
}
Expand Down
10 changes: 5 additions & 5 deletions system/Commands/Server/Serve.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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

/**
Expand Down Expand Up @@ -43,13 +42,14 @@ protected function execute(array $arguments, array $options): int
{
$basePort = (int) $options['port'];
$status = EXIT_SUCCESS;
$output = $this->getOutput();

for ($offset = 0; $offset <= self::RETRIES; $offset++) {
$port = $basePort + $offset;

CLI::write(sprintf('CodeIgniter development server started on http://%s:%s', $options['host'], $port), 'green');
CLI::write('Press Control-C to stop.');
CLI::newLine();
$output->write(sprintf('CodeIgniter development server started on http://%s:%s', $options['host'], $port), 'green');
$output->write('Press Control-C to stop.');
$output->newLine();

passthru(
$this->buildServeCommand($options['php'], $options['host'], $port, FCPATH, SYSTEMPATH . 'rewrite.php'),
Expand All @@ -60,7 +60,7 @@ protected function execute(array $arguments, array $options): int
return $status;
}

CLI::newLine();
$output->newLine();
}

return $status;
Expand Down
28 changes: 14 additions & 14 deletions system/Commands/Translation/LocalizationFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\Input\Option;
use CodeIgniter\CLI\Output;
use CodeIgniter\CLI\Table;
use CodeIgniter\CLI\Verbosity;
use CodeIgniter\Helpers\Array\ArrayHelper;
use Config\App;
Expand Down Expand Up @@ -67,14 +68,15 @@ protected function execute(array $arguments, array $options): int
assert(is_string($dir));

$currentLocale = Locale::getDefault();
$output = $this->getOutput();

['currentDir' => $currentDir, 'languagePath' => $this->languagePath] = $this->resolvePaths();

if ($locale !== '') {
$supportedLocales = config(App::class)->supportedLocales;

if (! in_array($locale, $supportedLocales, true)) {
CLI::error(
$output->error(
sprintf(
'Error: "%s" is not supported. Supported locales: %s',
$locale,
Expand All @@ -94,23 +96,23 @@ protected function execute(array $arguments, array $options): int
$tempCurrentDir = realpath($currentDir . $dir);

if ($tempCurrentDir === false) {
CLI::error(sprintf('Error: Directory must be located in "%s"', $currentDir), 'light_gray', 'red');
$output->error(sprintf('Error: Directory must be located in "%s"', $currentDir), 'light_gray', 'red');

return EXIT_USER_INPUT;
}

if ($this->isSubdirectory($tempCurrentDir, $this->languagePath)) {
CLI::error(sprintf('Error: Directory "%s" restricted to scan.', $this->languagePath), 'light_gray', 'red');
$output->error(sprintf('Error: Directory "%s" restricted to scan.', $this->languagePath), 'light_gray', 'red');

return EXIT_USER_INPUT;
}

$currentDir = $tempCurrentDir;
}

$this->process($currentDir, $currentLocale);
$this->process($output, $currentDir, $currentLocale);

CLI::write('All operations done!', 'green');
$output->write('All operations done!', 'green');

return EXIT_SUCCESS;
}
Expand All @@ -136,10 +138,9 @@ private function resolvePaths(): array
];
}

private function process(string $currentDir, string $currentLocale): void
private function process(Output $output, string $currentDir, string $currentLocale): void
{
$showNew = $this->getValidatedOption('show-new') === true;
$output = $this->getOutput();

$tableRows = [];
$countNewKeys = 0;
Expand All @@ -152,7 +153,7 @@ private function process(string $currentDir, string $currentLocale): void
'foundLanguageKeys' => $foundLanguageKeys,
'badLanguageKeys' => $badLanguageKeys,
'countFiles' => $countFiles,
] = $this->findLanguageKeysInFiles($files);
] = $this->findLanguageKeysInFiles($output, $files);

ksort($foundLanguageKeys);

Expand Down Expand Up @@ -189,11 +190,11 @@ private function process(string $currentDir, string $currentLocale): void

if ($showNew && $tableRows !== []) {
sort($tableRows);
CLI::table($tableRows, ['File', 'Key']);
$output->write((new Table($tableRows, ['File', 'Key']))->render());
}

if (! $showNew && $countNewKeys > 0) {
CLI::write('Note: You need to run your linting tool to fix coding standards issues.', 'white', 'red');
$output->write('Note: You need to run your linting tool to fix coding standards issues.', 'white', 'red');
}

$output->write(sprintf('Files found: %d', $countFiles), verbosity: Verbosity::Verbose);
Expand All @@ -209,7 +210,7 @@ private function process(string $currentDir, string $currentLocale): void

ArrayHelper::sortValuesByNatural($tableBadRows, 0);

CLI::table($tableBadRows, ['Bad Key', 'Filepath']);
$output->write((new Table($tableBadRows, ['Bad Key', 'Filepath']))->render());
}
}

Expand Down Expand Up @@ -423,12 +424,11 @@ private function isSubdirectory(string $directory, string $rootDirectory): bool
*
* @return array{'foundLanguageKeys': array<string, array<string, string>>, 'badLanguageKeys': array<int, array<int, string>>, 'countFiles': int}
*/
private function findLanguageKeysInFiles(array $files): array
private function findLanguageKeysInFiles(Output $output, array $files): array
{
$foundLanguageKeys = [];
$badLanguageKeys = [];
$countFiles = 0;
$output = $this->getOutput();

foreach ($files as $file) {
if ($this->isIgnoredFile($file)) {
Expand Down
Loading
Loading