From a46694c8d6e96466786ad411401ef529924975a5 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Fri, 6 Sep 2019 23:43:24 -0400 Subject: [PATCH 1/2] Dynamic completion to use same binary as main call The binary of Helm to use for dynamic completion should be the same as the actual Helm binary being used. For example, if PATH points to a version of helm v2, but the user calls bin/helm to use a local v3 version, then dynamic completion should also use bin/helm. If not, in this example, the dynamic completion will use the information returned by helm v2. This improvement is particularly useful for users that will run both helm v2 and helm v3 at the same time. Signed-off-by: Marc Khouzam --- cmd/helm/root.go | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/cmd/helm/root.go b/cmd/helm/root.go index 69981ca01..bc8e4a800 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -91,30 +91,49 @@ __helm_get_namespaces() __helm_list_releases() { - __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - local out filter - # Use ^ to map from the start of the release name - filter="^${words[c]}" - if out=$(helm list $(__helm_override_flags) -a -q -m 1000 -f ${filter} 2>/dev/null); then + __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" + local out filter helm_binary + + # Use ^ to map from the start of the release name + filter="^${words[c]}" + + helm_binary="${words[0]}" + __helm_debug "${FUNCNAME[0]}: helm_binary is ${helm_binary}" + + # Use eval in case helm_binary or __helm_override_flags contains a variable (e.g., $HOME/bin/h3) + if out=$(eval ${helm_binary} list $(__helm_override_flags) -a -q -m 1000 -f ${filter} 2>/dev/null); then COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) fi } + __helm_list_repos() { __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - local out - if out=$(helm repo list 2>/dev/null | tail +2 | cut -f1); then + local out helm_binary + + helm_binary="${words[0]}" + __helm_debug "${FUNCNAME[0]}: helm_binary is ${helm_binary}" + + # Use eval in case helm_binary contains a variable (e.g., $HOME/bin/h3) + if out=$(eval ${helm_binary} repo list 2>/dev/null | tail +2 | cut -f1); then COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) fi } + __helm_list_plugins() { __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - local out - if out=$(helm plugin list 2>/dev/null | tail +2 | cut -f1); then + local out helm_binary + + helm_binary="${words[0]}" + __helm_debug "${FUNCNAME[0]}: helm_binary is ${helm_binary}" + + # Use eval in case helm_binary contains a variable (e.g., $HOME/bin/h3) + if out=$(eval ${helm_binary} plugin list 2>/dev/null | tail +2 | cut -f1); then COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) fi } + __helm_custom_func() { __helm_debug "${FUNCNAME[0]}: last_command is $last_command" From 2db09189f4702368fe6c7be9d832bcf805c48087 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Mon, 23 Sep 2019 21:55:00 -0400 Subject: [PATCH 2/2] Simplify logic Signed-off-by: Marc Khouzam --- cmd/helm/root.go | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/cmd/helm/root.go b/cmd/helm/root.go index bc8e4a800..74080ef0c 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -89,19 +89,22 @@ __helm_get_namespaces() fi } -__helm_list_releases() +__helm_binary_name() { - __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - local out filter helm_binary - - # Use ^ to map from the start of the release name - filter="^${words[c]}" - + local helm_binary helm_binary="${words[0]}" __helm_debug "${FUNCNAME[0]}: helm_binary is ${helm_binary}" + echo ${helm_binary} +} - # Use eval in case helm_binary or __helm_override_flags contains a variable (e.g., $HOME/bin/h3) - if out=$(eval ${helm_binary} list $(__helm_override_flags) -a -q -m 1000 -f ${filter} 2>/dev/null); then +__helm_list_releases() +{ + __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" + local out filter + # Use ^ to map from the start of the release name + filter="^${words[c]}" + # Use eval in case helm_binary_name or __helm_override_flags contains a variable (e.g., $HOME/bin/h3) + if out=$(eval $(__helm_binary_name) list $(__helm_override_flags) -a -q -m 1000 -f ${filter} 2>/dev/null); then COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) fi } @@ -109,13 +112,9 @@ __helm_list_releases() __helm_list_repos() { __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - local out helm_binary - - helm_binary="${words[0]}" - __helm_debug "${FUNCNAME[0]}: helm_binary is ${helm_binary}" - - # Use eval in case helm_binary contains a variable (e.g., $HOME/bin/h3) - if out=$(eval ${helm_binary} repo list 2>/dev/null | tail +2 | cut -f1); then + local out + # Use eval in case helm_binary_name contains a variable (e.g., $HOME/bin/h3) + if out=$(eval $(__helm_binary_name) repo list 2>/dev/null | tail +2 | cut -f1); then COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) fi } @@ -123,13 +122,9 @@ __helm_list_repos() __helm_list_plugins() { __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" - local out helm_binary - - helm_binary="${words[0]}" - __helm_debug "${FUNCNAME[0]}: helm_binary is ${helm_binary}" - - # Use eval in case helm_binary contains a variable (e.g., $HOME/bin/h3) - if out=$(eval ${helm_binary} plugin list 2>/dev/null | tail +2 | cut -f1); then + local out + # Use eval in case helm_binary_name contains a variable (e.g., $HOME/bin/h3) + if out=$(eval $(__helm_binary_name) plugin list 2>/dev/null | tail +2 | cut -f1); then COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) fi }