Add artifact name suggestions for download and install commands

This commit is contained in:
crazywhalecc
2026-02-04 16:25:23 +08:00
parent 3fa2d69813
commit 16f94466fd
3 changed files with 41 additions and 3 deletions

View File

@@ -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