Skip to content

Commit 1509828

Browse files
authored
Merge pull request #5114 from jporwal05/master
fix: (fish-completion) Help for value enum
2 parents 7f5eac7 + 34291a2 commit 1509828

File tree

9 files changed

+40
-14
lines changed

9 files changed

+40
-14
lines changed

clap_complete/examples/exhaustive.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use clap::builder::PossibleValue;
12
#[cfg(feature = "unstable-dynamic")]
23
use clap::{FromArgMatches, Subcommand};
34
use clap_complete::{generate, Generator, Shell};
@@ -88,6 +89,14 @@ fn cli() -> clap::Command {
8889
.long("expansions")
8990
.action(clap::ArgAction::SetTrue)
9091
.help("Execute the shell command with $SHELL"),
92+
clap::Arg::new("choice")
93+
.long("choice")
94+
.action(clap::ArgAction::Set)
95+
.value_parser(clap::builder::PossibleValuesParser::new([
96+
PossibleValue::new("bash").help("bash (shell)"),
97+
PossibleValue::new("fish").help("fish shell"),
98+
PossibleValue::new("zsh").help("zsh shell"),
99+
])),
91100
])
92101
.subcommands([
93102
clap::Command::new("cmd-single-quotes")

clap_complete/src/shells/fish.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,12 @@ fn value_completion(option: &Arg) -> String {
168168
.filter_map(|value| if value.is_hide_set() {
169169
None
170170
} else {
171+
// The help text after \t is wrapped in '' to make sure that the it is taken literally
172+
// and there is no command substitution or variable expansion resulting in unexpected errors
171173
Some(format!(
172-
"{}\t{}",
174+
"{}\t'{}'",
173175
escape_string(value.get_name(), true).as_str(),
174-
escape_string(&value.get_help().unwrap_or_default().to_string(), true)
176+
escape_string(&value.get_help().unwrap_or_default().to_string(), false)
175177
))
176178
})
177179
.collect::<Vec<_>>()

clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,16 @@ _exhaustive() {
732732
return 0
733733
;;
734734
exhaustive__quote)
735-
opts="-h -V --single-quotes --double-quotes --backticks --backslash --brackets --expansions --global --help --version cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help"
735+
opts="-h -V --single-quotes --double-quotes --backticks --backslash --brackets --expansions --choice --global --help --version cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help"
736736
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
737737
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
738738
return 0
739739
fi
740740
case "${prev}" in
741+
--choice)
742+
COMPREPLY=($(compgen -W "bash fish zsh" -- "${cur}"))
743+
return 0
744+
;;
741745
*)
742746
COMPREPLY=()
743747
;;

clap_complete/tests/snapshots/home/static/exhaustive/elvish/elvish/rc.elv

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
4848
cand --version 'Print version'
4949
}
5050
&'exhaustive;quote'= {
51+
cand --choice 'choice'
5152
cand --single-quotes 'Can be ''always'', ''auto'', or ''never'''
5253
cand --double-quotes 'Can be "always", "auto", or "never"'
5354
cand --backticks 'For more information see `echo test`'
5455
cand --backslash 'Avoid ''\n'''
5556
cand --brackets 'List packages [filter]'
5657
cand --expansions 'Execute the shell command with $SHELL'
5758
cand --global 'everywhere'
58-
cand -h 'Print help'
59-
cand --help 'Print help'
59+
cand -h 'Print help (see more with ''--help'')'
60+
cand --help 'Print help (see more with ''--help'')'
6061
cand -V 'Print version'
6162
cand --version 'Print version'
6263
cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never'''

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
complete -c exhaustive -n "__fish_use_subcommand" -l generate -d 'generate' -r -f -a "{bash ,elvish ,fish ,powershell ,zsh }"
1+
complete -c exhaustive -n "__fish_use_subcommand" -l generate -d 'generate' -r -f -a "{bash '',elvish '',fish '',powershell '',zsh ''}"
22
complete -c exhaustive -n "__fish_use_subcommand" -l global -d 'everywhere'
33
complete -c exhaustive -n "__fish_use_subcommand" -s h -l help -d 'Print help'
44
complete -c exhaustive -n "__fish_use_subcommand" -s V -l version -d 'Print version'
@@ -12,20 +12,21 @@ complete -c exhaustive -n "__fish_use_subcommand" -f -a "hint"
1212
complete -c exhaustive -n "__fish_use_subcommand" -f -a "complete" -d 'Register shell completions for this program'
1313
complete -c exhaustive -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
1414
complete -c exhaustive -n "__fish_seen_subcommand_from action" -l set -d 'value' -r
15-
complete -c exhaustive -n "__fish_seen_subcommand_from action" -l choice -d 'enum' -r -f -a "{first ,second }"
15+
complete -c exhaustive -n "__fish_seen_subcommand_from action" -l choice -d 'enum' -r -f -a "{first '',second ''}"
1616
complete -c exhaustive -n "__fish_seen_subcommand_from action" -l set-true -d 'bool'
1717
complete -c exhaustive -n "__fish_seen_subcommand_from action" -l count -d 'number'
1818
complete -c exhaustive -n "__fish_seen_subcommand_from action" -l global -d 'everywhere'
1919
complete -c exhaustive -n "__fish_seen_subcommand_from action" -s h -l help -d 'Print help'
2020
complete -c exhaustive -n "__fish_seen_subcommand_from action" -s V -l version -d 'Print version'
21+
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -l choice -r -f -a "{bash 'bash (shell)',fish 'fish shell',zsh 'zsh shell'}"
2122
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -l single-quotes -d 'Can be \'always\', \'auto\', or \'never\''
2223
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -l double-quotes -d 'Can be "always", "auto", or "never"'
2324
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -l backticks -d 'For more information see `echo test`'
2425
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -l backslash -d 'Avoid \'\\n\''
2526
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -l brackets -d 'List packages [filter]'
2627
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -l expansions -d 'Execute the shell command with $SHELL'
2728
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -l global -d 'everywhere'
28-
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -s h -l help -d 'Print help'
29+
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -s h -l help -d 'Print help (see more with \'--help\')'
2930
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -s V -l version -d 'Print version'
3031
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "cmd-single-quotes" -d 'Can be \'always\', \'auto\', or \'never\''
3132
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "cmd-double-quotes" -d 'Can be "always", "auto", or "never"'
@@ -95,7 +96,7 @@ complete -c exhaustive -n "__fish_seen_subcommand_from alias" -s f -s F -l flag
9596
complete -c exhaustive -n "__fish_seen_subcommand_from alias" -l global -d 'everywhere'
9697
complete -c exhaustive -n "__fish_seen_subcommand_from alias" -s h -l help -d 'Print help'
9798
complete -c exhaustive -n "__fish_seen_subcommand_from alias" -s V -l version -d 'Print version'
98-
complete -c exhaustive -n "__fish_seen_subcommand_from hint" -l choice -r -f -a "{bash ,fish ,zsh }"
99+
complete -c exhaustive -n "__fish_seen_subcommand_from hint" -l choice -r -f -a "{bash '',fish '',zsh ''}"
99100
complete -c exhaustive -n "__fish_seen_subcommand_from hint" -l unknown -r
100101
complete -c exhaustive -n "__fish_seen_subcommand_from hint" -l other -r -f
101102
complete -c exhaustive -n "__fish_seen_subcommand_from hint" -s p -l path -r -F
@@ -111,7 +112,7 @@ complete -c exhaustive -n "__fish_seen_subcommand_from hint" -l email -r -f
111112
complete -c exhaustive -n "__fish_seen_subcommand_from hint" -l global -d 'everywhere'
112113
complete -c exhaustive -n "__fish_seen_subcommand_from hint" -s h -l help -d 'Print help'
113114
complete -c exhaustive -n "__fish_seen_subcommand_from hint" -s V -l version -d 'Print version'
114-
complete -c exhaustive -n "__fish_seen_subcommand_from complete" -l shell -d 'Specify shell to complete for' -r -f -a "{bash ,fish }"
115+
complete -c exhaustive -n "__fish_seen_subcommand_from complete" -l shell -d 'Specify shell to complete for' -r -f -a "{bash '',fish ''}"
115116
complete -c exhaustive -n "__fish_seen_subcommand_from complete" -l register -d 'Path to write completion-registration to' -r -F
116117
complete -c exhaustive -n "__fish_seen_subcommand_from complete" -l global -d 'everywhere'
117118
complete -c exhaustive -n "__fish_seen_subcommand_from complete" -s h -l help -d 'Print help (see more with \'--help\')'

clap_complete/tests/snapshots/home/static/exhaustive/zsh/zsh/_exhaustive

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ _arguments "${_arguments_options[@]}" \
4545
;;
4646
(quote)
4747
_arguments "${_arguments_options[@]}" \
48+
'--choice=[]: :((bash\:"bash (shell)"
49+
fish\:"fish shell"
50+
zsh\:"zsh shell"))' \
4851
'--single-quotes[Can be '\''always'\'', '\''auto'\'', or '\''never'\'']' \
4952
'--double-quotes[Can be "always", "auto", or "never"]' \
5053
'--backticks[For more information see \`echo test\`]' \
5154
'--backslash[Avoid '\''\\n'\'']' \
5255
'--brackets[List packages \[filter\]]' \
5356
'--expansions[Execute the shell command with \$SHELL]' \
5457
'--global[everywhere]' \
55-
'-h[Print help]' \
56-
'--help[Print help]' \
58+
'-h[Print help (see more with '\''--help'\'')]' \
59+
'--help[Print help (see more with '\''--help'\'')]' \
5760
'-V[Print version]' \
5861
'--version[Print version]' \
5962
":: :_exhaustive__quote_commands" \

clap_complete/tests/snapshots/sub_subcommands.fish

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and not __fish_seen
1111
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -s V -l version -d 'Print version'
1212
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "sub_cmd" -d 'sub-subcommand'
1313
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
14-
complete -c my-app -n "__fish_seen_subcommand_from 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. help\,with\,comma,Second to trigger display of options }"
14+
complete -c my-app -n "__fish_seen_subcommand_from 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. 'help,with,comma',Second to trigger display of options ''}"
1515
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from sub_cmd" -s h -l help -d 'Print help (see more with \'--help\')'
1616
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from sub_cmd" -s V -l version -d 'Print version'
1717
complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "sub_cmd" -d 'sub-subcommand'

clap_complete/tests/snapshots/value_hint.fish

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
complete -c my-app -l choice -r -f -a "{bash ,fish ,zsh }"
1+
complete -c my-app -l choice -r -f -a "{bash '',fish '',zsh ''}"
22
complete -c my-app -l unknown -r
33
complete -c my-app -l other -r -f
44
complete -c my-app -s p -l path -r -F

clap_complete/tests/testsuite/fish.rs

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ action complete (Register shell completions for this program) hint
142142
alias help (Print this message or the help of the given subcommand(s)) last quote"#;
143143
let actual = runtime.complete(input, &term).unwrap();
144144
snapbox::assert_eq(expected, actual);
145+
146+
let input = "exhaustive quote --choice \t";
147+
let actual = runtime.complete(input, &term).unwrap();
148+
let expected = r#"% exhaustive quote --choice
149+
bash (bash (shell)) fish (fish shell) zsh (zsh shell)"#;
150+
snapbox::assert_eq(expected, actual);
145151
}
146152

147153
#[cfg(all(unix, feature = "unstable-dynamic"))]

0 commit comments

Comments
 (0)