mirror of
https://github.com/securego/gosec.git
synced 2024-12-25 03:55:54 +00:00
Add a recursive flag -r to skip specifying ./... path
* added recursive flag to skip specifying ./... path * refactored to remove code duplication
This commit is contained in:
parent
48bbf96b56
commit
ea5d31f7f5
1 changed files with 13 additions and 4 deletions
|
@ -133,6 +133,9 @@ var (
|
||||||
// print the text report with color, this is enabled by default
|
// print the text report with color, this is enabled by default
|
||||||
flagColor = flag.Bool("color", true, "Prints the text format report with colorization when it goes in the stdout")
|
flagColor = flag.Bool("color", true, "Prints the text format report with colorization when it goes in the stdout")
|
||||||
|
|
||||||
|
// append ./... to the target dir.
|
||||||
|
flagRecursive = flag.Bool("r", false, "Appends \"./...\" to the target dir.")
|
||||||
|
|
||||||
// overrides the output format when stdout the results while saving them in the output file
|
// overrides the output format when stdout the results while saving them in the output file
|
||||||
flagVerbose = flag.String("verbose", "", "Overrides the output format when stdout the results while saving them in the output file.\nValid options are: json, yaml, csv, junit-xml, html, sonarqube, golint, sarif or text")
|
flagVerbose = flag.String("verbose", "", "Overrides the output format when stdout the results while saving them in the output file.\nValid options are: json, yaml, csv, junit-xml, html, sonarqube, golint, sarif or text")
|
||||||
|
|
||||||
|
@ -319,9 +322,9 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure at least one file was specified
|
// Ensure at least one file was specified or that the recursive -r flag was set.
|
||||||
if flag.NArg() == 0 {
|
if flag.NArg() == 0 && !*flagRecursive {
|
||||||
fmt.Fprintf(os.Stderr, "\nError: FILE [FILE...] or './...' expected\n") //#nosec
|
fmt.Fprintf(os.Stderr, "\nError: FILE [FILE...] or './...' or -r expected\n") //#nosec
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -380,13 +383,19 @@ func main() {
|
||||||
|
|
||||||
excludedDirs := gosec.ExcludedDirsRegExp(flagDirsExclude)
|
excludedDirs := gosec.ExcludedDirsRegExp(flagDirsExclude)
|
||||||
var packages []string
|
var packages []string
|
||||||
for _, path := range flag.Args() {
|
|
||||||
|
paths := flag.Args()
|
||||||
|
if len(paths) == 0 {
|
||||||
|
paths = append(paths, "./...")
|
||||||
|
}
|
||||||
|
for _, path := range paths {
|
||||||
pcks, err := gosec.PackagePaths(path, excludedDirs)
|
pcks, err := gosec.PackagePaths(path, excludedDirs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal(err)
|
logger.Fatal(err)
|
||||||
}
|
}
|
||||||
packages = append(packages, pcks...)
|
packages = append(packages, pcks...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(packages) == 0 {
|
if len(packages) == 0 {
|
||||||
logger.Fatal("No packages found")
|
logger.Fatal("No packages found")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue