mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
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:
parent
e39aeab848
commit
1146f0da15
2 changed files with 17 additions and 10 deletions
|
@ -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()
|
||||
};
|
||||
|
|
|
@ -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]' \
|
||||
|
|
Loading…
Reference in a new issue