diff --git a/go-junit-report.go b/go-junit-report.go index 309c964..117ab5e 100644 --- a/go-junit-report.go +++ b/go-junit-report.go @@ -1,11 +1,20 @@ package main import ( + "flag" "fmt" "os" ) +var noXmlHeader bool + +func init() { + flag.BoolVar(&noXmlHeader, "no-xml-header", false, "do not print xml header") +} + func main() { + flag.Parse() + // Read input report, err := Parse(os.Stdin) if err != nil { @@ -14,7 +23,7 @@ func main() { } // Write xml - err = JUnitReportXML(report, os.Stdout) + err = JUnitReportXML(report, noXmlHeader, os.Stdout) if err != nil { fmt.Printf("Error writing XML: %s\n", err) os.Exit(1) diff --git a/junit-formatter.go b/junit-formatter.go index 0b58f31..2f1f887 100644 --- a/junit-formatter.go +++ b/junit-formatter.go @@ -52,7 +52,7 @@ func NewJUnitProperty(name, value string) JUnitProperty { // JUnitReportXML writes a junit xml representation of the given report to w // in the format described at http://windyroad.org/dl/Open%20Source/JUnit.xsd -func JUnitReportXML(report *Report, w io.Writer) error { +func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error { suites := []JUnitTestSuite{} // convert Report to JUnit test suites @@ -111,7 +111,9 @@ func JUnitReportXML(report *Report, w io.Writer) error { writer := bufio.NewWriter(w) - writer.WriteString(xml.Header) + if !noXmlHeader { + writer.WriteString(xml.Header) + } writer.Write(bytes) writer.WriteByte('\n') writer.Flush()