mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52: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!(
|
format!(
|
||||||
"case $state in
|
"case $state in
|
||||||
({name})
|
({name})
|
||||||
curcontext=\"${{curcontext%:*:*}}:{name_hyphen}-command-$words[1]:\"
|
words=($line[{pos}] \"${{words[@]}}\")
|
||||||
case $line[1] in
|
(( CURRENT += 1 ))
|
||||||
|
curcontext=\"${{curcontext%:*:*}}:{name_hyphen}-command-$line[{pos}]:\"
|
||||||
|
case $line[{pos}] in
|
||||||
{subcommands}
|
{subcommands}
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac",
|
esac",
|
||||||
name = p.meta.name,
|
name = p.meta.name,
|
||||||
name_hyphen = p.meta.bin_name.as_ref().unwrap().replace(" ", "-"),
|
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()
|
String::new()
|
||||||
};
|
};
|
||||||
let sc = if p.has_subcommands() {
|
let sc = if p.has_subcommands() {
|
||||||
format!("\"*:: :->{name}\" \\", name = p.meta.name)
|
format!("\"*::: :->{name}\" \\", name = p.meta.name)
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
|
|
|
@ -101,12 +101,14 @@ _myapp() {
|
||||||
'--version[Prints version information]' \
|
'--version[Prints version information]' \
|
||||||
"::file -- some input file:_files" \
|
"::file -- some input file:_files" \
|
||||||
":: :_myapp_commands" \
|
":: :_myapp_commands" \
|
||||||
"*:: :->myapp" \
|
"*::: :->myapp" \
|
||||||
&& ret=0
|
&& ret=0
|
||||||
case $state in
|
case $state in
|
||||||
(myapp)
|
(myapp)
|
||||||
curcontext="${curcontext%:*:*}:myapp-command-$words[1]:"
|
words=($line[2] "${words[@]}")
|
||||||
case $line[1] in
|
(( CURRENT += 1 ))
|
||||||
|
curcontext="${curcontext%:*:*}:myapp-command-$line[2]:"
|
||||||
|
case $line[2] in
|
||||||
(test)
|
(test)
|
||||||
_arguments -s -S -C \
|
_arguments -s -S -C \
|
||||||
'--case=[the case to test]' \
|
'--case=[the case to test]' \
|
||||||
|
@ -390,12 +392,14 @@ _my_app() {
|
||||||
'--version[Prints version information]' \
|
'--version[Prints version information]' \
|
||||||
"::file -- some input file:_files" \
|
"::file -- some input file:_files" \
|
||||||
":: :_my_app_commands" \
|
":: :_my_app_commands" \
|
||||||
"*:: :->my_app" \
|
"*::: :->my_app" \
|
||||||
&& ret=0
|
&& ret=0
|
||||||
case $state in
|
case $state in
|
||||||
(my_app)
|
(my_app)
|
||||||
curcontext="${curcontext%:*:*}:my_app-command-$words[1]:"
|
words=($line[2] "${words[@]}")
|
||||||
case $line[1] in
|
(( CURRENT += 1 ))
|
||||||
|
curcontext="${curcontext%:*:*}:my_app-command-$line[2]:"
|
||||||
|
case $line[2] in
|
||||||
(test)
|
(test)
|
||||||
_arguments -s -S -C \
|
_arguments -s -S -C \
|
||||||
'--case=[the case to test]' \
|
'--case=[the case to test]' \
|
||||||
|
|
Loading…
Reference in a new issue