Skip to content

Commit

Permalink
Merge pull request #128 from puzzle/fix-kustomize-binary-flag
Browse files Browse the repository at this point in the history
Make `binary` Flag Global
  • Loading branch information
ioboi committed May 31, 2024
2 parents a48ae2b + efb7cdb commit b03b1ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
15 changes: 7 additions & 8 deletions cmd/kustomize.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"cmp"
"fmt"
"os/exec"

Expand All @@ -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")
Expand All @@ -46,10 +45,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)
}
5 changes: 5 additions & 0 deletions cmd/kustomize/build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kustomize

import (
"cmp"

"github.com/puzzle/goff/kustomize"

"github.com/spf13/cobra"
Expand All @@ -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)
},
}
Expand Down

0 comments on commit b03b1ec

Please sign in to comment.