Allow shell completion for build:libs command

This commit is contained in:
crazywhalecc
2026-02-06 12:37:02 +08:00
parent d6af728e79
commit 0c386e967a

View File

@@ -6,8 +6,10 @@ namespace StaticPHP\Command;
use StaticPHP\Artifact\DownloaderOptions; use StaticPHP\Artifact\DownloaderOptions;
use StaticPHP\Package\PackageInstaller; use StaticPHP\Package\PackageInstaller;
use StaticPHP\Registry\PackageLoader;
use StaticPHP\Util\V2CompatLayer; use StaticPHP\Util\V2CompatLayer;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@@ -16,7 +18,19 @@ class BuildLibsCommand extends BaseCommand
{ {
public function configure(): void public function configure(): void
{ {
$this->addArgument('libraries', InputArgument::REQUIRED, 'The library packages will be compiled, comma separated'); $this->addArgument(
'libraries',
InputArgument::REQUIRED,
'The library packages will be compiled, comma separated',
suggestedValues: function (CompletionInput $input) {
$packages = [];
foreach (PackageLoader::getPackages(['target', 'library']) as $name => $_) {
$packages[] = $name;
}
$val = $input->getCompletionValue();
return array_filter($packages, fn ($name) => str_starts_with($name, $val));
}
);
// Builder options // Builder options
$this->getDefinition()->addOptions([ $this->getDefinition()->addOptions([
new InputOption('with-suggests', ['L', 'E'], null, 'Resolve and install suggested packages as well'), new InputOption('with-suggests', ['L', 'E'], null, 'Resolve and install suggested packages as well'),