Skip to content

Commit

Permalink
test(complete): Test help escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg committed Aug 3, 2023
1 parent 3ec5372 commit f7f7803
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 34 deletions.
1 change: 1 addition & 0 deletions clap_complete/examples/exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn cli() -> clap::Command {
clap::Command::new("cmd-brackets").about("List packages [filter]"),
clap::Command::new("cmd-expansions")
.about("Execute the shell command with $SHELL"),
clap::Command::new("escape-help").about("\\tab\t\"'\nNew Line"),
]),
clap::Command::new("value").args([
clap::Arg::new("delim").long("delim").value_delimiter(','),
Expand Down
1 change: 0 additions & 1 deletion clap_complete/src/dynamic/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,3 @@ pub fn subcommands(p: &clap::Command) -> Vec<(String, Option<StyledStr>)> {
.map(|sc| (sc.get_name().to_string(), sc.get_about().cloned()))
.collect()
}

6 changes: 5 additions & 1 deletion clap_complete/src/dynamic/shells/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ impl crate::dynamic::Completer for Fish {
for (completion, help) in completions {
write!(buf, "{}", completion.to_string_lossy())?;
if let Some(help) = help {
write!(buf, "\t{}", help.to_string().lines().next().unwrap_or_default())?;
write!(
buf,
"\t{}",
help.to_string().lines().next().unwrap_or_default()
)?;
}
writeln!(buf)?;
}
Expand Down
57 changes: 54 additions & 3 deletions clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ _exhaustive() {
exhaustive__help__quote,cmd-single-quotes)
cmd="exhaustive__help__quote__cmd__single__quotes"
;;
exhaustive__help__quote,escape-help)
cmd="exhaustive__help__quote__escape__help"
;;
exhaustive__pacman,help)
cmd="exhaustive__pacman__help"
;;
Expand Down Expand Up @@ -128,6 +131,9 @@ _exhaustive() {
exhaustive__quote,cmd-single-quotes)
cmd="exhaustive__quote__cmd__single__quotes"
;;
exhaustive__quote,escape-help)
cmd="exhaustive__quote__escape__help"
;;
exhaustive__quote,help)
cmd="exhaustive__quote__help"
;;
Expand All @@ -149,6 +155,9 @@ _exhaustive() {
exhaustive__quote__help,cmd-single-quotes)
cmd="exhaustive__quote__help__cmd__single__quotes"
;;
exhaustive__quote__help,escape-help)
cmd="exhaustive__quote__help__escape__help"
;;
exhaustive__quote__help,help)
cmd="exhaustive__quote__help__help"
;;
Expand Down Expand Up @@ -391,7 +400,7 @@ _exhaustive() {
return 0
;;
exhaustive__help__quote)
opts="cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions"
opts="cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -488,6 +497,20 @@ _exhaustive() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__help__quote__escape__help)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__help__value)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
Expand Down Expand Up @@ -709,7 +732,7 @@ _exhaustive() {
return 0
;;
exhaustive__quote)
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 help"
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"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -806,8 +829,22 @@ _exhaustive() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__quote__escape__help)
opts="-h -V --global --help --version"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__quote__help)
opts="cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help"
opts="cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -904,6 +941,20 @@ _exhaustive() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__quote__help__escape__help)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
exhaustive__quote__help__help)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
cand cmd-backslash 'Avoid ''\n'''
cand cmd-brackets 'List packages [filter]'
cand cmd-expansions 'Execute the shell command with $SHELL'
cand escape-help '\tab "''
New Line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'exhaustive;quote;cmd-single-quotes'= {
Expand Down Expand Up @@ -109,13 +111,22 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
cand -V 'Print version'
cand --version 'Print version'
}
&'exhaustive;quote;escape-help'= {
cand --global 'everywhere'
cand -h 'Print help'
cand --help 'Print help'
cand -V 'Print version'
cand --version 'Print version'
}
&'exhaustive;quote;help'= {
cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never'''
cand cmd-double-quotes 'Can be "always", "auto", or "never"'
cand cmd-backticks 'For more information see `echo test`'
cand cmd-backslash 'Avoid ''\n'''
cand cmd-brackets 'List packages [filter]'
cand cmd-expansions 'Execute the shell command with $SHELL'
cand escape-help '\tab "''
New Line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'exhaustive;quote;help;cmd-single-quotes'= {
Expand All @@ -130,6 +141,8 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
}
&'exhaustive;quote;help;cmd-expansions'= {
}
&'exhaustive;quote;help;escape-help'= {
}
&'exhaustive;quote;help;help'= {
}
&'exhaustive;value'= {
Expand Down Expand Up @@ -255,6 +268,8 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
cand cmd-backslash 'Avoid ''\n'''
cand cmd-brackets 'List packages [filter]'
cand cmd-expansions 'Execute the shell command with $SHELL'
cand escape-help '\tab "''
New Line'
}
&'exhaustive;help;quote;cmd-single-quotes'= {
}
Expand All @@ -268,6 +283,8 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
}
&'exhaustive;help;quote;cmd-expansions'= {
}
&'exhaustive;help;quote;escape-help'= {
}
&'exhaustive;help;value'= {
}
&'exhaustive;help;pacman'= {
Expand Down
Loading

0 comments on commit f7f7803

Please sign in to comment.