fix(completions/zsh.rs): Maybe fix completions with mixed positionals and subcommands

Optional positionals mixed with subcommands will still break this, since
I can't see how to tell which element of $line is the command than.
Mixing optional positionals with subcommands is a bit weird and awkward
though...
This commit is contained in:
Segev Finer 2018-01-13 20:49:20 +02:00
parent e39aeab848
commit 1146f0da15
2 changed files with 17 additions and 10 deletions

View file

@ -230,15 +230,18 @@ fn get_subcommands_of(p: &Parser) -> String {
format!(
"case $state in
({name})
curcontext=\"${{curcontext%:*:*}}:{name_hyphen}-command-$words[1]:\"
case $line[1] in
words=($line[{pos}] \"${{words[@]}}\")
(( CURRENT += 1 ))
curcontext=\"${{curcontext%:*:*}}:{name_hyphen}-command-$line[{pos}]:\"
case $line[{pos}] in
{subcommands}
esac
;;
esac",
name = p.meta.name,
name_hyphen = p.meta.bin_name.as_ref().unwrap().replace(" ", "-"),
subcommands = subcmds.join("\n")
subcommands = subcmds.join("\n"),
pos = p.positionals().len() + 1
)
}
@ -285,7 +288,7 @@ fn get_args_of(p: &Parser) -> String {
String::new()
};
let sc = if p.has_subcommands() {
format!("\"*:: :->{name}\" \\", name = p.meta.name)
format!("\"*::: :->{name}\" \\", name = p.meta.name)
} else {
String::new()
};

View file

@ -101,12 +101,14 @@ _myapp() {
'--version[Prints version information]' \
"::file -- some input file:_files" \
":: :_myapp_commands" \
"*:: :->myapp" \
"*::: :->myapp" \
&& ret=0
case $state in
(myapp)
curcontext="${curcontext%:*:*}:myapp-command-$words[1]:"
case $line[1] in
words=($line[2] "${words[@]}")
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:myapp-command-$line[2]:"
case $line[2] in
(test)
_arguments -s -S -C \
'--case=[the case to test]' \
@ -390,12 +392,14 @@ _my_app() {
'--version[Prints version information]' \
"::file -- some input file:_files" \
":: :_my_app_commands" \
"*:: :->my_app" \
"*::: :->my_app" \
&& ret=0
case $state in
(my_app)
curcontext="${curcontext%:*:*}:my_app-command-$words[1]:"
case $line[1] in
words=($line[2] "${words[@]}")
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:my_app-command-$line[2]:"
case $line[2] in
(test)
_arguments -s -S -C \
'--case=[the case to test]' \