From fa0740f2168363128050082ace2751541e8db0a6 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Tue, 12 Sep 2023 16:27:07 +0200 Subject: [PATCH] Explicitly define application commands --- src/SPC/ConsoleApplication.php | 50 +++++++++++++---------- src/SPC/command/DeployCommand.php | 2 +- src/SPC/command/dev/SortConfigCommand.php | 2 +- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/SPC/ConsoleApplication.php b/src/SPC/ConsoleApplication.php index f43463ee..09c57238 100644 --- a/src/SPC/ConsoleApplication.php +++ b/src/SPC/ConsoleApplication.php @@ -4,7 +4,17 @@ declare(strict_types=1); namespace SPC; -use SPC\store\FileSystem; +use SPC\command\BuildCliCommand; +use SPC\command\BuildLibsCommand; +use SPC\command\DeployCommand; +use SPC\command\dev\AllExtCommand; +use SPC\command\dev\PhpVerCommand; +use SPC\command\dev\SortConfigCommand; +use SPC\command\DoctorCommand; +use SPC\command\DownloadCommand; +use SPC\command\DumpLicenseCommand; +use SPC\command\ExtractCommand; +use SPC\command\MicroCombineCommand; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\HelpCommand; use Symfony\Component\Console\Command\ListCommand; @@ -12,14 +22,10 @@ use Symfony\Component\Console\Command\ListCommand; /** * static-php-cli console app entry */ -class ConsoleApplication extends Application +final class ConsoleApplication extends Application { public const VERSION = '2.0-rc6'; - /** - * @throws \ReflectionException - * @throws exception\FileSystemException - */ public function __construct() { parent::__construct('static-php-cli', self::VERSION); @@ -29,21 +35,23 @@ class ConsoleApplication extends Application // Detailed debugging errors are not displayed in the production environment. Only the error display provided by Symfony console is used. $this->setCatchExceptions(file_exists(ROOT_DIR . '/.prod') || !in_array('--debug', $argv)); - // Add subcommands by scanning the directory src/static-php-cli/command/ - $commands = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/command', 'SPC\\command'); - $phar = class_exists('\\Phar') && \Phar::running() || !class_exists('\\Phar'); - $commands = array_filter($commands, function ($y) use ($phar) { - $archive_blacklist = [ - 'SPC\command\dev\SortConfigCommand', - 'SPC\command\DeployCommand', - ]; - if ($phar && in_array($y, $archive_blacklist)) { - return false; - } - $reflection = new \ReflectionClass($y); - return !$reflection->isAbstract() && !$reflection->isInterface(); - }); - $this->addCommands(array_map(function ($x) { return new $x(); }, $commands)); + $this->addCommands( + [ + new BuildCliCommand(), + new BuildLibsCommand(), + new DeployCommand(), + new DoctorCommand(), + new DownloadCommand(), + new DumpLicenseCommand(), + new ExtractCommand(), + new MicroCombineCommand(), + + // Dev commands + new AllExtCommand(), + new PhpVerCommand(), + new SortConfigCommand(), + ] + ); } protected function getDefaultCommands(): array diff --git a/src/SPC/command/DeployCommand.php b/src/SPC/command/DeployCommand.php index b5353619..770fc39c 100644 --- a/src/SPC/command/DeployCommand.php +++ b/src/SPC/command/DeployCommand.php @@ -13,7 +13,7 @@ use Symfony\Component\Console\Input\InputOption; use function Laravel\Prompts\confirm; use function Laravel\Prompts\text; -#[AsCommand('deploy', 'Deploy static-php-cli self to an .phar application')] +#[AsCommand('deploy', 'Deploy static-php-cli self to an .phar application', [], true)] class DeployCommand extends BaseCommand { public function configure(): void diff --git a/src/SPC/command/dev/SortConfigCommand.php b/src/SPC/command/dev/SortConfigCommand.php index bee44ff9..8eb7680a 100644 --- a/src/SPC/command/dev/SortConfigCommand.php +++ b/src/SPC/command/dev/SortConfigCommand.php @@ -15,7 +15,7 @@ use Symfony\Component\Console\Input\InputArgument; /** * Modify config file: sort lib, ext, source by name. */ -#[AsCommand('dev:sort-config', 'After config edited, sort it by alphabet', ['sort-config'])] +#[AsCommand('dev:sort-config', 'After config edited, sort it by alphabet', ['sort-config'], true)] class SortConfigCommand extends BaseCommand { public function configure(): void