From eb2a8c6af8319faa3cc6cecbaa3182ad2ce3813d Mon Sep 17 00:00:00 2001 From: Ryo Nakamine Date: Sat, 28 Dec 2024 13:56:18 +0900 Subject: [PATCH 1/4] add --fail-on-kustomize-error option --- cmd/root.go | 1 + cmd/run.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 2e4d939..1c159ab 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -28,6 +28,7 @@ type rootFlags struct { var RootCmd = &cobra.Command{ Use: "git-kustomize-diff", Short: "git-kustomize-diff", + SilenceUsage: true, SilenceErrors: false, PersistentPreRun: func(cmd *cobra.Command, args []string) { if cmd.Use == "version" { diff --git a/cmd/run.go b/cmd/run.go index ca14558..5e567e9 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -36,6 +36,7 @@ type runFlags struct { gitPath string debug bool allowDirty bool + failOnKustomizeError bool } var runCmd = &cobra.Command{ @@ -80,6 +81,14 @@ var runCmd = &cobra.Command{ printRunResult(dir, opts, res) + if runOpts.failOnKustomizeError { + for _, v := range res.DiffMap.Results { + if _, ok := v.(*gitkustomizediff.DiffError); ok { + return fmt.Errorf("kustomize build failed") + } + } + } + return nil }, } @@ -96,6 +105,7 @@ func init() { runCmd.PersistentFlags().StringVar(&runOpts.gitPath, "git-path", "", "path of a git binary (default to git)") runCmd.PersistentFlags().BoolVar(&runOpts.debug, "debug", false, "debug mode") runCmd.PersistentFlags().BoolVar(&runOpts.allowDirty, "allow-dirty", false, "allow dirty tree") + runCmd.PersistentFlags().BoolVar(&runOpts.failOnKustomizeError, "fail-on-kustomize-error", false, "return non-zero status code if kustomize build fails") } func printRunResult(dirPath string, opts gitkustomizediff.RunOpts, res *gitkustomizediff.RunResult) { From 10c71d370406a1f98c4f2d286b00823f63354cd8 Mon Sep 17 00:00:00 2001 From: Ryo Nakamine Date: Sat, 28 Dec 2024 14:52:47 +0900 Subject: [PATCH 2/4] update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4cdc1ce..8fcfc5f 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Flags: --base string base commitish (default to origin/main) --debug debug mode --exclude string exclude regexp (default to none) + --fail-on-kustomize-error return non-zero status code if kustomize build fails --git-path string path of a git binary (default to git) -h, --help help for run --include string include regexp (default to all) From 2d9d3433989a1169c7b0fd661e54c094c55fc14c Mon Sep 17 00:00:00 2001 From: Ryo Nakamine Date: Mon, 30 Dec 2024 16:44:55 +0900 Subject: [PATCH 3/4] fix: rename option to fail-on-diff-error --- README.md | 5 +---- cmd/run.go | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8fcfc5f..0d1f087 100644 --- a/README.md +++ b/README.md @@ -37,15 +37,12 @@ $ git-kustomize-diff run Flags: ``` -Usage: - git-kustomize-diff run target_dir [flags] - Flags: --allow-dirty allow dirty tree --base string base commitish (default to origin/main) --debug debug mode --exclude string exclude regexp (default to none) - --fail-on-kustomize-error return non-zero status code if kustomize build fails + --fail-on-diff-error return non-zero status code if a diff error occurs --git-path string path of a git binary (default to git) -h, --help help for run --include string include regexp (default to all) diff --git a/cmd/run.go b/cmd/run.go index 5e567e9..257b74e 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -36,7 +36,7 @@ type runFlags struct { gitPath string debug bool allowDirty bool - failOnKustomizeError bool + failOnDiffError bool } var runCmd = &cobra.Command{ @@ -81,10 +81,10 @@ var runCmd = &cobra.Command{ printRunResult(dir, opts, res) - if runOpts.failOnKustomizeError { + if runOpts.failOnDiffError { for _, v := range res.DiffMap.Results { if _, ok := v.(*gitkustomizediff.DiffError); ok { - return fmt.Errorf("kustomize build failed") + return fmt.Errorf("fail on diff error") } } } @@ -105,7 +105,7 @@ func init() { runCmd.PersistentFlags().StringVar(&runOpts.gitPath, "git-path", "", "path of a git binary (default to git)") runCmd.PersistentFlags().BoolVar(&runOpts.debug, "debug", false, "debug mode") runCmd.PersistentFlags().BoolVar(&runOpts.allowDirty, "allow-dirty", false, "allow dirty tree") - runCmd.PersistentFlags().BoolVar(&runOpts.failOnKustomizeError, "fail-on-kustomize-error", false, "return non-zero status code if kustomize build fails") + runCmd.PersistentFlags().BoolVar(&runOpts.failOnDiffError, "fail-on-diff-error", false, "return non-zero status code if a diff error occurs") } func printRunResult(dirPath string, opts gitkustomizediff.RunOpts, res *gitkustomizediff.RunResult) { From 2b7e3088c10674a9bd9a115ffaf80f68061c8666 Mon Sep 17 00:00:00 2001 From: Ryo Nakamine Date: Mon, 30 Dec 2024 16:54:37 +0900 Subject: [PATCH 4/4] fix readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0d1f087..72dad97 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,9 @@ $ git-kustomize-diff run Flags: ``` +Usage: + git-kustomize-diff run target_dir [flags] + Flags: --allow-dirty allow dirty tree --base string base commitish (default to origin/main)