Skip to content

Commit f2ae0bc

Browse files
committed
reporter: add quiet mode to suppress log output
1 parent 652fcf1 commit f2ae0bc

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

cmd/go-ctrf-json-reporter/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ var buildFailed bool
1313
func main() {
1414
var outputFile string
1515
var verbose bool
16+
var quiet bool
1617
flag.BoolVar(&verbose, "verbose", false, "Enable verbose output")
1718
flag.BoolVar(&verbose, "v", false, "Enable verbose output (shorthand)")
19+
flag.BoolVar(&quiet, "quiet", false, "Disable all log output")
20+
flag.BoolVar(&quiet, "q", false, "Disable all log output (shorthand)")
1821
flag.StringVar(&outputFile, "output", "ctrf-report.json", "The output file for the test results")
1922
flag.StringVar(&outputFile, "o", "ctrf-report.json", "The output file for the test results (shorthand)")
2023

@@ -59,19 +62,25 @@ func main() {
5962
}
6063
}
6164

62-
report, err := reporter.ParseTestResults(os.Stdin, verbose, env)
65+
effectiveVerbose := verbose && !quiet
66+
67+
report, err := reporter.ParseTestResults(os.Stdin, effectiveVerbose, env)
6368
if err != nil {
64-
_, _ = fmt.Fprintf(os.Stderr, "Error parsing test results: %v\n", err)
69+
if !quiet {
70+
_, _ = fmt.Fprintf(os.Stderr, "Error parsing test results: %v\n", err)
71+
}
6572
os.Exit(1)
6673
}
6774

6875
err = reporter.WriteReportToFile(outputFile, report)
6976
if err != nil {
70-
_, _ = fmt.Fprintf(os.Stderr, "Error writing the report to file: %v\n", err)
77+
if !quiet {
78+
_, _ = fmt.Fprintf(os.Stderr, "Error writing the report to file: %v\n", err)
79+
}
7180
os.Exit(1)
7281
}
7382

74-
if !verbose {
83+
if !verbose && !quiet {
7584
buildOutput := reporter.GetBuildOutput()
7685
fmt.Println(buildOutput)
7786
}

0 commit comments

Comments
 (0)