Skip to content

Commit

Permalink
feat(complete): Support to run ZSH completion as a script
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoXiaoSN committed Feb 27, 2023
1 parent cdb33b6 commit 0f3e729
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 10 deletions.
6 changes: 5 additions & 1 deletion clap_complete/src/shells/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ _{name}() {{
{subcommand_details}
_{name} \"$@\"
if [ \"$funcstack[1]\" = \"_{name}\" ]; then
_{name} \"$@\"
else
compdef _{name} {name}
fi
",
name = bin_name,
initial_args = get_args_of(cmd, None),
Expand Down
6 changes: 5 additions & 1 deletion clap_complete/tests/snapshots/aliases.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ _my-app_commands() {
_describe -t commands 'my-app commands' commands "$@"
}

_my-app "$@"
if [ "$funcstack[1]" = "_my-app" ]; then
_my-app "$@"
else
compdef _my-app my-app
fi
6 changes: 5 additions & 1 deletion clap_complete/tests/snapshots/basic.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ _my-app__test_commands() {
_describe -t commands 'my-app test commands' commands "$@"
}

_my-app "$@"
if [ "$funcstack[1]" = "_my-app" ]; then
_my-app "$@"
else
compdef _my-app my-app
fi
6 changes: 5 additions & 1 deletion clap_complete/tests/snapshots/feature_sample.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ _my-app__test_commands() {
_describe -t commands 'my-app test commands' commands "$@"
}

_my-app "$@"
if [ "$funcstack[1]" = "_my-app" ]; then
_my-app "$@"
else
compdef _my-app my-app
fi
6 changes: 5 additions & 1 deletion clap_complete/tests/snapshots/quoting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,8 @@ _my-app__help__help_commands() {
_describe -t commands 'my-app help help commands' commands "$@"
}

_my-app "$@"
if [ "$funcstack[1]" = "_my-app" ]; then
_my-app "$@"
else
compdef _my-app my-app
fi
6 changes: 5 additions & 1 deletion clap_complete/tests/snapshots/special_commands.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,8 @@ _my-app__test_commands() {
_describe -t commands 'my-app test commands' commands "$@"
}

_my-app "$@"
if [ "$funcstack[1]" = "_my-app" ]; then
_my-app "$@"
else
compdef _my-app my-app
fi
6 changes: 5 additions & 1 deletion clap_complete/tests/snapshots/sub_subcommands.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,8 @@ _my-app__test_commands() {
_describe -t commands 'my-app test commands' commands "$@"
}

_my-app "$@"
if [ "$funcstack[1]" = "_my-app" ]; then
_my-app "$@"
else
compdef _my-app my-app
fi
6 changes: 5 additions & 1 deletion clap_complete/tests/snapshots/two_multi_valued_arguments.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ _my-app_commands() {
_describe -t commands 'my-app commands' commands "$@"
}

_my-app "$@"
if [ "$funcstack[1]" = "_my-app" ]; then
_my-app "$@"
else
compdef _my-app my-app
fi
6 changes: 5 additions & 1 deletion clap_complete/tests/snapshots/value_hint.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ _my-app_commands() {
_describe -t commands 'my-app commands' commands "$@"
}

_my-app "$@"
if [ "$funcstack[1]" = "_my-app" ]; then
_my-app "$@"
else
compdef _my-app my-app
fi
6 changes: 5 additions & 1 deletion clap_complete/tests/snapshots/value_terminator.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ _my-app_commands() {
_describe -t commands 'my-app commands' commands "$@"
}

_my-app "$@"
if [ "$funcstack[1]" = "_my-app" ]; then
_my-app "$@"
else
compdef _my-app my-app
fi

0 comments on commit 0f3e729

Please sign in to comment.