Skip to content

Commit

Permalink
fix(completions/zsh.rs): Don't pass -S to _arguments if Zsh is too old
Browse files Browse the repository at this point in the history
If you do pass it than _arguments considers -C as a possible option in
the completions.
  • Loading branch information
segevfiner committed Jan 14, 2018
1 parent 1146f0d commit 16b4f14
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/completions/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ impl<'a, 'b> ZshGen<'a, 'b> {
_{name}() {{
typeset -A opt_args
typeset -a _arguments_options
local ret=1
if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi
local context curcontext=\"$curcontext\" state line
{initial_args}
{subcommands}
Expand Down Expand Up @@ -275,7 +282,7 @@ fn parser_of<'a, 'b>(p: &'b Parser<'a, 'b>, sc: &str) -> &'b Parser<'a, 'b> {
// -S: Do not complete anything after '--' and treat those as argument values
fn get_args_of(p: &Parser) -> String {
debugln!("get_args_of;");
let mut ret = vec![String::from("_arguments -s -S -C \\")];
let mut ret = vec![String::from("_arguments \"${_arguments_options[@]}\" \\")];
let opts = write_opts_of(p);
let flags = write_flags_of(p);
let positionals = write_positionals_of(p);
Expand Down
39 changes: 30 additions & 9 deletions tests/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,17 @@ static ZSH: &'static str = r#"#compdef myapp
_myapp() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi
local context curcontext="$curcontext" state line
_arguments -s -S -C \
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
Expand All @@ -110,7 +117,7 @@ _myapp() {
curcontext="${curcontext%:*:*}:myapp-command-$line[2]:"
case $line[2] in
(test)
_arguments -s -S -C \
_arguments "${_arguments_options[@]}" \
'--case=[the case to test]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
Expand All @@ -119,7 +126,7 @@ _arguments -s -S -C \
&& ret=0
;;
(help)
_arguments -s -S -C \
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
Expand Down Expand Up @@ -382,10 +389,17 @@ static ZSH_SPECIAL_CMDS: &'static str = r#"#compdef my_app
_my_app() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi
local context curcontext="$curcontext" state line
_arguments -s -S -C \
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
Expand All @@ -401,7 +415,7 @@ _my_app() {
curcontext="${curcontext%:*:*}:my_app-command-$line[2]:"
case $line[2] in
(test)
_arguments -s -S -C \
_arguments "${_arguments_options[@]}" \
'--case=[the case to test]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
Expand All @@ -410,7 +424,7 @@ _arguments -s -S -C \
&& ret=0
;;
(some_cmd)
_arguments -s -S -C \
_arguments "${_arguments_options[@]}" \
'--config=[the other case to test]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
Expand All @@ -419,15 +433,15 @@ _arguments -s -S -C \
&& ret=0
;;
(some-cmd-with-hypens)
_arguments -s -S -C \
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
;;
(help)
_arguments -s -S -C \
_arguments "${_arguments_options[@]}" \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
Expand Down Expand Up @@ -661,10 +675,17 @@ static ZSH_SPECIAL_HELP: &'static str = r#"#compdef my_app
_my_app() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi
local context curcontext="$curcontext" state line
_arguments -s -S -C \
_arguments "${_arguments_options[@]}" \
'--single-quotes[Can be '\''always'\'', '\''auto'\'', or '\''never'\'']' \
'--double-quotes[Can be "always", "auto", or "never"]' \
'--backticks[For more information see `echo test`]' \
Expand Down

0 comments on commit 16b4f14

Please sign in to comment.