Skip to content
Myr

Fix too many underscore for __custom_func (#794)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Fix too many underscore for __custom_func * Fix typo of too many leading underscores in docs

authored by Daisuke Taniwaki · committed by Eric Paris · parent fe5e611 · Browse files · 2 files+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+2 added−2 removed

  • other:+2 added−2 removed

2 files+2 added−2 removed

modified:bash_completions.go+1 added-1 removed
132 unmodified lines
133 # try command name qualified custom func134 __%[1]s_custom_func135 else136 # otherwise fall back to unqualified for compatibility137 declare -F ___custom_func >/dev/null && __custom_func137 declare -F __custom_func >/dev/null && __custom_func138 fi139 fi140141 # available in bash-completion >= 2, not always present on macOS
449 unmodified lines
modified:bash_completions.md+1 added-1 removed
107 unmodified lines
108 BashCompletionFunction: bash_completion_func,109}110```111112The `BashCompletionFunction` option is really only valid/useful on the root command. Doing the above will cause `___kubectl_custom_func()` (`__<command-use>_custom_func()`) to be called when the built in processor was unable to find a solution. In the case of kubernetes a valid command might look something like `kubectl get pod [mypod]`. If you type `kubectl get pod [tab][tab]` the `__kubectl_customc_func()` will run because the cobra.Command only understood "kubectl" and "get." `__kubectl_custom_func()` will see that the cobra.Command is "kubectl_get" and will thus call another helper `__kubectl_get_resource()`. `__kubectl_get_resource` will look at the 'nouns' collected. In our example the only noun will be `pod`. So it will call `__kubectl_parse_get pod`. `__kubectl_parse_get` will actually call out to kubernetes and get any pods. It will then set `COMPREPLY` to valid pods!112The `BashCompletionFunction` option is really only valid/useful on the root command. Doing the above will cause `__kubectl_custom_func()` (`__<command-use>_custom_func()`) to be called when the built in processor was unable to find a solution. In the case of kubernetes a valid command might look something like `kubectl get pod [mypod]`. If you type `kubectl get pod [tab][tab]` the `__kubectl_customc_func()` will run because the cobra.Command only understood "kubectl" and "get." `__kubectl_custom_func()` will see that the cobra.Command is "kubectl_get" and will thus call another helper `__kubectl_get_resource()`. `__kubectl_get_resource` will look at the 'nouns' collected. In our example the only noun will be `pod`. So it will call `__kubectl_parse_get pod`. `__kubectl_parse_get` will actually call out to kubernetes and get any pods. It will then set `COMPREPLY` to valid pods!113114## Have the completions code complete your 'nouns'115116In the above example "pod" was assumed to already be typed. But if you want `kubectl get [tab][tab]` to show a list of valid "nouns" you have to set them. Simplified code from `kubectl get` looks like:
140 unmodified lines