31
31
#[AsCommand(name: '|_complete ' , description: 'Internal command to provide shell completion suggestions ' )]
32
32
final class CompleteCommand extends Command
33
33
{
34
+ public const COMPLETION_API_VERSION = '1 ' ;
35
+
34
36
/**
35
37
* @deprecated since Symfony 6.1
36
38
*/
@@ -65,7 +67,8 @@ protected function configure(): void
65
67
->addOption ('shell ' , 's ' , InputOption::VALUE_REQUIRED , 'The shell type (" ' .implode ('", " ' , array_keys ($ this ->completionOutputs )).'") ' )
66
68
->addOption ('input ' , 'i ' , InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY , 'An array of input tokens (e.g. COMP_WORDS or argv) ' )
67
69
->addOption ('current ' , 'c ' , InputOption::VALUE_REQUIRED , 'The index of the "input" array that the cursor is in (e.g. COMP_CWORD) ' )
68
- ->addOption ('symfony ' , 'S ' , InputOption::VALUE_REQUIRED , 'The version of the completion script ' )
70
+ ->addOption ('api-version ' , 'a ' , InputOption::VALUE_REQUIRED , 'The API version of the completion script ' )
71
+ ->addOption ('symfony ' , 'S ' , InputOption::VALUE_REQUIRED , 'deprecated ' )
69
72
;
70
73
}
71
74
@@ -77,16 +80,16 @@ protected function initialize(InputInterface $input, OutputInterface $output)
77
80
protected function execute (InputInterface $ input , OutputInterface $ output ): int
78
81
{
79
82
try {
80
- // uncomment when a bugfix or BC break has been introduced in the shell completion scripts
81
- // $version = $input->getOption('symfony');
82
- // if ($version && version_compare($version, 'x.y' , '>=')) {
83
- // $message = sprintf('Completion script version is not supported ("%s" given, ">=x.y " required).', $version);
84
- // $this->log($message);
83
+ // "symfony" must be kept for compat with the shell scripts generated by Symfony Console 5.4 - 6.1
84
+ $ version = $ input ->getOption ('symfony ' ) ? ' 1 ' : $ input -> getOption ( ' api-version ' );
85
+ if ($ version && version_compare ($ version , self :: COMPLETION_API_VERSION , '>= ' )) {
86
+ $ message = sprintf ('Completion script version is not supported ("%s" given, ">=%s " required). ' , $ version, self :: COMPLETION_API_VERSION );
87
+ $ this ->log ($ message );
85
88
86
- // $output->writeln($message.' Install the Symfony completion script again by using the "completion" command.');
89
+ $ output ->writeln ($ message .' Install the Symfony completion script again by using the "completion" command. ' );
87
90
88
- // return 126;
89
- // }
91
+ return 126 ;
92
+ }
90
93
91
94
$ shell = $ input ->getOption ('shell ' );
92
95
if (!$ shell ) {
0 commit comments