8000 feature #46901 [Console] Be explicit about the completion API version… · symfony/symfony@a2f27ad · GitHub
[go: up one dir, main page]

Skip to content

Commit a2f27ad

Browse files
committed
feature #46901 [Console] Be explicit about the completion API version (wouterj)
This PR was merged into the 6.2 branch. Discussion ---------- [Console] Be explicit about the completion API version | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | yes | New feature? | yes | Deprecations? | no | Tickets | Fix #44733 | License | MIT | Doc PR | n/a Using the application version is wrong, especially for standalone apps like PHPStan. The completion API is not bound to change on a PHPStan version upgrade, but instead only when something in symfony/console changes. I suggest having an explicit completion API version, that we can increase once we change something in the API (and thus require an update of the shell scripts). Commits ------- b19eb38 [Console] Be explicit about the completion API version
2 parents 4b4f334 + b19eb38 commit a2f27ad

File tree

8 files changed

+49
-20
lines changed

8 files changed

+49
-20
lines changed

src/Symfony/Component/Console/Command/CompleteCommand.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#[AsCommand(name: '|_complete', description: 'Internal command to provide shell completion suggestions')]
3232
final class CompleteCommand extends Command
3333
{
34+
public const COMPLETION_API_VERSION = '1';
35+
3436
/**
3537
* @deprecated since Symfony 6.1
3638
*/
@@ -65,7 +67,8 @@ protected function configure(): void
6567
->addOption('shell', 's', InputOption::VALUE_REQUIRED, 'The shell type ("'.implode('", "', array_keys($this->completionOutputs)).'")')
6668
->addOption('input', 'i', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'An array of input tokens (e.g. COMP_WORDS or argv)')
6769
->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')
6972
;
7073
}
7174

@@ -77,16 +80,16 @@ protected function initialize(InputInterface $input, OutputInterface $output)
7780
protected function execute(InputInterface $input, OutputInterface $output): int
7881
{
7982
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);
8588

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.');
8790

88-
// return 126;
89-
//}
91+
return 126;
92+
}
9093

9194
$shell = $input->getOption('shell');
9295
if (!$shell) {

src/Symfony/Component/Console/Command/DumpCompletionCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
107107
return self::INVALID;
108108
}
109109

110-
$output->write(str_replace(['{{ COMMAND_NAME }}', '{{ VERSION }}'], [$commandName, $this->getApplication()->getVersion()], file_get_contents($completionFile)));
110+
$output->write(str_replace(['{{ COMMAND_NAME }}', '{{ VERSION }}'], [$commandName, CompleteCommand::COMPLETION_API_VERSION], file_get_contents($completionFile)));
111111

112112
return self::SUCCESS;
113113
}

src/Symfony/Component/Console/Resources/completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _sf_{{ COMMAND_NAME }}() {
2222
local cur prev words cword
2323
_get_comp_words_by_ref -n := cur prev words cword
2424

25-
local completecmd=("$sf_cmd" "_complete" "-sbash" "-c$cword" "-S{{ VERSION }}")
25+
local completecmd=("$sf_cmd" "_complete" "-sbash" "-c$cword" "-a{{ VERSION }}")
2626
for w in ${words[@]}; do
2727
w=$(printf -- '%b' "$w")
2828
# remove quotes from typed values

src/Symfony/Component/Console/Resources/completion.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function _sf_{{ COMMAND_NAME }}
99
set sf_cmd (commandline -o)
1010
set c (count (commandline -oc))
1111

12-
set completecmd "$sf_cmd[1]" "_complete" "-sfish" "-S{{ VERSION }}"
12+
set completecmd "$sf_cmd[1]" "_complete" "-sfish" "-a{{ VERSION }}"
1313

1414
for i in $sf_cmd
1515
if [ $i != "" ]

src/Symfony/Component/Console/Tests/Fixtures/application_1.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "_complete",
55
"hidden": true,
66
"usage": [
7-
"_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]"
7+
"_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-a|--api-version API-VERSION] [-S|--symfony SYMFONY]"
88
],
99
"description": "Internal command to provide shell completion suggestions",
1010
"help": "Internal command to provide shell completion suggestions",
@@ -17,7 +17,7 @@
1717
"accept_value": true,
1818
"is_value_required": true,
1919
"is_multiple": false,
20-
"description": "The version of the completion script",
20+
"description": "deprecated",
2121
"default": null
2222
},
2323
"help": {
@@ -109,6 +109,15 @@
109109
"is_multiple": true,
110110
"description": "An array of input tokens (e.g. COMP_WORDS or argv)",
111111
"default": []
112+
},
113+
"api-version": {
114+
"name": "--api-version",
115+
"shortcut": "-a",
116+
"accept_value": true,
117+
"is_value_required": true,
118+
"is_multiple": false,
119+
"description": "The API version of the completion script",
120+
"default": null
112121
}
113122
}
114123
}

src/Symfony/Component/Console/Tests/Fixtures/application_1.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<commands>
44
<command id="_complete" name="_complete" hidden="1">
55
<usages>
6-
<usage>_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]</usage>
6+
<usage>_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-a|--api-version API-VERSION] [-S|--symfony SYMFONY]</usage>
77
</usages>
88
<description>Internal command to provide shell completion suggestions</description>
99
<help>Internal command to provide shell completion suggestions</help>
@@ -21,8 +21,12 @@
2121
<description>The index of the "input" array that the cursor is in (e.g. COMP_CWORD)</description>
2222
<defaults/>
2323
</option>
24+
<option name="--api-version" shortcut="-a" accept_value="1" is_value_required="1" is_multiple="0">
25+
<description>The API version of the completion script</description>
26+
<defaults/>
27+
</option>
2428
<option name="--symfony" shortcut="-S" accept_value="1" is_value_required="1" is_multiple="0">
25-
<description>The version of the completion script</description>
29+
<description>deprecated</description>
2630
<defaults/>
2731
</option>
2832
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">

src/Symfony/Component/Console/Tests/Fixtures/application_2.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "_complete",
99
"hidden": true,
1010
"usage": [
11-
"_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]"
11+
"_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-a|--api-version API-VERSION] [-S|--symfony SYMFONY]"
1212
],
1313
"description": "Internal command to provide shell completion suggestions",
1414
"help": "Internal command to provide shell completion suggestions",
@@ -21,7 +21,7 @@
2121
"accept_value": true,
2222
"is_value_required": true,
2323
"is_multiple": false,
24-
"description": "The version of the completion script",
24+
"description": "deprecated",
2525
"default": null
2626
},
2727
"help": {
@@ -113,6 +113,15 @@
113113
"is_multiple": true,
114114
"description": "An array of input tokens (e.g. COMP_WORDS or argv)",
115115
"default": []
116+
},
117+
"api-version": {
118+
"name": "--api-version",
119+
"shortcut": "-a",
120+
"accept_value": true,
121+
"is_value_required": true,
122+
"is_multiple": false,
123+
"description": "The API version of the completion script",
124+
"default": null
116125
}
117126
}
118127
}

src/Symfony/Component/Console/Tests/Fixtures/application_2.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<commands>
44
<command id="_complete" name="_complete" hidden="1">
55
<usages>
6-
<usage>_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]</usage>
6+
<usage>_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-a|--api-version API-VERSION] [-S|--symfony SYMFONY]</usage>
77
</usages>
88
<description>Internal command to provide shell completion suggestions</description>
99
<help>Internal command to provide shell completion suggestions</help>
@@ -21,8 +21,12 @@
2121
<description>The index of the "input" array that the cursor is in (e.g. COMP_CWORD)</description>
2222
<defaults/>
2323
</option>
24+
<option name="--api-version" shortcut="-a" accept_value="1" is_value_required="1" is_multiple="0">
25+
<description>The API version of the completion script</description>
26+
<defaults/>
27+
</option>
2428
<option name="--symfony" shortcut="-S" accept_value="1" is_value_required="1" is_multiple="0">
25-
<description>The version of the completion script</description>
29+
<description>deprecated</description>
2630
<defaults/>
2731
</option>
2832
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">

0 commit comments

Comments
 (0)
0