Skip to content

Commit

Permalink
Add tk diff --exit-zero flag
Browse files Browse the repository at this point in the history
That causes `tk diff` to exit with 0 when there is a diff present.

Signed-off-by: Craig Furman <craig.furman89@gmail.com>
  • Loading branch information
craigfurman committed Feb 5, 2021
1 parent 315bb09 commit 4ff6849
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/tk/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func diffCmd() *cli.Command {
cmd.Flags().StringVar(&opts.Strategy, "diff-strategy", "", "force the diff-strategy to use. Automatically chosen if not set.")
cmd.Flags().BoolVarP(&opts.Summarize, "summarize", "s", false, "print summary of the differences, not the actual contents")
cmd.Flags().BoolVarP(&opts.WithPrune, "with-prune", "p", false, "include objects deleted from the configuration in the differences")
cmd.Flags().BoolVarP(&opts.ExitZero, "exit-zero", "z", false, "Exit with 0 even when differences are found.")

vars := workflowFlags(cmd.Flags())
getJsonnetOpts := jsonnetFlags(cmd.Flags())
Expand Down Expand Up @@ -142,7 +143,11 @@ func diffCmd() *cli.Command {
return err
}

os.Exit(ExitStatusDiff)
exitStatusDiff := ExitStatusDiff
if opts.ExitZero {
exitStatusDiff = ExitStatusClean
}
os.Exit(exitStatusDiff)
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/tanka/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ type DiffOpts struct {
Summarize bool
// WithPrune includes objects to be deleted by prune command in the diff
WithPrune bool
// Exit with 0 even when differences are found
ExitZero bool
}

// Diff parses the environment at the given directory (a `baseDir`) and returns
Expand Down

0 comments on commit 4ff6849

Please sign in to comment.