From 27b77a6b6eb035dafd8a025ea29d89ea2f967e2e Mon Sep 17 00:00:00 2001 From: John McCabe Date: Wed, 28 Feb 2018 00:33:34 +0000 Subject: [PATCH] Prefix bash functions with root command name Prior to this commit the autocomplete bash functions were being prefixed with the root command name, but references to those functions from subcommands were having the subcommands prefixed instead - causing the function lookups to fail and error out. For example (as observed in kubernetes/kubernetes#60517): kubectl create -f [Tab] failed with the following message: kubectl create -f __create_handle_filename_extension_flag: command not found in this case the function being invoked should be __kubectl_handle_filename_extension_flag Signed-off-by: John McCabe --- bash_completions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash_completions.go b/bash_completions.go index d898630b..291eae7d 100644 --- a/bash_completions.go +++ b/bash_completions.go @@ -317,7 +317,7 @@ func writeFlagHandler(buf *bytes.Buffer, name string, annotations map[string][]s var ext string if len(value) > 0 { - ext = fmt.Sprintf("__%s_handle_filename_extension_flag ", cmd.Name()) + strings.Join(value, "|") + ext = fmt.Sprintf("__%s_handle_filename_extension_flag ", cmd.Root().Name()) + strings.Join(value, "|") } else { ext = "_filedir" } @@ -335,7 +335,7 @@ func writeFlagHandler(buf *bytes.Buffer, name string, annotations map[string][]s var ext string if len(value) == 1 { - ext = fmt.Sprintf("__%s_handle_subdirs_in_dir_flag ", cmd.Name()) + value[0] + ext = fmt.Sprintf("__%s_handle_subdirs_in_dir_flag ", cmd.Root().Name()) + value[0] } else { ext = "_filedir -d" }