From 90e23dc3a27b26d8b6ea784361aeefa2b34598d3 Mon Sep 17 00:00:00 2001 From: nshauli Date: Thu, 23 May 2019 17:34:21 +0300 Subject: [PATCH] Add support for writing JSON results to output file using --output flag --- app.go | 2 +- root.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index 2cb16a5..b168e99 100644 --- a/app.go +++ b/app.go @@ -51,7 +51,7 @@ func outputResults(controls *check.Controls, summary check.Summary) error { if err != nil { return err } - fmt.Println(string(out)) + util.PrintOutput(string(out), outputFile) } else { util.PrettyPrint(controls, summary, noRemediations, includeTestOutput) } diff --git a/root.go b/root.go index 212ba7a..862db75 100644 --- a/root.go +++ b/root.go @@ -35,6 +35,7 @@ var ( checkList string jsonFmt bool includeTestOutput bool + outputFile string ) // RootCmd represents the base command when called without any subcommands @@ -74,6 +75,7 @@ func init() { RootCmd.Flags().StringVarP(&cfgDir, "config-dir", "D", "cfg", "directory to get benchmark definitions") RootCmd.PersistentFlags().BoolVar(&jsonFmt, "json", false, "Prints the results as JSON") RootCmd.PersistentFlags().BoolVar(&includeTestOutput, "include-test-output", false, "Prints the test's output") + RootCmd.PersistentFlags().StringVar(&outputFile, "outputfile", "", "Writes the JSON results to output file") RootCmd.PersistentFlags().StringVarP( &checkList, "check",