From 26fb211d5cc46489ae69a0c326acde150f4e7a09 Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Fri, 11 Feb 2022 13:22:44 +0300 Subject: [PATCH] Clean up commands text to be consistent. --- console | 2 +- src/Commands/Config/DumpCommand.php | 12 +++--------- src/Commands/Config/GenerateCommand.php | 12 ++---------- src/Commands/Config/PHPCommand.php | 6 +++--- src/Commands/State/ExportCommand.php | 17 ++++------------- src/Commands/State/ImportCommand.php | 17 +++++------------ src/Commands/Storage/MaintenanceCommand.php | 2 +- src/Commands/Storage/MakeCommand.php | 2 +- src/Commands/Storage/MigrationsCommand.php | 4 ++-- src/Libs/KernelConsole.php | 4 ++-- 10 files changed, 24 insertions(+), 54 deletions(-) diff --git a/console b/console index c8544991..a7a132ab 100644 --- a/console +++ b/console @@ -18,7 +18,7 @@ if (!defined('DS')) { } if (!defined('ROOT_PATH')) { - define('ROOT_PATH', __DIR__); + define('ROOT_PATH', realpath(__DIR__)); } set_error_handler(function (int $number, mixed $error, mixed $file, int $line) { diff --git a/src/Commands/Config/DumpCommand.php b/src/Commands/Config/DumpCommand.php index 01c0b988..3e107f45 100644 --- a/src/Commands/Config/DumpCommand.php +++ b/src/Commands/Config/DumpCommand.php @@ -22,19 +22,13 @@ class DumpCommand extends Command protected function configure(): void { $this->setName('config:dump') - ->setDescription('Dump configs to customize.') - ->addOption( - 'location', - 'l', - InputOption::VALUE_OPTIONAL, - 'Path to config dir.', - Config::get('path'), - ) + ->setDescription('Create config files.') + ->addOption('location', 'l', InputOption::VALUE_OPTIONAL, 'Path to config dir.', Config::get('path')) ->addOption('override', 'w', InputOption::VALUE_NONE, 'Override existing file.') ->addArgument( 'type', InputArgument::REQUIRED, - sprintf('Config to dump. Can be one of ( %s )', implode(' or ', array_keys(self::$configs))) + sprintf('Config type to create. Can be one of ( %s )', implode(' or ', array_keys(self::$configs))) ); } diff --git a/src/Commands/Config/GenerateCommand.php b/src/Commands/Config/GenerateCommand.php index 09590c1e..5eb3a57b 100644 --- a/src/Commands/Config/GenerateCommand.php +++ b/src/Commands/Config/GenerateCommand.php @@ -18,7 +18,7 @@ class GenerateCommand extends Command { $this->setName('config:generate') ->setDescription('Generate API key for webhook.') - ->addOption('regenerate', 'w', InputOption::VALUE_NONE, 'Regenerate the API key'); + ->addOption('regenerate', 'w', InputOption::VALUE_NONE, 'Regenerate the API key.'); } /** @@ -37,7 +37,7 @@ class GenerateCommand extends Command } } - $randomKey = $this->generateHash(); + $randomKey = bin2hex(random_bytes(16)); $output->writeln(sprintf('Your Webhook API key is: %s', $randomKey)); @@ -45,12 +45,4 @@ class GenerateCommand extends Command return self::SUCCESS; } - - /** - * @throws Exception - */ - private function generateHash(): string - { - return bin2hex(random_bytes(16)); - } } diff --git a/src/Commands/Config/PHPCommand.php b/src/Commands/Config/PHPCommand.php index 378d1881..42789299 100644 --- a/src/Commands/Config/PHPCommand.php +++ b/src/Commands/Config/PHPCommand.php @@ -15,11 +15,11 @@ final class PHPCommand extends Command protected function configure(): void { $this->setName('config:php') - ->setDescription('Generate PHP Config') - ->addOption('fpm', null, InputOption::VALUE_NONE, 'Generate FPM Config.'); + ->setDescription('Generate php config.') + ->addOption('fpm', null, InputOption::VALUE_NONE, 'Generate php-fpm config.'); } - protected function execute(InputInterface $input, OutputInterface $output): int + protected function runCommand(InputInterface $input, OutputInterface $output): int { return $input->getOption('fpm') ? $this->makeFPM($output) : $this->makeConfig($output); } diff --git a/src/Commands/State/ExportCommand.php b/src/Commands/State/ExportCommand.php index 987d6124..e80975e6 100644 --- a/src/Commands/State/ExportCommand.php +++ b/src/Commands/State/ExportCommand.php @@ -25,9 +25,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Yaml\Yaml; use Throwable; -use function ag; -use function makeDate; - class ExportCommand extends Command { public function __construct(private ExportInterface $mapper, private Request $http, private LoggerInterface $logger) @@ -42,21 +39,15 @@ class ExportCommand extends Command { $this->setName('state:export') ->setDescription('Export watch state to servers.') - ->addOption( - 'read-mapper', - null, - InputOption::VALUE_OPTIONAL, - 'Shows what kind of mapper configured.', - $this->mapper::class - ) - ->addOption('redirect-logger', 'r', InputOption::VALUE_NONE, 'Redirect logger to stderr.') - ->addOption('memory-usage', 'm', InputOption::VALUE_NONE, 'Display memory usage.') + ->addOption('read-mapper', null, InputOption::VALUE_OPTIONAL, 'Configured mapper.', $this->mapper::class) + ->addOption('redirect-logger', 'r', InputOption::VALUE_NONE, 'Redirect logger to stdout.') + ->addOption('memory-usage', 'm', InputOption::VALUE_NONE, 'Show memory usage.') ->addOption('force-full', 'f', InputOption::VALUE_NONE, 'Force full export.') ->addOption( 'concurrency', null, InputOption::VALUE_OPTIONAL, - 'How many Requests to send.', + 'How many parallel requests to send.', (int)Config::get('request.export.concurrency') ) ->addOption( diff --git a/src/Commands/State/ImportCommand.php b/src/Commands/State/ImportCommand.php index a64adc91..76cfee30 100644 --- a/src/Commands/State/ImportCommand.php +++ b/src/Commands/State/ImportCommand.php @@ -21,9 +21,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Yaml\Yaml; -use function ag; -use function makeDate; - class ImportCommand extends Command { public function __construct(private ImportInterface $mapper, private LoggerInterface $logger) @@ -38,15 +35,9 @@ class ImportCommand extends Command { $this->setName('state:import') ->setDescription('Import watch state from servers.') - ->addOption( - 'read-mapper', - null, - InputOption::VALUE_OPTIONAL, - 'Shows what kind of mapper configured.', - $this->mapper::class - ) - ->addOption('redirect-logger', 'r', InputOption::VALUE_NONE, 'Redirect logger to stderr.') - ->addOption('memory-usage', 'm', InputOption::VALUE_NONE, 'Display memory usage.') + ->addOption('read-mapper', null, InputOption::VALUE_OPTIONAL, 'Configured Mapper.', $this->mapper::class) + ->addOption('redirect-logger', 'r', InputOption::VALUE_NONE, 'Redirect logger to stdout.') + ->addOption('memory-usage', 'm', InputOption::VALUE_NONE, 'Show memory usage.') ->addOption('force-full', 'f', InputOption::VALUE_NONE, 'Force full import.') ->addOption( 'servers-filter', @@ -181,7 +172,9 @@ class ImportCommand extends Command Utils::settle($promises)->wait(); $this->logger->notice(sprintf('Finished waiting on (%d) HTTP Requests.', count($promises))); + $this->logger->notice(sprintf('Committing (%d) Changes.', count($this->mapper))); $operations = $this->mapper->commit(); + $this->logger->notice('Finished Committing the changes.'); if ($input->getOption('stats-show')) { Data::add('operations', 'stats', $operations); diff --git a/src/Commands/Storage/MaintenanceCommand.php b/src/Commands/Storage/MaintenanceCommand.php index c16e1fd6..d00bd554 100644 --- a/src/Commands/Storage/MaintenanceCommand.php +++ b/src/Commands/Storage/MaintenanceCommand.php @@ -22,7 +22,7 @@ final class MaintenanceCommand extends Command ->setDescription('Run maintenance tasks on storage backend.'); } - protected function execute(InputInterface $input, OutputInterface $output): int + protected function runCommand(InputInterface $input, OutputInterface $output): int { $this->storage->maintenance($input, $output); diff --git a/src/Commands/Storage/MakeCommand.php b/src/Commands/Storage/MakeCommand.php index bbfb5f37..22d81686 100644 --- a/src/Commands/Storage/MakeCommand.php +++ b/src/Commands/Storage/MakeCommand.php @@ -23,7 +23,7 @@ final class MakeCommand extends Command $this->setName('storage:make') ->setDescription('Create Storage backend migration.') ->addOption('extra', null, InputOption::VALUE_OPTIONAL, 'Extra options.', null) - ->addArgument('name', InputArgument::REQUIRED, 'Migration name'); + ->addArgument('name', InputArgument::REQUIRED, 'Migration name.'); } protected function runCommand(InputInterface $input, OutputInterface $output): int diff --git a/src/Commands/Storage/MigrationsCommand.php b/src/Commands/Storage/MigrationsCommand.php index 6458ce85..84644b08 100644 --- a/src/Commands/Storage/MigrationsCommand.php +++ b/src/Commands/Storage/MigrationsCommand.php @@ -22,8 +22,8 @@ final class MigrationsCommand extends Command { $this->setName('storage:migrations') ->setDescription('Update storage backend schema.') - ->addOption('extra', null, InputOption::VALUE_OPTIONAL, 'Extra options', null) - ->addOption('fresh', 'f', InputOption::VALUE_NONE, 'Start migrations from start') + ->addOption('extra', null, InputOption::VALUE_OPTIONAL, 'Extra options.', null) + ->addOption('fresh', 'f', InputOption::VALUE_NONE, 'Start migrations from start.') ->addArgument('direction', InputArgument::OPTIONAL, 'Migrations path (up/down).', 'up'); } diff --git a/src/Libs/KernelConsole.php b/src/Libs/KernelConsole.php index a3443130..c180939f 100644 --- a/src/Libs/KernelConsole.php +++ b/src/Libs/KernelConsole.php @@ -131,9 +131,9 @@ class KernelConsole public function runHttp( Closure $fn, ServerRequestInterface|null $request = null, - EmitterInterface|null $emit = null + EmitterInterface|null $emitter = null ): void { - $emitter = $emit ?? new SapiEmitter(); + $emitter = $emitter ?? new SapiEmitter(); $request = $request ?? ServerRequestFactory::fromGlobals(); try {