mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
Add artifact name suggestions for download and install commands
This commit is contained in:
parent
3fa2d69813
commit
16f94466fd
@ -6,11 +6,13 @@ namespace StaticPHP\Command;
|
||||
|
||||
use StaticPHP\Artifact\ArtifactDownloader;
|
||||
use StaticPHP\Artifact\DownloaderOptions;
|
||||
use StaticPHP\Registry\ArtifactLoader;
|
||||
use StaticPHP\Registry\PackageLoader;
|
||||
use StaticPHP\Util\DependencyResolver;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
use StaticPHP\Util\InteractiveTerm;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
@ -19,7 +21,17 @@ class DownloadCommand extends BaseCommand
|
||||
{
|
||||
public function configure(): void
|
||||
{
|
||||
$this->addArgument('artifacts', InputArgument::OPTIONAL, 'Specific artifacts to download, comma separated, e.g "php-src,openssl,curl"');
|
||||
$this->addArgument(
|
||||
'artifacts',
|
||||
InputArgument::OPTIONAL,
|
||||
'Specific artifacts to download, comma separated, e.g "php-src,openssl,curl"',
|
||||
suggestedValues: function (CompletionInput $input) {
|
||||
$input_val = $input->getCompletionValue();
|
||||
$all_names = ArtifactLoader::getLoadedArtifactNames();
|
||||
// filter by input value
|
||||
return array_filter($all_names, fn ($name) => str_starts_with($name, $input_val));
|
||||
},
|
||||
);
|
||||
|
||||
// 2.x compatible options
|
||||
$this->addOption('shallow-clone', null, null, '(deprecated) Clone shallowly repositories when downloading sources');
|
||||
|
||||
@ -6,14 +6,29 @@ namespace StaticPHP\Command;
|
||||
|
||||
use StaticPHP\DI\ApplicationContext;
|
||||
use StaticPHP\Package\PackageInstaller;
|
||||
use StaticPHP\Registry\PackageLoader;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
#[AsCommand('install-pkg', 'Install additional package', ['i', 'install-package'])]
|
||||
class InstallPackageCommand extends BaseCommand
|
||||
{
|
||||
public function configure()
|
||||
public function configure(): void
|
||||
{
|
||||
$this->addArgument('package', null, 'The package to install (name or path)');
|
||||
$this->addArgument(
|
||||
'package',
|
||||
InputArgument::REQUIRED,
|
||||
'The package to install (name or path)',
|
||||
suggestedValues: function (CompletionInput $input) {
|
||||
$packages = [];
|
||||
foreach (PackageLoader::getPackages(['target', 'virtual-target']) as $name => $_) {
|
||||
$packages[] = $name;
|
||||
}
|
||||
$val = $input->getCompletionValue();
|
||||
return array_filter($packages, fn ($name) => str_starts_with($name, $val));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
|
||||
@ -69,6 +69,17 @@ class ArtifactLoader
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get names of all loaded artifacts.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getLoadedArtifactNames(): array
|
||||
{
|
||||
self::initArtifactInstances();
|
||||
return array_keys(self::$artifacts ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process #[CustomSource] attribute.
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user