Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make binary Flag Global #128

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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