Skip to content

Commit

Permalink
Add quiet mode
Browse files Browse the repository at this point in the history
When -quiet is specified on the command line we will only show issues
when issues were found.

Fixes #55
  • Loading branch information
gcmurphy committed Nov 4, 2016
1 parent 9fa0b72 commit d72cee8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}

0 comments on commit d72cee8

Please sign in to comment.