From dd577bdf3103152e76d48bdb168460f239bdfa29 Mon Sep 17 00:00:00 2001 From: Haim Ashkenazi Date: Thu, 1 Mar 2018 08:50:20 +0200 Subject: [PATCH] zsh-completion: added zsh-completion documentation. --- README.md | 6 ++++++ zsh_completion.md | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 zsh_completion.md diff --git a/README.md b/README.md index ff16e3f..8a9ace4 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ etc. * [Suggestions when "unknown command" happens](#suggestions-when-unknown-command-happens) * [Generating documentation for your command](#generating-documentation-for-your-command) * [Generating bash completions](#generating-bash-completions) + * [Generating zsh completions](#generating-zsh-completions) - [Contributing](#contributing) - [License](#license) @@ -719,6 +720,11 @@ Cobra can generate documentation based on subcommands, flags, etc. in the follow Cobra can generate a bash-completion file. If you add more information to your command, these completions can be amazingly powerful and flexible. Read more about it in [Bash Completions](bash_completions.md). +## Generating zsh completions + +Cobra can generate zsh-completion file. Read more about it in +[Zsh Completions](zsh_completions.md). + # Contributing 1. Fork it diff --git a/zsh_completion.md b/zsh_completion.md new file mode 100644 index 0000000..bfedcf1 --- /dev/null +++ b/zsh_completion.md @@ -0,0 +1,26 @@ +## Generating Zsh Completion for your cobra.Command + +Cobra supports native Zsh completion generated from the root `cobra.Command`. +The generated completion script should be put somewhere in your `$fpath` named +`_`. + +### What's Supported + +* Completion for all non-hidden subcommands using their `.Short` description. +* Completion for all non-hidden flags using the following rules: + * Filename completion works by marking the flag with `cmd.MarkFlagFilename...` + family of commands. However, it will ignore specific extensions requested by + this command (see about what's not supported yet below). + * The requirement for argument to the flag is decided by the `.NoOptDefVal` + flag value - if it's empty then completion will expect an argument. + * Flags of one of the various `*Arrary` and `*Slice` types supports multiple + specifications (with or without argument depending on the specific type). + +### What's not yet Supported + +* Positional argument completion are not supported yet. +* Filename completion ignores extension specification. +* Custom completion scripts are not supported yet (We should probably create zsh + specific one, doesn't make sense to re-use the bash one as the functions will + be different). +* Whatever other feature you're looking for and doesn't exist :)