mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
Explicitly define application commands
This commit is contained in:
parent
52430cbdde
commit
fa0740f216
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user