Skip to content

Commit

Permalink
Merge pull request #4734 from XiaoXiaoSN/master
Browse files Browse the repository at this point in the history
feat(complete): Support to run ZSH completion as a script
  • Loading branch information
epage committed Feb 27, 2023
2 parents cdb33b6 + 0f3e729 commit e9535a3
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
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
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
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
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
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
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
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
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
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
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 e9535a3

Please sign in to comment.