From fdb3bc544bc1852b3cad791946a5a8147f70e24f Mon Sep 17 00:00:00 2001 From: Yannik Daellenbach Date: Thu, 30 May 2024 16:50:30 +0200 Subject: [PATCH 1/2] Make "binary" flag persistent --- cmd/kustomize.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/kustomize.go b/cmd/kustomize.go index ef95df5..3c6274c 100644 --- a/cmd/kustomize.go +++ b/cmd/kustomize.go @@ -46,10 +46,10 @@ var kustomizeCmd = &cobra.Command{ } func init() { - kustomizeCmd.AddCommand(kustomize.KustomizeBuildCmd) - rootCmd.AddCommand(kustomizeCmd) - - binary = kustomizeCmd.Flags().String("binary", "", "Alternative kustomize binary") + binary = kustomizeCmd.PersistentFlags().String("binary", "", "Alternative kustomize binary") version = kustomizeCmd.Flags().BoolP("version", "v", false, "Display version of kustomize") outputDotDir = kustomizeCmd.Flags().StringP("output-dir", "o", ".", "Output directory") + + kustomizeCmd.AddCommand(kustomize.KustomizeBuildCmd) + rootCmd.AddCommand(kustomizeCmd) } From efb7cdb9d206b1a769299031b12f6b3c3249b7fe Mon Sep 17 00:00:00 2001 From: Yannik Daellenbach Date: Thu, 30 May 2024 16:50:50 +0200 Subject: [PATCH 2/2] Handle if "binary" flag is not set (is empty) Set `kustomize` as default --- cmd/kustomize.go | 7 +++---- cmd/kustomize/build.go | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/kustomize.go b/cmd/kustomize.go index 3c6274c..024fe3d 100644 --- a/cmd/kustomize.go +++ b/cmd/kustomize.go @@ -1,6 +1,7 @@ package cmd import ( + "cmp" "fmt" "os/exec" @@ -25,10 +26,8 @@ var kustomizeCmd = &cobra.Command{ }, Long: `Generate a DOT file to visualize the dependencies between your kustomize components`, RunE: func(cmd *cobra.Command, args []string) error { - kustomizeCmd := "kustomize" - if *binary != "" { - kustomizeCmd = *binary - } + + kustomizeCmd := cmp.Or(*binary, "kustomize") if *version { kustomizeCmd := exec.CommandContext(cmd.Context(), kustomizeCmd, "version") diff --git a/cmd/kustomize/build.go b/cmd/kustomize/build.go index 919ef97..f228679 100644 --- a/cmd/kustomize/build.go +++ b/cmd/kustomize/build.go @@ -1,6 +1,8 @@ package kustomize import ( + "cmp" + "github.com/puzzle/goff/kustomize" "github.com/spf13/cobra" @@ -24,6 +26,9 @@ var KustomizeBuildCmd = &cobra.Command{ if err != nil { return err } + + kustomizeCommand = cmp.Or(kustomizeCommand, "kustomize") + return kustomize.BuildAll(kustomizeCommand, args[0], *outputBuildDir) }, }