mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-03 23:05:41 +08:00
refactor command as more easily
This commit is contained in:
@@ -8,20 +8,17 @@ use SPC\exception\FileSystemException;
|
||||
use SPC\exception\ValidationException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\util\ConfigValidator;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* 修改 config 后对其 kv 进行排序的操作
|
||||
*/
|
||||
#[AsCommand('sort-config', 'After config edited, sort it by alphabet')]
|
||||
class SortConfigCommand extends BaseCommand
|
||||
{
|
||||
protected static $defaultName = 'sort-config';
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$this->setDescription('After config edited, sort it by alphabet');
|
||||
$this->addArgument('config-name', InputArgument::REQUIRED, 'Your config to be sorted, you can sort "lib", "source" and "ext".');
|
||||
}
|
||||
|
||||
@@ -29,9 +26,9 @@ class SortConfigCommand extends BaseCommand
|
||||
* @throws ValidationException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
public function handle(): int
|
||||
{
|
||||
switch ($name = $input->getArgument('config-name')) {
|
||||
switch ($name = $this->getArgument('config-name')) {
|
||||
case 'lib':
|
||||
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/lib.json'), true);
|
||||
ConfigValidator::validateLibs($file);
|
||||
@@ -51,10 +48,10 @@ class SortConfigCommand extends BaseCommand
|
||||
file_put_contents(ROOT_DIR . '/config/ext.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
break;
|
||||
default:
|
||||
$output->writeln("<error>invalid config name: {$name}</error>");
|
||||
$this->output->writeln("<error>invalid config name: {$name}</error>");
|
||||
return 1;
|
||||
}
|
||||
$output->writeln('<info>sort success</info>');
|
||||
$this->output->writeln('<info>sort success</info>');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user