Skip to content

Commit

Permalink
Merge pull request #5874 from tetzng/fix-fish-completions
Browse files Browse the repository at this point in the history
fix(complete): Remove `{}` and use newline instead of comma in Fish completions
  • Loading branch information
epage authored Jan 9, 2025
2 parents 721deab + 28e163a commit 07f9f15
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
6 changes: 3 additions & 3 deletions clap_complete/src/aot/shells/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ fn value_completion(option: &Arg) -> String {
}

if let Some(data) = utils::possible_values(option) {
// We return the possible values with their own empty description e.g. {a\t,b\t}
// We return the possible values with their own empty description e.g. "a\t''\nb\t''"
// this makes sure that a and b don't get the description of the option or argument
format!(
" -r -f -a \"{{{}}}\"",
" -r -f -a \"{}\"",
data.iter()
.filter_map(|value| if value.is_hide_set() {
None
Expand All @@ -292,7 +292,7 @@ fn value_completion(option: &Arg) -> String {
))
})
.collect::<Vec<_>>()
.join(",")
.join("\n")
)
} else {
// NB! If you change this, please also update the table in `ValueHint` documentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ function __fish_exhaustive_using_subcommand
contains -- $cmd[1] $argv
end

complete -c exhaustive -n "__fish_exhaustive_needs_command" -l generate -d 'generate' -r -f -a "{bash\t'',elvish\t'',fish\t'',powershell\t'',zsh\t''}"
complete -c exhaustive -n "__fish_exhaustive_needs_command" -l empty-choice -r -f -a "{}"
complete -c exhaustive -n "__fish_exhaustive_needs_command" -l generate -d 'generate' -r -f -a "bash\t''
elvish\t''
fish\t''
powershell\t''
zsh\t''"
complete -c exhaustive -n "__fish_exhaustive_needs_command" -l empty-choice -r -f -a ""
complete -c exhaustive -n "__fish_exhaustive_needs_command" -s h -l help -d 'Print help'
complete -c exhaustive -n "__fish_exhaustive_needs_command" -f -a "empty"
complete -c exhaustive -n "__fish_exhaustive_needs_command" -f -a "global"
Expand Down Expand Up @@ -55,11 +59,15 @@ complete -c exhaustive -n "__fish_exhaustive_using_subcommand global; and __fish
complete -c exhaustive -n "__fish_exhaustive_using_subcommand global; and __fish_seen_subcommand_from help" -f -a "two"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand global; and __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l set -d 'value' -r
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l choice -d 'enum' -r -f -a "{first\t'',second\t''}"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l choice -d 'enum' -r -f -a "first\t''
second\t''"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l set-true -d 'bool'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l count -d 'number'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -s h -l help -d 'Print help'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l choice -r -f -a "{another shell\t'something with a space',bash\t'bash (shell)',fish\t'fish shell',zsh\t'zsh shell'}"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l choice -r -f -a "another shell\t'something with a space'
bash\t'bash (shell)'
fish\t'fish shell'
zsh\t'zsh shell'"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l single-quotes -d 'Can be \'always\', \'auto\', or \'never\''
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l double-quotes -d 'Can be "always", "auto", or "never"'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l backticks -d 'For more information see `echo test`'
Expand Down Expand Up @@ -107,7 +115,9 @@ complete -c exhaustive -n "__fish_exhaustive_using_subcommand last" -s h -l help
complete -c exhaustive -n "__fish_exhaustive_using_subcommand alias" -s o -s O -l option -l opt -d 'cmd option' -r
complete -c exhaustive -n "__fish_exhaustive_using_subcommand alias" -s f -s F -l flag -l flg -d 'cmd flag'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand alias" -s h -l help -d 'Print help'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l choice -r -f -a "{bash\t'',fish\t'',zsh\t''}"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l choice -r -f -a "bash\t''
fish\t''
zsh\t''"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l unknown -r
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l other -r -f
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -s p -l path -r -F
Expand Down
6 changes: 4 additions & 2 deletions clap_complete/tests/snapshots/sub_subcommands.fish
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and not __fish_s
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and not __fish_seen_subcommand_from sub_cmd help" -s V -l version -d 'Print version'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and not __fish_seen_subcommand_from sub_cmd help" -f -a "sub_cmd" -d 'sub-subcommand'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and not __fish_seen_subcommand_from sub_cmd help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and __fish_seen_subcommand_from sub_cmd" -l config -d 'the other case to test' -r -f -a "{Lest quotes\, aren\'t escaped.\t'help,with,comma',Second to trigger display of options\t''}"
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and __fish_seen_subcommand_from sub_cmd" -l config -d 'the other case to test' -r -f -a "Lest quotes\, aren\'t escaped.\t'help,with,comma'
Second to trigger display of options\t''"
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and __fish_seen_subcommand_from sub_cmd" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and __fish_seen_subcommand_from sub_cmd" -s V -l version -d 'Print version'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and __fish_seen_subcommand_from help" -f -a "sub_cmd" -d 'sub-subcommand'
Expand All @@ -47,7 +48,8 @@ complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and not __
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and not __fish_seen_subcommand_from sub_cmd help" -s V -l version -d 'Print version'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and not __fish_seen_subcommand_from sub_cmd help" -f -a "sub_cmd" -d 'sub-subcommand'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and not __fish_seen_subcommand_from sub_cmd help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and __fish_seen_subcommand_from sub_cmd" -l config -d 'the other case to test' -r -f -a "{Lest quotes\, aren\'t escaped.\t'help,with,comma',Second to trigger display of options\t''}"
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and __fish_seen_subcommand_from sub_cmd" -l config -d 'the other case to test' -r -f -a "Lest quotes\, aren\'t escaped.\t'help,with,comma'
Second to trigger display of options\t''"
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and __fish_seen_subcommand_from sub_cmd" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and __fish_seen_subcommand_from sub_cmd" -s V -l version -d 'Print version'
complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and __fish_seen_subcommand_from help" -f -a "sub_cmd" -d 'sub-subcommand'
Expand Down
4 changes: 3 additions & 1 deletion clap_complete/tests/snapshots/value_hint.fish
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
complete -c my-app -l choice -r -f -a "{bash\t'',fish\t'',zsh\t''}"
complete -c my-app -l choice -r -f -a "bash\t''
fish\t''
zsh\t''"
complete -c my-app -l unknown -r
complete -c my-app -l other -r -f
complete -c my-app -s p -l path -r -F
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/testsuite/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ CHANGELOG.md examples/ LICENSE-MIT src/
let actual = runtime.complete(input, &term).unwrap();
let expected = snapbox::str![[r#"
% exhaustive quote --choice
another shell (something with a space) bash (bash (shell)) fish (fish shell) zsh (zsh shell)
another bash (bash (shell)) fish (fish shell) shell (something with a space) zsh (zsh shell)
"#]];
assert_data_eq!(actual, expected);
}
Expand Down

0 comments on commit 07f9f15

Please sign in to comment.