From 797f9377c4feecc07f0f67d572630af79b620405 Mon Sep 17 00:00:00 2001 From: Taj Date: Sun, 5 Feb 2023 14:05:08 +0000 Subject: [PATCH] file restructure and export to a file directly instead of redirecting the output --- cmd/vulnny/main.go => main.go | 12 +++++++++++- {cmd/vulnny/testdata => testdata}/vuln/README.md | 0 {cmd/vulnny/testdata => testdata}/vuln/go.mod | 0 {cmd/vulnny/testdata => testdata}/vuln/go.sum | 0 {cmd/vulnny/testdata => testdata}/vuln/vuln.go | 0 {cmd/vulnny/testdata => testdata}/vuln/vuln_extra.go | 0 6 files changed, 11 insertions(+), 1 deletion(-) rename cmd/vulnny/main.go => main.go (81%) rename {cmd/vulnny/testdata => testdata}/vuln/README.md (100%) rename {cmd/vulnny/testdata => testdata}/vuln/go.mod (100%) rename {cmd/vulnny/testdata => testdata}/vuln/go.sum (100%) rename {cmd/vulnny/testdata => testdata}/vuln/vuln.go (100%) rename {cmd/vulnny/testdata => testdata}/vuln/vuln_extra.go (100%) diff --git a/cmd/vulnny/main.go b/main.go similarity index 81% rename from cmd/vulnny/main.go rename to main.go index bfd7634..722ecbb 100644 --- a/cmd/vulnny/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( ) func main() { + outFile := flag.String("o", "", "File to export the SARIF log to. If not specified, the log would be printed to the stdout.") flag.Parse() log, err := runVulnny() if err != nil { @@ -27,7 +28,16 @@ func main() { fmt.Fprintf(os.Stderr, "failed to marshal SARIF: %s\n", err.Error()) os.Exit(1) } - fmt.Println(string(data)) + out := os.Stdout + if *outFile != "" { + out, err = os.OpenFile(*outFile, os.O_WRONLY|os.O_CREATE, 0644) + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } + defer out.Close() + } + fmt.Fprintln(out, string(data)) } func runVulnny() (*sarif.Log, error) { diff --git a/cmd/vulnny/testdata/vuln/README.md b/testdata/vuln/README.md similarity index 100% rename from cmd/vulnny/testdata/vuln/README.md rename to testdata/vuln/README.md diff --git a/cmd/vulnny/testdata/vuln/go.mod b/testdata/vuln/go.mod similarity index 100% rename from cmd/vulnny/testdata/vuln/go.mod rename to testdata/vuln/go.mod diff --git a/cmd/vulnny/testdata/vuln/go.sum b/testdata/vuln/go.sum similarity index 100% rename from cmd/vulnny/testdata/vuln/go.sum rename to testdata/vuln/go.sum diff --git a/cmd/vulnny/testdata/vuln/vuln.go b/testdata/vuln/vuln.go similarity index 100% rename from cmd/vulnny/testdata/vuln/vuln.go rename to testdata/vuln/vuln.go diff --git a/cmd/vulnny/testdata/vuln/vuln_extra.go b/testdata/vuln/vuln_extra.go similarity index 100% rename from cmd/vulnny/testdata/vuln/vuln_extra.go rename to testdata/vuln/vuln_extra.go