我有一個 Symfony 控制臺應用程式,我想將它與自動完成一起使用,但 autocoplite 不起作用。當我點擊tab什么都沒有發生。
如果我這樣輸入,我的應用程式可以從命令列成功運行:
./myapp generate-constants nomenclature
然后它列印
你好世界!,命名法
這是我的腳本名為 myapp
#!/usr/bin/env php
<?php
require 'bootstrap.php';
use MyApp\Core\Console\GenerateConstantsCommand;
use Symfony\Component\Console\Application;
$app = new Application();
$app->add(new GenerateConstantsCommand());
$app->run();
這是 GenerateConstantsCommand.php
<?php
namespace MyApp\Core\Console;
use LogicException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
class GenerateConstantsCommand extends Command
{
protected function configure()
{
$this->setName('generate-constants')
->setDescription('Generate constsants')
->setHelp('Demonstration of custom commands created by Symfony Console component.')
->addArgument('nomenclature', InputArgument::REQUIRED, 'Pass the nomenclature');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf('Hello World!, %s', $input->getArgument('nomenclature')));
return 0;
}
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestOptionValuesFor('nomenclature')) {
$suggestions->suggestValues(['json', 'xml']);
}
}
}
我做錯了什么?為什么自動完成不起作用?
我也嘗試過使用 stecman/symfony-console-completion ,但是當我運行eval $(./myapp _completion --generate-hook)游標時,游標會轉到新行并永遠停留在那里。
我使用 Bash 5.0.17(1)-release、Ubuntu 20.04.4 LTS、Symfony Console 5.4.7 和 PHP 7.3.26。
uj5u.com熱心網友回復:
根據
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/465453.html
標籤:php 重击 交响乐 ubuntu symfony 控制台
上一篇:bash操作檔案中的多個字串
