2023-07-28 00:02:49 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\command;
|
|
|
|
|
|
|
|
|
|
use SPC\builder\traits\UnixSystemUtilTrait;
|
2023-08-20 19:51:45 +08:00
|
|
|
use SPC\exception\FileSystemException;
|
|
|
|
|
use SPC\exception\RuntimeException;
|
|
|
|
|
use SPC\exception\WrongUsageException;
|
2024-02-18 13:54:06 +08:00
|
|
|
use SPC\store\SourceManager;
|
2023-07-28 00:02:49 +08:00
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
|
2024-02-18 13:54:06 +08:00
|
|
|
#[AsCommand('extract', 'Extract required sources', ['extract-source'])]
|
2023-07-28 00:02:49 +08:00
|
|
|
class ExtractCommand extends BaseCommand
|
|
|
|
|
{
|
|
|
|
|
use UnixSystemUtilTrait;
|
|
|
|
|
|
2023-08-20 19:51:45 +08:00
|
|
|
public function configure(): void
|
2023-07-28 00:02:49 +08:00
|
|
|
{
|
|
|
|
|
$this->addArgument('sources', InputArgument::REQUIRED, 'The sources will be compiled, comma separated');
|
2025-03-31 16:37:24 +08:00
|
|
|
$this->addOption('source-only', null, null, 'Only check the source exist, do not check the lib and ext');
|
2023-07-28 00:02:49 +08:00
|
|
|
}
|
|
|
|
|
|
2023-08-20 19:51:45 +08:00
|
|
|
/**
|
|
|
|
|
* @throws WrongUsageException
|
|
|
|
|
* @throws FileSystemException
|
|
|
|
|
* @throws RuntimeException
|
|
|
|
|
*/
|
2023-07-28 00:02:49 +08:00
|
|
|
public function handle(): int
|
|
|
|
|
{
|
|
|
|
|
$sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
|
|
|
|
|
if (empty($sources)) {
|
2023-08-05 21:53:46 +02:00
|
|
|
$this->output->writeln('<error>sources cannot be empty, at least contain one !</error>');
|
2023-08-06 10:43:20 +08:00
|
|
|
return static::FAILURE;
|
2023-07-28 00:02:49 +08:00
|
|
|
}
|
2025-03-31 16:37:24 +08:00
|
|
|
SourceManager::initSource(sources: $sources, source_only: $this->getOption('source-only'));
|
2023-07-28 00:02:49 +08:00
|
|
|
logger()->info('Extract done !');
|
2023-08-06 10:43:20 +08:00
|
|
|
return static::SUCCESS;
|
2023-07-28 00:02:49 +08:00
|
|
|
}
|
|
|
|
|
}
|