Skip to content

Commit 28e163a

Browse files
committed
fix(complete): Remove {} and replace commas with newlines
1 parent b5a47c4 commit 28e163a

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

clap_complete/src/aot/shells/fish.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ fn value_completion(option: &Arg) -> String {
275275
}
276276

277277
if let Some(data) = utils::possible_values(option) {
278-
// We return the possible values with their own empty description e.g. {a\t,b\t}
278+
// We return the possible values with their own empty description e.g. "a\t''\nb\t''"
279279
// this makes sure that a and b don't get the description of the option or argument
280280
format!(
281-
" -r -f -a \"{{{}}}\"",
281+
" -r -f -a \"{}\"",
282282
data.iter()
283283
.filter_map(|value| if value.is_hide_set() {
284284
None
@@ -292,7 +292,7 @@ fn value_completion(option: &Arg) -> String {
292292
))
293293
})
294294
.collect::<Vec<_>>()
295-
.join(",")
295+
.join("\n")
296296
)
297297
} else {
298298
// NB! If you change this, please also update the table in `ValueHint` documentation.

clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ function __fish_exhaustive_using_subcommand
2424
contains -- $cmd[1] $argv
2525
end
2626

27-
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''}"
28-
complete -c exhaustive -n "__fish_exhaustive_needs_command" -l empty-choice -r -f -a "{}"
27+
complete -c exhaustive -n "__fish_exhaustive_needs_command" -l generate -d 'generate' -r -f -a "bash\t''
28+
elvish\t''
29+
fish\t''
30+
powershell\t''
31+
zsh\t''"
32+
complete -c exhaustive -n "__fish_exhaustive_needs_command" -l empty-choice -r -f -a ""
2933
complete -c exhaustive -n "__fish_exhaustive_needs_command" -s h -l help -d 'Print help'
3034
complete -c exhaustive -n "__fish_exhaustive_needs_command" -f -a "empty"
3135
complete -c exhaustive -n "__fish_exhaustive_needs_command" -f -a "global"
@@ -55,11 +59,15 @@ complete -c exhaustive -n "__fish_exhaustive_using_subcommand global; and __fish
5559
complete -c exhaustive -n "__fish_exhaustive_using_subcommand global; and __fish_seen_subcommand_from help" -f -a "two"
5660
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)'
5761
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l set -d 'value' -r
58-
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l choice -d 'enum' -r -f -a "{first\t'',second\t''}"
62+
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l choice -d 'enum' -r -f -a "first\t''
63+
second\t''"
5964
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l set-true -d 'bool'
6065
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l count -d 'number'
6166
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -s h -l help -d 'Print help'
62-
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'}"
67+
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'
68+
bash\t'bash (shell)'
69+
fish\t'fish shell'
70+
zsh\t'zsh shell'"
6371
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\''
6472
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"'
6573
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`'
@@ -107,7 +115,9 @@ complete -c exhaustive -n "__fish_exhaustive_using_subcommand last" -s h -l help
107115
complete -c exhaustive -n "__fish_exhaustive_using_subcommand alias" -s o -s O -l option -l opt -d 'cmd option' -r
108116
complete -c exhaustive -n "__fish_exhaustive_using_subcommand alias" -s f -s F -l flag -l flg -d 'cmd flag'
109117
complete -c exhaustive -n "__fish_exhaustive_using_subcommand alias" -s h -l help -d 'Print help'
110-
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l choice -r -f -a "{bash\t'',fish\t'',zsh\t''}"
118+
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l choice -r -f -a "bash\t''
119+
fish\t''
120+
zsh\t''"
111121
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l unknown -r
112122
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l other -r -f
113123
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -s p -l path -r -F

clap_complete/tests/snapshots/sub_subcommands.fish

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ complete -c my-app -n "__fish_my_app_using_subcommand some_cmd; and not __fish_s
3838
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'
3939
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'
4040
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)'
41-
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''}"
41+
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'
42+
Second to trigger display of options\t''"
4243
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\')'
4344
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'
4445
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'
@@ -47,7 +48,8 @@ complete -c my-app -n "__fish_my_app_using_subcommand some_cmd_alias; and not __
4748
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'
4849
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'
4950
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)'
50-
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''}"
51+
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'
52+
Second to trigger display of options\t''"
5153
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\')'
5254
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'
5355
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'

clap_complete/tests/snapshots/value_hint.fish

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
complete -c my-app -l choice -r -f -a "{bash\t'',fish\t'',zsh\t''}"
1+
complete -c my-app -l choice -r -f -a "bash\t''
2+
fish\t''
3+
zsh\t''"
24
complete -c my-app -l unknown -r
35
complete -c my-app -l other -r -f
46
complete -c my-app -s p -l path -r -F

clap_complete/tests/testsuite/fish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ CHANGELOG.md examples/ LICENSE-MIT src/
187187
let actual = runtime.complete(input, &term).unwrap();
188188
let expected = snapbox::str![[r#"
189189
% exhaustive quote --choice
190-
another shell (something with a space) bash (bash (shell)) fish (fish shell) zsh (zsh shell)
190+
another bash (bash (shell)) fish (fish shell) shell (something with a space) zsh (zsh shell)
191191
"#]];
192192
assert_data_eq!(actual, expected);
193193
}

0 commit comments

Comments
 (0)