From d4947fce2349a9e11abc6e412cbc5f77e96de224 Mon Sep 17 00:00:00 2001 From: Miguel Bernabeu Diaz Date: Thu, 14 Feb 2019 02:11:26 +0100 Subject: [PATCH] Add --expect-no-changes flag to preview (#449) We want to offer a return-code oriented interface to detect changes pending to be applied. The preview command, by default, returns 0 regardless of pending changes. We add a flag, `--expect-no-changes`, that will return non-zero if there are changes pending application, and 0 if there are none. --- commands/previewPush.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commands/previewPush.go b/commands/previewPush.go index f4317f95f..e18821b18 100644 --- a/commands/previewPush.go +++ b/commands/previewPush.go @@ -34,6 +34,7 @@ type PreviewArgs struct { GetCredentialsArgs FilterArgs Notify bool + WarnChanges bool } func (args *PreviewArgs) flags() []cli.Flag { @@ -45,6 +46,11 @@ func (args *PreviewArgs) flags() []cli.Flag { Destination: &args.Notify, Usage: `set to true to send notifications to configured destinations`, }) + flags = append(flags, cli.BoolFlag{ + Name: "expect-no-changes", + Destination: &args.WarnChanges, + Usage: `set to true for non-zero return code if there are changes`, + }) return flags } @@ -165,6 +171,9 @@ DomainLoop: if anyErrors { return errors.Errorf("Completed with errors") } + if totalCorrections != 0 && args.WarnChanges { + return errors.Errorf("There are pending changes") + } return nil }