Skip to content

Commit

Permalink
feat(cmd) add --non-zero-exit-code flag to diff command
Browse files Browse the repository at this point in the history
This makes it easy to integrate decK into a CI pipeline.
A script can easily determine if there is a diff present by examining
the exit code of decK.

Fix #98
  • Loading branch information
hbagdi committed Nov 9, 2019
1 parent b6ebdee commit edd520e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"net/http"
"os"

"github.com/fatih/color"
"github.com/hbagdi/deck/diff"
Expand Down Expand Up @@ -109,5 +110,9 @@ func syncMain(filename string, dry bool, parallelism int) error {
printFn(" Created: %v\n", stats.CreateOps)
printFn(" Updated: %v\n", stats.UpdateOps)
printFn(" Deleted: %v\n", stats.DeleteOps)
if diffCmdNonZeroExitCode &&
stats.CreateOps+stats.UpdateOps+stats.DeleteOps != 0 {
os.Exit(2)
}
return nil
}
9 changes: 7 additions & 2 deletions cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
)

var (
diffCmdKongStateFile string
diffCmdParallelism int
diffCmdKongStateFile string
diffCmdParallelism int
diffCmdNonZeroExitCode bool
)

// diffCmd represents the diff command
Expand Down Expand Up @@ -48,4 +49,8 @@ func init() {
"select-tag", []string{},
"only entities matching tags specified via this flag are diffed.\n"+
"Multiple tags are ANDed together.")
diffCmd.Flags().BoolVar(&diffCmdNonZeroExitCode, "non-zero-exit-code",
false, "return exit code 2 if there is a diff present,\n"+
"exit code 0 if no diff is found,\n"+
"and exit code 1 if an error occurs.")
}

0 comments on commit edd520e

Please sign in to comment.