diff --git a/go-junit-report.go b/go-junit-report.go index 43ff964..ed801c2 100644 --- a/go-junit-report.go +++ b/go-junit-report.go @@ -10,19 +10,12 @@ import ( ) var ( - noXMLHeader bool - packageName string - goVersionFlag string - setExitCode bool + noXMLHeader = flag.Bool("no-xml-header", false, "do not print xml header") + packageName = flag.String("package-name", "", "specify a package name (compiled test have no package name in output)") + goVersionFlag = flag.String("go-version", "", "specify the value to use for the go.version property in the generated XML") + setExitCode = flag.Bool("set-exit-code", false, "set exit code to 1 if tests failed") ) -func init() { - flag.BoolVar(&noXMLHeader, "no-xml-header", false, "do not print xml header") - flag.StringVar(&packageName, "package-name", "", "specify a package name (compiled test have no package name in output)") - flag.StringVar(&goVersionFlag, "go-version", "", "specify the value to use for the go.version property in the generated XML") - flag.BoolVar(&setExitCode, "set-exit-code", false, "set exit code to 1 if tests failed") -} - func main() { flag.Parse() @@ -32,20 +25,20 @@ func main() { } // Read input - report, err := parser.Parse(os.Stdin, packageName) + report, err := parser.Parse(os.Stdin, *packageName) if err != nil { fmt.Printf("Error reading input: %s\n", err) os.Exit(1) } // Write xml - err = formatter.JUnitReportXML(report, noXMLHeader, goVersionFlag, os.Stdout) + err = formatter.JUnitReportXML(report, *noXMLHeader, *goVersionFlag, os.Stdout) if err != nil { fmt.Printf("Error writing XML: %s\n", err) os.Exit(1) } - if setExitCode && report.Failures() > 0 { + if *setExitCode && report.Failures() > 0 { os.Exit(1) } }