Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for YAML output format #177

Merged
merged 2 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add YAML output format
  • Loading branch information
Cosmin Cojocar committed Feb 21, 2018
commit fa17ed1a8fc43e22135f659969803ab5f66a5071
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 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