mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-03 23:05:41 +08:00
Add getLibVersion and getExtVersion method for extensions and libs
This commit is contained in:
51
src/SPC/command/dev/ExtVerCommand.php
Normal file
51
src/SPC/command/dev/ExtVerCommand.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\command\dev;
|
||||
|
||||
use SPC\builder\BuilderProvider;
|
||||
use SPC\command\BaseCommand;
|
||||
use SPC\store\Config;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand('dev:ext-version', 'Returns version of extension from source directory', ['dev:ext-ver'])]
|
||||
class ExtVerCommand extends BaseCommand
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->addArgument('extension', InputArgument::REQUIRED, 'The library name');
|
||||
}
|
||||
|
||||
public function initialize(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
$this->no_motd = true;
|
||||
parent::initialize($input, $output);
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
// Get lib object
|
||||
$builder = BuilderProvider::makeBuilderByInput($this->input);
|
||||
|
||||
$ext_conf = Config::getExt($this->getArgument('extension'));
|
||||
$builder->proveExts([$this->getArgument('extension')], true);
|
||||
|
||||
// Check whether lib is extracted
|
||||
// if (!is_dir(SOURCE_PATH . '/' . $this->getArgument('library'))) {
|
||||
// $this->output->writeln("<error>Library {$this->getArgument('library')} is not extracted</error>");
|
||||
// return static::FAILURE;
|
||||
// }
|
||||
|
||||
$version = $builder->getExt($this->getArgument('extension'))->getExtVersion();
|
||||
if ($version === null) {
|
||||
$this->output->writeln("<error>Failed to get version of extension {$this->getArgument('extension')}</error>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
$this->output->writeln("<info>{$version}</info>");
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
60
src/SPC/command/dev/LibVerCommand.php
Normal file
60
src/SPC/command/dev/LibVerCommand.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\command\dev;
|
||||
|
||||
use SPC\builder\BuilderProvider;
|
||||
use SPC\command\BaseCommand;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\Config;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand('dev:lib-version', 'Returns version of library from source directory', ['dev:lib-ver'])]
|
||||
class LibVerCommand extends BaseCommand
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->addArgument('library', InputArgument::REQUIRED, 'The library name');
|
||||
}
|
||||
|
||||
public function initialize(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
$this->no_motd = true;
|
||||
parent::initialize($input, $output);
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
// Get lib object
|
||||
$builder = BuilderProvider::makeBuilderByInput($this->input);
|
||||
$builder->setLibsOnly();
|
||||
|
||||
// check lib name exist in lib.json
|
||||
try {
|
||||
Config::getLib($this->getArgument('library'));
|
||||
} catch (WrongUsageException $e) {
|
||||
$this->output->writeln("<error>Library {$this->getArgument('library')} is not supported yet</error>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$builder->proveLibs([$this->getArgument('library')]);
|
||||
|
||||
// Check whether lib is extracted
|
||||
if (!is_dir(SOURCE_PATH . '/' . $this->getArgument('library'))) {
|
||||
$this->output->writeln("<error>Library {$this->getArgument('library')} is not extracted</error>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$version = $builder->getLib($this->getArgument('library'))->getLibVersion();
|
||||
if ($version === null) {
|
||||
$this->output->writeln("<error>Failed to get version of library {$this->getArgument('library')}</error>");
|
||||
return static::FAILURE;
|
||||
}
|
||||
$this->output->writeln("<info>{$version}</info>");
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user