From d72cee866343fae171a41a9efcaedd4e387a1b34 Mon Sep 17 00:00:00 2001 From: Grant Murphy Date: Fri, 4 Nov 2016 11:36:55 -0700 Subject: [PATCH] Add quiet mode When -quiet is specified on the command line we will only show issues when issues were found. Fixes #55 --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 2c0aa17..1c29b94 100644 --- a/main.go +++ b/main.go @@ -38,8 +38,12 @@ var flagFormat = flag.String("fmt", "text", "Set output format. Valid options ar // output file var flagOutput = flag.String("out", "", "Set output file for results") +// config file var flagConfig = flag.String("conf", "", "Path to optional config file") +// quiet +var flagQuiet = flag.Bool("quiet", false, "Only show output when errors are found") + var usageText = ` GAS - Go AST Scanner @@ -216,6 +220,12 @@ func main() { } } + issuesFound := len(analyzer.Issues) > 0 + // Exit quietly if nothing was found + if !issuesFound && *flagQuiet { + os.Exit(0) + } + // Create output report if *flagOutput != "" { outfile, err := os.Create(*flagOutput) @@ -229,7 +239,7 @@ func main() { } // Do we have an issue? If so exit 1 - if len(analyzer.Issues) > 0 { + if issuesFound { os.Exit(1) } }