mirror of https://github.com/spf13/cobra.git
Compare commits
4 Commits
58ee80eaeb
...
32f250b307
Author | SHA1 | Date |
---|---|---|
Toni Kangas | 32f250b307 | |
Vui Lam | 02326d52c0 | |
Toni Kangas | 3f2dad7403 | |
Toni Kangas | fbc5c65ae1 |
|
@ -230,7 +230,7 @@ __%[1]s_handle_completion_types() {
|
|||
comp=${comp%%%%$tab*}
|
||||
# Only consider the completions that match
|
||||
if [[ $comp == "$cur"* ]]; then
|
||||
COMPREPLY+=("$comp")
|
||||
COMPREPLY+=( "$(printf %%q "$comp")" )
|
||||
fi
|
||||
done < <(printf "%%s\n" "${completions[@]}")
|
||||
;;
|
||||
|
@ -247,7 +247,14 @@ __%[1]s_handle_standard_completion_case() {
|
|||
|
||||
# Short circuit to optimize if we don't have descriptions
|
||||
if [[ "${completions[*]}" != *$tab* ]]; then
|
||||
IFS=$'\n' read -ra COMPREPLY -d '' < <(compgen -W "${completions[*]}" -- "$cur")
|
||||
local compgen_words=$(printf "%%s\n" "${completions[@]}")
|
||||
IFS=$'\n' read -ra COMPREPLY -d '' < <(IFS=$'\n' compgen -W "${compgen_words}" -- "$cur")
|
||||
|
||||
# If there is a single completion left, escape the completion
|
||||
if ((${#COMPREPLY[*]} == 1)); then
|
||||
COMPREPLY[0]=$(printf %%q "${COMPREPLY[0]}")
|
||||
fi
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
@ -266,12 +273,12 @@ __%[1]s_handle_standard_completion_case() {
|
|||
fi
|
||||
done < <(printf "%%s\n" "${completions[@]}")
|
||||
|
||||
# If there is a single completion left, remove the description text
|
||||
# If there is a single completion left, remove the description text and escape the completion
|
||||
if ((${#COMPREPLY[*]} == 1)); then
|
||||
__%[1]s_debug "COMPREPLY[0]: ${COMPREPLY[0]}"
|
||||
comp="${COMPREPLY[0]%%%%$tab*}"
|
||||
__%[1]s_debug "Removed description from single completion, which is now: ${comp}"
|
||||
COMPREPLY[0]=$comp
|
||||
COMPREPLY[0]=$(printf %%q "${comp}")
|
||||
else # Format the descriptions
|
||||
__%[1]s_format_comp_descriptions $longest
|
||||
fi
|
||||
|
|
|
@ -20,12 +20,12 @@ bin/ internal/ scripts/ pkg/ testdata/
|
|||
## Supported shells
|
||||
|
||||
Active Help is currently only supported for the following shells:
|
||||
- Bash (using [bash completion V2](shell_completions.md#bash-completion-v2) only). Note that bash 4.4 or higher is required for the prompt to appear when an Active Help message is printed.
|
||||
- Bash (using [bash completion V2](completions/_index.md#bash-completion-v2) only). Note that bash 4.4 or higher is required for the prompt to appear when an Active Help message is printed.
|
||||
- Zsh
|
||||
|
||||
## Adding Active Help messages
|
||||
|
||||
As Active Help uses the shell completion system, the implementation of Active Help messages is done by enhancing custom dynamic completions. If you are not familiar with dynamic completions, please refer to [Shell Completions](shell_completions.md).
|
||||
As Active Help uses the shell completion system, the implementation of Active Help messages is done by enhancing custom dynamic completions. If you are not familiar with dynamic completions, please refer to [Shell Completions](completions/_index.md).
|
||||
|
||||
Adding Active Help is done through the use of the `cobra.AppendActiveHelp(...)` function, where the program repeatedly adds Active Help messages to the list of completions. Keep reading for details.
|
||||
|
||||
|
@ -148,7 +148,7 @@ details for your users.
|
|||
|
||||
## Debugging Active Help
|
||||
|
||||
Debugging your Active Help code is done in the same way as debugging your dynamic completion code, which is with Cobra's hidden `__complete` command. Please refer to [debugging shell completion](shell_completions.md#debugging) for details.
|
||||
Debugging your Active Help code is done in the same way as debugging your dynamic completion code, which is with Cobra's hidden `__complete` command. Please refer to [debugging shell completion](completions/_index.md#debugging) for details.
|
||||
|
||||
When debugging with the `__complete` command, if you want to specify different Active Help configurations, you should use the active help environment variable. That variable is named `<PROGRAM>_ACTIVE_HELP` where any non-ASCII-alphanumeric characters are replaced by an `_`. For example, we can test deactivating some Active Help as shown below:
|
||||
|
||||
|
|
Loading…
Reference in New Issue