From e619cec0904f87f43d0e21e3e6c516f513f31e83 Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Tue, 7 Jan 2020 11:49:40 -0800 Subject: [PATCH] Cleanup completion for kustomize --- cmd/config/main.go | 6 +++++- kustomize/main.go | 20 +------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/cmd/config/main.go b/cmd/config/main.go index ff1b6f2eb..ebc89adcf 100644 --- a/cmd/config/main.go +++ b/cmd/config/main.go @@ -9,6 +9,7 @@ package main import ( "os" + "sigs.k8s.io/kustomize/cmd/config/complete" "sigs.k8s.io/kustomize/cmd/config/configcobra" "sigs.k8s.io/kustomize/kyaml/commandutil" ) @@ -16,7 +17,10 @@ import ( func main() { // enable the config commands os.Setenv(commandutil.EnableAlphaCommmandsEnvName, "true") - if err := configcobra.NewConfigCommand("").Execute(); err != nil { + cmd := configcobra.NewConfigCommand("") + complete.Complete(cmd).Complete("config") + + if err := cmd.Execute(); err != nil { os.Exit(1) } } diff --git a/kustomize/main.go b/kustomize/main.go index 8545bc22c..2dfb826a0 100644 --- a/kustomize/main.go +++ b/kustomize/main.go @@ -6,35 +6,17 @@ package main import ( "os" - "path/filepath" - "github.com/spf13/cobra" "sigs.k8s.io/kustomize/cmd/config/complete" "sigs.k8s.io/kustomize/kustomize/v3/internal/commands" ) func main() { cmd := commands.NewDefaultCommand() - completion(cmd) + complete.Complete(cmd).Complete("kustomize") if err := cmd.Execute(); err != nil { os.Exit(1) } os.Exit(0) } - -// completion performs shell completion if kustomize is being called to provide -// shell completion commands. -func completion(cmd *cobra.Command) { - // bash shell completion passes the command name as the first argument - // do this after configuring cmd so it has all the subcommands - if len(os.Args) > 1 { - // use the base name in case kustomize is called with an absolute path - name := filepath.Base(os.Args[1]) - if name == "kustomize" { - // complete calls kustomize with itself as an argument - complete.Complete(cmd).Complete("kustomize") - os.Exit(0) - } - } -}