Merge branch 'master' into feature/issue-107

pull/108/head
Liz Rice 6 years ago committed by GitHub
commit 0b4872104d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -137,41 +137,48 @@ func colorPrint(state check.State, s string) {
// prettyPrint outputs the results to stdout in human-readable format // prettyPrint outputs the results to stdout in human-readable format
func prettyPrint(r *check.Controls, summary check.Summary) { func prettyPrint(r *check.Controls, summary check.Summary) {
colorPrint(check.INFO, fmt.Sprintf("%s %s\n", r.ID, r.Text)) // Print check results.
for _, g := range r.Groups { if !noResults {
colorPrint(check.INFO, fmt.Sprintf("%s %s\n", g.ID, g.Text)) colorPrint(check.INFO, fmt.Sprintf("%s %s\n", r.ID, r.Text))
for _, c := range g.Checks { for _, g := range r.Groups {
colorPrint(c.State, fmt.Sprintf("%s %s\n", c.ID, c.Text)) colorPrint(check.INFO, fmt.Sprintf("%s %s\n", g.ID, g.Text))
for _, c := range g.Checks {
colorPrint(c.State, fmt.Sprintf("%s %s\n", c.ID, c.Text))
}
} }
}
fmt.Println() fmt.Println()
}
// Print remediations. // Print remediations.
if summary.Fail > 0 || summary.Warn > 0 { if !noRemediations {
colors[check.WARN].Printf("== Remediations ==\n") if summary.Fail > 0 || summary.Warn > 0 {
for _, g := range r.Groups { colors[check.WARN].Printf("== Remediations ==\n")
for _, c := range g.Checks { for _, g := range r.Groups {
if c.State != check.PASS { for _, c := range g.Checks {
fmt.Printf("%s %s\n", c.ID, c.Remediation) if c.State != check.PASS {
fmt.Printf("%s %s\n", c.ID, c.Remediation)
}
} }
} }
fmt.Println()
} }
fmt.Println()
} }
// Print summary setting output color to highest severity. // Print summary setting output color to highest severity.
var res check.State if !noSummary {
if summary.Fail > 0 { var res check.State
res = check.FAIL if summary.Fail > 0 {
} else if summary.Warn > 0 { res = check.FAIL
res = check.WARN } else if summary.Warn > 0 {
} else { res = check.WARN
res = check.PASS } else {
} res = check.PASS
}
colors[res].Printf("== Summary ==\n") colors[res].Printf("== Summary ==\n")
fmt.Printf("%d checks PASS\n%d checks FAIL\n%d checks WARN\n", fmt.Printf("%d checks PASS\n%d checks FAIL\n%d checks WARN\n",
summary.Pass, summary.Fail, summary.Warn, summary.Pass, summary.Fail, summary.Warn,
) )
}
} }

@ -37,6 +37,9 @@ var (
masterFile string masterFile string
nodeFile string nodeFile string
federatedFile string federatedFile string
noResults bool
noSummary bool
noRemediations bool
) )
// RootCmd represents the base command when called without any subcommands // RootCmd represents the base command when called without any subcommands
@ -61,8 +64,13 @@ func Execute() {
func init() { func init() {
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
// Output control
RootCmd.PersistentFlags().BoolVar(&noResults, "noresults", false, "Disable prints of results section")
RootCmd.PersistentFlags().BoolVar(&noSummary, "nosummary", false, "Disable printing of summary section")
RootCmd.PersistentFlags().BoolVar(&noRemediations, "noremediations", false, "Disable printing of remediations section")
RootCmd.PersistentFlags().BoolVar(&jsonFmt, "json", false, "Prints the results as JSON") RootCmd.PersistentFlags().BoolVar(&jsonFmt, "json", false, "Prints the results as JSON")
RootCmd.PersistentFlags().BoolVar(&pgSQL, "pgsql", false, "Save the results to PostgreSQL") RootCmd.PersistentFlags().BoolVar(&pgSQL, "pgsql", false, "Save the results to PostgreSQL")
RootCmd.PersistentFlags().StringVarP( RootCmd.PersistentFlags().StringVarP(
&checkList, &checkList,
"check", "check",

Loading…
Cancel
Save