package and depencies
This commit is contained in:
@@ -11,10 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
use Symfony\Component\Console\Completion\CompletionSuggestions;
|
||||
use Symfony\Component\Console\Completion\Output\BashCompletionOutput;
|
||||
use Symfony\Component\Console\Completion\Output\CompletionOutputInterface;
|
||||
use Symfony\Component\Console\Completion\Output\FishCompletionOutput;
|
||||
use Symfony\Component\Console\Completion\Output\ZshCompletionOutput;
|
||||
use Symfony\Component\Console\Exception\CommandNotFoundException;
|
||||
use Symfony\Component\Console\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -26,9 +29,19 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
*
|
||||
* @author Wouter de Jong <wouter@wouterj.nl>
|
||||
*/
|
||||
#[AsCommand(name: '|_complete', description: 'Internal command to provide shell completion suggestions')]
|
||||
final class CompleteCommand extends Command
|
||||
{
|
||||
public const COMPLETION_API_VERSION = '1';
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 6.1
|
||||
*/
|
||||
protected static $defaultName = '|_complete';
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 6.1
|
||||
*/
|
||||
protected static $defaultDescription = 'Internal command to provide shell completion suggestions';
|
||||
|
||||
private $completionOutputs;
|
||||
@@ -41,7 +54,11 @@ final class CompleteCommand extends Command
|
||||
public function __construct(array $completionOutputs = [])
|
||||
{
|
||||
// must be set before the parent constructor, as the property value is used in configure()
|
||||
$this->completionOutputs = $completionOutputs + ['bash' => BashCompletionOutput::class];
|
||||
$this->completionOutputs = $completionOutputs + [
|
||||
'bash' => BashCompletionOutput::class,
|
||||
'fish' => FishCompletionOutput::class,
|
||||
'zsh' => ZshCompletionOutput::class,
|
||||
];
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -52,28 +69,29 @@ final class CompleteCommand extends Command
|
||||
->addOption('shell', 's', InputOption::VALUE_REQUIRED, 'The shell type ("'.implode('", "', array_keys($this->completionOutputs)).'")')
|
||||
->addOption('input', 'i', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'An array of input tokens (e.g. COMP_WORDS or argv)')
|
||||
->addOption('current', 'c', InputOption::VALUE_REQUIRED, 'The index of the "input" array that the cursor is in (e.g. COMP_CWORD)')
|
||||
->addOption('symfony', 'S', InputOption::VALUE_REQUIRED, 'The version of the completion script')
|
||||
->addOption('api-version', 'a', InputOption::VALUE_REQUIRED, 'The API version of the completion script')
|
||||
->addOption('symfony', 'S', InputOption::VALUE_REQUIRED, 'deprecated')
|
||||
;
|
||||
}
|
||||
|
||||
protected function initialize(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->isDebug = filter_var(getenv('SYMFONY_COMPLETION_DEBUG'), \FILTER_VALIDATE_BOOLEAN);
|
||||
$this->isDebug = filter_var(getenv('SYMFONY_COMPLETION_DEBUG'), \FILTER_VALIDATE_BOOL);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
try {
|
||||
// uncomment when a bugfix or BC break has been introduced in the shell completion scripts
|
||||
// $version = $input->getOption('symfony');
|
||||
// if ($version && version_compare($version, 'x.y', '>=')) {
|
||||
// $message = sprintf('Completion script version is not supported ("%s" given, ">=x.y" required).', $version);
|
||||
// $this->log($message);
|
||||
// "symfony" must be kept for compat with the shell scripts generated by Symfony Console 5.4 - 6.1
|
||||
$version = $input->getOption('symfony') ? '1' : $input->getOption('api-version');
|
||||
if ($version && version_compare($version, self::COMPLETION_API_VERSION, '<')) {
|
||||
$message = sprintf('Completion script version is not supported ("%s" given, ">=%s" required).', $version, self::COMPLETION_API_VERSION);
|
||||
$this->log($message);
|
||||
|
||||
// $output->writeln($message.' Install the Symfony completion script again by using the "completion" command.');
|
||||
$output->writeln($message.' Install the Symfony completion script again by using the "completion" command.');
|
||||
|
||||
// return 126;
|
||||
// }
|
||||
return 126;
|
||||
}
|
||||
|
||||
$shell = $input->getOption('shell');
|
||||
if (!$shell) {
|
||||
@@ -172,7 +190,7 @@ final class CompleteCommand extends Command
|
||||
|
||||
try {
|
||||
$completionInput->bind($this->getApplication()->getDefinition());
|
||||
} catch (ExceptionInterface $e) {
|
||||
} catch (ExceptionInterface) {
|
||||
}
|
||||
|
||||
return $completionInput;
|
||||
@@ -187,7 +205,7 @@ final class CompleteCommand extends Command
|
||||
}
|
||||
|
||||
return $this->getApplication()->find($inputName);
|
||||
} catch (CommandNotFoundException $e) {
|
||||
} catch (CommandNotFoundException) {
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user