Skip to content

Commit

Permalink
Added "scan.hitsonly" option
Browse files Browse the repository at this point in the history
  • Loading branch information
joelanford committed Feb 12, 2017
1 parent ad3a843 commit a191183
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ By default, ramdisk scratch space is disabled. To enable it, set
Usage: goscan [options] <scanfiles>
-scan.context int
Context to capture around each hit (default 10)
-scan.hitsonly
Only output results containing hits
-scan.output string
Results output file ("-" for stdout) (default "-")
-scan.parallelism int
Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ScanOpts struct {
KeywordsFile string
Policies []string
HitContext int
HitsOnly bool
ResultsFile string
Parallelism int
}
Expand Down Expand Up @@ -207,9 +208,11 @@ func run() error {
if !ok {
return nil
}
err = e.Encode(sr)
if err != nil {
return err
if !scanOpts.HitsOnly || len(sr.Hits) > 0 {
err = e.Encode(sr)
if err != nil {
return err
}
}
}
}
Expand All @@ -228,9 +231,10 @@ func parseFlags() (*scratch.Opts, *ScanOpts, error) {
configureScratchOpts(&scratchOpts)
flag.StringVar(&scanOpts.KeywordsFile, "scan.words", "", "YAML keywords file")
flag.IntVar(&scanOpts.HitContext, "scan.context", 10, "Context to capture around each hit")
flag.BoolVar(&scanOpts.HitsOnly, "scan.hitsonly", false, "Only output results containing hits")
flag.StringVar(&policies, "scan.policies", "all", "Comma-separated list of keyword policies")
flag.StringVar(&scanOpts.ResultsFile, "scan.output", "-", "Results output file (\"-\" for stdout)")
flag.IntVar(&scanOpts.Parallelism, "scan.parallelism", runtime.NumCPU(), "Number of goroutines to use to scan files.")
flag.IntVar(&scanOpts.Parallelism, "scan.parallelism", runtime.NumCPU(), "Number of goroutines to use to scan files")

flag.Parse()

Expand Down

0 comments on commit a191183

Please sign in to comment.