mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
remove list-ext command, use all-ext and alias to support its function
This commit is contained in:
parent
1ed104d2f6
commit
7298e2441b
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC;
|
namespace SPC;
|
||||||
|
|
||||||
use SPC\command\DeployCommand;
|
|
||||||
use SPC\store\FileSystem;
|
use SPC\store\FileSystem;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Command\HelpCommand;
|
use Symfony\Component\Console\Command\HelpCommand;
|
||||||
@ -32,13 +31,19 @@ class ConsoleApplication extends Application
|
|||||||
|
|
||||||
// 通过扫描目录 src/static-php-cli/command/ 添加子命令
|
// 通过扫描目录 src/static-php-cli/command/ 添加子命令
|
||||||
$commands = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/command', 'SPC\\command');
|
$commands = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/command', 'SPC\\command');
|
||||||
$this->addCommands(array_map(function ($x) { return new $x(); }, array_filter($commands, function ($y) {
|
$phar = class_exists('\\Phar') && \Phar::running() || !class_exists('\\Phar');
|
||||||
if (is_a($y, DeployCommand::class, true) && (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;
|
return false;
|
||||||
}
|
}
|
||||||
$reflection = new \ReflectionClass($y);
|
$reflection = new \ReflectionClass($y);
|
||||||
return !$reflection->isAbstract() && !$reflection->isInterface();
|
return !$reflection->isAbstract() && !$reflection->isInterface();
|
||||||
})));
|
});
|
||||||
|
$this->addCommands(array_map(function ($x) { return new $x(); }, $commands));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace SPC\command;
|
|
||||||
|
|
||||||
use SPC\exception\FileSystemException;
|
|
||||||
use SPC\store\Config;
|
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
|
||||||
|
|
||||||
#[AsCommand('list-ext', 'List supported extensions')]
|
|
||||||
class ListExtCommand extends BaseCommand
|
|
||||||
{
|
|
||||||
protected bool $no_motd = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws FileSystemException
|
|
||||||
*/
|
|
||||||
public function handle(): int
|
|
||||||
{
|
|
||||||
foreach (Config::getExts() as $ext => $meta) {
|
|
||||||
echo $ext . PHP_EOL;
|
|
||||||
}
|
|
||||||
return static::SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -8,16 +8,17 @@ use SPC\command\BaseCommand;
|
|||||||
use SPC\store\Config;
|
use SPC\store\Config;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
|
||||||
#[AsCommand('dev:ext-all', 'Dev command')]
|
#[AsCommand('dev:ext-all', 'Dev command', ['list-ext'])]
|
||||||
class AllExtCommand extends BaseCommand
|
class AllExtCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
public function configure()
|
public function configure()
|
||||||
{
|
{
|
||||||
|
$this->addOption('line', 'l', null, 'Show with separate lines');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$this->output->writeln(implode(',', array_keys(Config::getExts())));
|
$this->output->writeln(implode($this->input->getOption('line') ? PHP_EOL : ',', array_keys(Config::getExts())));
|
||||||
return static::SUCCESS;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace SPC\command;
|
namespace SPC\command\dev;
|
||||||
|
|
||||||
|
use SPC\command\BaseCommand;
|
||||||
use SPC\exception\FileSystemException;
|
use SPC\exception\FileSystemException;
|
||||||
use SPC\exception\ValidationException;
|
use SPC\exception\ValidationException;
|
||||||
use SPC\store\FileSystem;
|
use SPC\store\FileSystem;
|
||||||
@ -12,9 +13,9 @@ use Symfony\Component\Console\Attribute\AsCommand;
|
|||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改 config 后对其 kv 进行排序的操作
|
* Modify config file: sort lib, ext, source by name.
|
||||||
*/
|
*/
|
||||||
#[AsCommand('sort-config', 'After config edited, sort it by alphabet')]
|
#[AsCommand('dev:sort-config', 'After config edited, sort it by alphabet', ['sort-config'])]
|
||||||
class SortConfigCommand extends BaseCommand
|
class SortConfigCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
public function configure()
|
public function configure()
|
||||||
@ -33,19 +34,28 @@ class SortConfigCommand extends BaseCommand
|
|||||||
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/lib.json'), true);
|
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/lib.json'), true);
|
||||||
ConfigValidator::validateLibs($file);
|
ConfigValidator::validateLibs($file);
|
||||||
ksort($file);
|
ksort($file);
|
||||||
file_put_contents(ROOT_DIR . '/config/lib.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
if (!file_put_contents(ROOT_DIR . '/config/lib.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))) {
|
||||||
|
$this->output->writeln('<error>Write file lib.json failed!</error>');
|
||||||
|
return static::FAILURE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'source':
|
case 'source':
|
||||||
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/source.json'), true);
|
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/source.json'), true);
|
||||||
ConfigValidator::validateSource($file);
|
ConfigValidator::validateSource($file);
|
||||||
uksort($file, fn ($a, $b) => $a === 'php-src' ? -1 : ($b === 'php-src' ? 1 : ($a < $b ? -1 : 1)));
|
uksort($file, fn ($a, $b) => $a === 'php-src' ? -1 : ($b === 'php-src' ? 1 : ($a < $b ? -1 : 1)));
|
||||||
file_put_contents(ROOT_DIR . '/config/source.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
if (!file_put_contents(ROOT_DIR . '/config/source.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))) {
|
||||||
|
$this->output->writeln('<error>Write file source.json failed!</error>');
|
||||||
|
return static::FAILURE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'ext':
|
case 'ext':
|
||||||
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/ext.json'), true);
|
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/ext.json'), true);
|
||||||
ConfigValidator::validateExts($file);
|
ConfigValidator::validateExts($file);
|
||||||
ksort($file);
|
ksort($file);
|
||||||
file_put_contents(ROOT_DIR . '/config/ext.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
if (!file_put_contents(ROOT_DIR . '/config/ext.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))) {
|
||||||
|
$this->output->writeln('<error>Write file ext.json failed!</error>');
|
||||||
|
return static::FAILURE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->output->writeln("<error>invalid config name: {$name}</error>");
|
$this->output->writeln("<error>invalid config name: {$name}</error>");
|
||||||
Loading…
x
Reference in New Issue
Block a user