mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-13 20:05:35 +08:00
Explicitly define application commands
This commit is contained in:
committed by
Jerry Ma
parent
52430cbdde
commit
fa0740f216
@@ -4,7 +4,17 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC;
|
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\Application;
|
||||||
use Symfony\Component\Console\Command\HelpCommand;
|
use Symfony\Component\Console\Command\HelpCommand;
|
||||||
use Symfony\Component\Console\Command\ListCommand;
|
use Symfony\Component\Console\Command\ListCommand;
|
||||||
@@ -12,14 +22,10 @@ use Symfony\Component\Console\Command\ListCommand;
|
|||||||
/**
|
/**
|
||||||
* static-php-cli console app entry
|
* static-php-cli console app entry
|
||||||
*/
|
*/
|
||||||
class ConsoleApplication extends Application
|
final class ConsoleApplication extends Application
|
||||||
{
|
{
|
||||||
public const VERSION = '2.0-rc6';
|
public const VERSION = '2.0-rc6';
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws \ReflectionException
|
|
||||||
* @throws exception\FileSystemException
|
|
||||||
*/
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct('static-php-cli', self::VERSION);
|
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.
|
// 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));
|
$this->setCatchExceptions(file_exists(ROOT_DIR . '/.prod') || !in_array('--debug', $argv));
|
||||||
|
|
||||||
// Add subcommands by scanning the directory src/static-php-cli/command/
|
$this->addCommands(
|
||||||
$commands = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/command', 'SPC\\command');
|
[
|
||||||
$phar = class_exists('\\Phar') && \Phar::running() || !class_exists('\\Phar');
|
new BuildCliCommand(),
|
||||||
$commands = array_filter($commands, function ($y) use ($phar) {
|
new BuildLibsCommand(),
|
||||||
$archive_blacklist = [
|
new DeployCommand(),
|
||||||
'SPC\command\dev\SortConfigCommand',
|
new DoctorCommand(),
|
||||||
'SPC\command\DeployCommand',
|
new DownloadCommand(),
|
||||||
];
|
new DumpLicenseCommand(),
|
||||||
if ($phar && in_array($y, $archive_blacklist)) {
|
new ExtractCommand(),
|
||||||
return false;
|
new MicroCombineCommand(),
|
||||||
}
|
|
||||||
$reflection = new \ReflectionClass($y);
|
// Dev commands
|
||||||
return !$reflection->isAbstract() && !$reflection->isInterface();
|
new AllExtCommand(),
|
||||||
});
|
new PhpVerCommand(),
|
||||||
$this->addCommands(array_map(function ($x) { return new $x(); }, $commands));
|
new SortConfigCommand(),
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getDefaultCommands(): array
|
protected function getDefaultCommands(): array
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use Symfony\Component\Console\Input\InputOption;
|
|||||||
use function Laravel\Prompts\confirm;
|
use function Laravel\Prompts\confirm;
|
||||||
use function Laravel\Prompts\text;
|
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
|
class DeployCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
public function configure(): void
|
public function configure(): void
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
/**
|
/**
|
||||||
* Modify config file: sort lib, ext, source by name.
|
* 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
|
class SortConfigCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
public function configure(): void
|
public function configure(): void
|
||||||
|
|||||||
Reference in New Issue
Block a user