diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4e24280..51e1bca 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -18,4 +18,5 @@ jobs: id: cac with: args: --help - - run: echo -e "${{ steps.cac.outputs.result }}" \ No newline at end of file + - run: echo -e "${{ steps.cac.outputs.result }}" + name: print action output \ No newline at end of file diff --git a/cmd/diff.go b/cmd/diff.go index 1e68d16..9efc75d 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -29,6 +29,7 @@ var ( With("profile", rootConfig.Profile). With("source", diffConfig.Source). With("target", diffConfig.Target). + With("out", diffConfig.Out). Info("Comparing workspace configuration") if app, err = cac.InitApp(rootConfig.ConfigPath, rootConfig.Profile); err != nil { @@ -52,6 +53,14 @@ var ( return err } + if diffConfig.Out != "-" { + if err = os.WriteFile(diffConfig.Out, []byte(result), 0644); err != nil { + return errors.Wrap(err, "failed to write diff result to file") + } + + return nil + } + if _, err = os.Stdout.Write([]byte(result)); err != nil { return errors.Wrap(err, "failed to write diff result to stdout") } @@ -66,6 +75,7 @@ var ( WithSecrets bool Colors bool OnlyPresent bool + Out string } ) @@ -75,6 +85,7 @@ func init() { diffCmd.PersistentFlags().StringVar(&diffConfig.Workspace, "workspace", "", "Workspace to compare") diffCmd.PersistentFlags().BoolVar(&diffConfig.Colors, "colors", true, "Colorize output") diffCmd.PersistentFlags().BoolVar(&diffConfig.OnlyPresent, "only-present", false, "Compare only resources present at source") + diffCmd.PersistentFlags().StringVar(&diffConfig.Out, "out", "-", "Diff output. It can be a file or '-' for stdout") mustMarkRequired(diffCmd, "source", "target", "workspace") }