Add support for YAML output format (#177)

* Add YAML output format

* Update README
This commit is contained in:
cosmincojocar 2018-03-05 13:20:24 +01:00 committed by Grant Murphy
parent c6183b4d5c
commit 1d9f816ca5
4 changed files with 15 additions and 3 deletions

2
Godeps/Godeps.json generated
View file

@ -296,7 +296,7 @@
},
{
"ImportPath": "gopkg.in/yaml.v2",
"Rev": "eb3733d160e74a9c7e442f435eb3bea458e1d19f"
"Rev": "d670f9405373e636a5a2765eea47fac0c9bc91a4"
}
]
}

View file

@ -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:

View file

@ -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")

View file

@ -23,6 +23,7 @@ import (
plainTemplate "text/template"
"github.com/GoASTScanner/gas"
"gopkg.in/yaml.v2"
)
// ReportFormat enumrates the output format for reported issues
@ -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":
@ -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()