mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-21 07:45:36 +08:00
Rework style of dev command showing extensions details
This commit is contained in:
committed by
Jerry Ma
parent
4d0e825b43
commit
3bd037f48f
@@ -6,15 +6,19 @@ namespace SPC\command\dev;
|
|||||||
|
|
||||||
use SPC\command\BaseCommand;
|
use SPC\command\BaseCommand;
|
||||||
use SPC\exception\FileSystemException;
|
use SPC\exception\FileSystemException;
|
||||||
|
use SPC\exception\WrongUsageException;
|
||||||
use SPC\store\Config;
|
use SPC\store\Config;
|
||||||
|
use SPC\util\DependencyUtil;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
#[AsCommand('dev:ext-all', 'Dev command', ['list-ext'])]
|
#[AsCommand('dev:extensions', 'Helper command that lists available extension details', ['list-ext'])]
|
||||||
class AllExtCommand extends BaseCommand
|
class AllExtCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
public function configure(): void
|
public function configure(): void
|
||||||
{
|
{
|
||||||
$this->addOption('line', 'l', null, 'Show with separate lines');
|
$this->addArgument('extensions', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Extension name', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,7 +26,41 @@ class AllExtCommand extends BaseCommand
|
|||||||
*/
|
*/
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$this->output->writeln(implode($this->input->getOption('line') ? PHP_EOL : ',', array_keys(Config::getExts())));
|
$extensions = $this->input->getArgument('extensions') ?: [];
|
||||||
|
|
||||||
|
$style = new SymfonyStyle($this->input, $this->output);
|
||||||
|
$style->writeln($extensions ? 'Available extensions:' : 'Extensions:');
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
foreach (Config::getExts() as $extension => $details) {
|
||||||
|
if ($extensions !== [] && !\in_array($extension, $extensions, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
[, $libraries, $not_included] = DependencyUtil::getExtLibsByDeps([$extension]);
|
||||||
|
} catch (WrongUsageException) {
|
||||||
|
$libraries = $not_included = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$lib_suggests = Config::getExt($extension, 'lib-suggests', []);
|
||||||
|
$ext_suggests = Config::getExt($extension, 'ext-suggests', []);
|
||||||
|
|
||||||
|
$data[] = [
|
||||||
|
$extension,
|
||||||
|
implode(', ', $libraries),
|
||||||
|
implode(', ', $lib_suggests),
|
||||||
|
implode(',', $not_included),
|
||||||
|
implode(', ', $ext_suggests),
|
||||||
|
Config::getExt($extension, 'unix-only', false) ? 'true' : 'false',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$style->table(
|
||||||
|
['Extension', 'lib-depends', 'lib-suggests', 'ext-depends', 'ext-suggests', 'unix-only'],
|
||||||
|
$data
|
||||||
|
);
|
||||||
|
|
||||||
return static::SUCCESS;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace SPC\command\dev;
|
|
||||||
|
|
||||||
use SPC\command\BaseCommand;
|
|
||||||
use SPC\exception\FileSystemException;
|
|
||||||
use SPC\exception\RuntimeException;
|
|
||||||
use SPC\exception\WrongUsageException;
|
|
||||||
use SPC\store\Config;
|
|
||||||
use SPC\util\DependencyUtil;
|
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
|
|
||||||
#[AsCommand('dev:ext-info', 'Dev command')]
|
|
||||||
class ExtInfoCommand extends BaseCommand
|
|
||||||
{
|
|
||||||
public function configure(): void
|
|
||||||
{
|
|
||||||
$this->addArgument('extensions', InputArgument::REQUIRED, 'The extension name you need to get info');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws WrongUsageException
|
|
||||||
* @throws FileSystemException
|
|
||||||
* @throws RuntimeException
|
|
||||||
*/
|
|
||||||
public function handle(): int
|
|
||||||
{
|
|
||||||
$extensions = array_map('trim', array_filter(explode(',', $this->getArgument('extensions'))));
|
|
||||||
|
|
||||||
// 根据提供的扩展列表获取依赖库列表并编译
|
|
||||||
foreach ($extensions as $extension) {
|
|
||||||
$this->output->writeln('<comment>[ ' . $extension . ' ]</comment>');
|
|
||||||
[, $libraries, $not_included] = DependencyUtil::getExtLibsByDeps([$extension]);
|
|
||||||
$lib_suggests = Config::getExt($extension, 'lib-suggests', []);
|
|
||||||
$ext_suggests = Config::getExt($extension, 'ext-suggests', []);
|
|
||||||
$this->output->writeln("<info>lib-depends:\t" . implode(', ', $libraries) . '</info>');
|
|
||||||
$this->output->writeln("<info>lib-suggests:\t" . implode(', ', $lib_suggests) . '</info>');
|
|
||||||
$this->output->writeln("<info>ext-depends:\t" . implode(',', $not_included) . '</info>');
|
|
||||||
$this->output->writeln("<info>ext-suggests:\t" . implode(', ', $ext_suggests) . '</info>');
|
|
||||||
if (Config::getExt($extension, 'unix-only', false)) {
|
|
||||||
$this->output->writeln("<info>Unix only:\ttrue</info>");
|
|
||||||
}
|
|
||||||
$this->output->writeln('');
|
|
||||||
}
|
|
||||||
return static::SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user