Skip to content

Commit

Permalink
Add support for YAML output format (securego#177)
Browse files Browse the repository at this point in the history
* Add YAML output format

* Update README
  • Loading branch information
cosmincojocar authored and gcmurphy committed Mar 5, 2018
1 parent c6183b4 commit 1d9f816
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ $ gas -nosec=true ./...

### Output formats

Gas currently supports text, json, csv and JUnit XML output formats. By default
Gas currently supports text, json, yaml, csv and JUnit XML output formats. By default
results will be reported to stdout, but can also be written to an output
file. The output format is controlled by the '-fmt' flag, and the output file is controlled by the '-out' flag as follows:

Expand Down
2 changes: 1 addition & 1 deletion cmd/gas/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var (
flagIgnoreNoSec = flag.Bool("nosec", false, "Ignores #nosec comments when set")

// format output
flagFormat = flag.String("fmt", "text", "Set output format. Valid options are: json, csv, junit-xml, html, or text")
flagFormat = flag.String("fmt", "text", "Set output format. Valid options are: json, yaml, csv, junit-xml, html, or text")

// output file
flagOutput = flag.String("out", "", "Set output file for results")
Expand Down
12 changes: 12 additions & 0 deletions output/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
plainTemplate "text/template"

"github.com/GoASTScanner/gas"
"gopkg.in/yaml.v2"
)

// ReportFormat enumrates the output format for reported issues
Expand Down Expand Up @@ -72,6 +73,8 @@ func CreateReport(w io.Writer, format string, issues []*gas.Issue, metrics *gas.
switch format {
case "json":
err = reportJSON(w, data)
case "yaml":
err = reportYAML(w, data)
case "csv":
err = reportCSV(w, data)
case "junit-xml":
Expand Down Expand Up @@ -99,6 +102,15 @@ func reportJSON(w io.Writer, data *reportInfo) error {
return err
}

func reportYAML(w io.Writer, data *reportInfo) error {
raw, err := yaml.Marshal(data)
if err != nil {
return err
}
_, err = w.Write(raw)
return err
}

func reportCSV(w io.Writer, data *reportInfo) error {
out := csv.NewWriter(w)
defer out.Flush()
Expand Down

0 comments on commit 1d9f816

Please sign in to comment.