Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] Be explicit about the completion API version #46901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/Symfony/Component/Console/Command/CompleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#[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
*/
Expand Down Expand Up @@ -65,7 +67,8 @@ protected function configure(): void
->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')
;
}

Expand All @@ -77,16 +80,16 @@ protected function initialize(InputInterface $input, OutputInterface $output)
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, '>=')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison in wrong. Fixed in #47019

$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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::INVALID;
}

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

return self::SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Resources/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _sf_{{ COMMAND_NAME }}() {
local cur prev words cword
_get_comp_words_by_ref -n := cur prev words cword

local completecmd=("$sf_cmd" "_complete" "-sbash" "-c$cword" "-S{{ VERSION }}")
local completecmd=("$sf_cmd" "_complete" "-sbash" "-c$cword" "-a{{ VERSION }}")
for w in ${words[@]}; do
w=$(printf -- '%b' "$w")
# remove quotes from typed values
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Resources/completion.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function _sf_{{ COMMAND_NAME }}
set sf_cmd (commandline -o)
set c (count (commandline -oc))

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

for i in $sf_cmd
if [ $i != "" ]
Expand Down
13 changes: 11 additions & 2 deletions src/Symfony/Component/Console/Tests/Fixtures/application_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "_complete",
"hidden": true,
"usage": [
"_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]"
"_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-a|--api-version API-VERSION] [-S|--symfony SYMFONY]"
],
"description": "Internal command to provide shell completion suggestions",
"help": "Internal command to provide shell completion suggestions",
Expand All @@ -17,7 +17,7 @@
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
"description": "The version of the completion script",
"description": "deprecated",
"default": null
},
"help": {
Expand Down Expand Up @@ -109,6 +109,15 @@
"is_multiple": true,
"description": "An array of input tokens (e.g. COMP_WORDS or argv)",
"default": []
},
"api-version": {
"name": "--api-version",
"shortcut": "-a",
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
"description": "The API version of the completion script",
"default": null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<commands>
<command id="_complete" name="_complete" hidden="1">
<usages>
<usage>_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]</usage>
<usage>_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-a|--api-version API-VERSION] [-S|--symfony SYMFONY]</usage>
</usages>
<description>Internal command to provide shell completion suggestions</description>
<help>Internal command to provide shell completion suggestions</help>
Expand All @@ -21,8 +21,12 @@
<description>The index of the "input" array that the cursor is in (e.g. COMP_CWORD)</description>
<defaults/>
</option>
<option name="--api-version" shortcut="-a" accept_value="1" is_value_required="1" is_multiple="0">
<description>The API version of the completion script</description>
<defaults/>
</option>
<option name="--symfony" shortcut="-S" accept_value="1" is_value_required="1" is_multiple="0">
<description>The version of the completion script</description>
<description>deprecated</description>
<defaults/>
</option>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
Expand Down
13 changes: 11 additions & 2 deletions src/Symfony/Component/Console/Tests/Fixtures/application_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "_complete",
"hidden": true,
"usage": [
"_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]"
"_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-a|--api-version API-VERSION] [-S|--symfony SYMFONY]"
],
"description": "Internal command to provide shell completion suggestions",
"help": "Internal command to provide shell completion suggestions",
Expand All @@ -21,7 +21,7 @@
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
"description": "The version of the completion script",
"description": "deprecated",
"default": null
},
"help": {
Expand Down Expand Up @@ -113,6 +113,15 @@
"is_multiple": true,
"description": "An array of input tokens (e.g. COMP_WORDS or argv)",
"default": []
},
"api-version": {
"name": "--api-version",
"shortcut": "-a",
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
"description": "The API version of the completion script",
"default": null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<commands>
<command id="_complete" name="_complete" hidden="1">
<usages>
<usage>_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-S|--symfony SYMFONY]</usage>
<usage>_complete [-s|--shell SHELL] [-i|--input INPUT] [-c|--current CURRENT] [-a|--api-version API-VERSION] [-S|--symfony SYMFONY]</usage>
</usages>
<description>Internal command to provide shell completion suggestions</description>
<help>Internal command to provide shell completion suggestions</help>
Expand All @@ -21,8 +21,12 @@
<description>The index of the "input" array that the cursor is in (e.g. COMP_CWORD)</description>
<defaults/>
</option>
<option name="--api-version" shortcut="-a" accept_value="1" is_value_required="1" is_multiple="0">
<description>The API version of the completion script</description>
<defaults/>
</option>
<option name="--symfony" shortcut="-S" accept_value="1" is_value_required="1" is_multiple="0">
<description>The version of the completion script</description>
<description>deprecated</description>
<defaults/>
</option>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
Expand Down