Skip to content

Commit 21ea159

Browse files
authored
Merge pull request #69 from arduino/per1234/non-json-output
Suppress text output when in --format json mode
2 parents 06764f5 + b3e72ed commit 21ea159

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

Diff for: check/check.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ import (
2727
"github.com/arduino/arduino-check/project"
2828
"github.com/arduino/arduino-check/result"
2929
"github.com/arduino/arduino-check/result/feedback"
30-
"github.com/arduino/arduino-check/result/outputformat"
3130
"github.com/sirupsen/logrus"
3231
)
3332

3433
// RunChecks runs all checks for the given project and outputs the results.
3534
func RunChecks(project project.Type) {
36-
fmt.Printf("Checking %s in %s\n", project.ProjectType, project.Path)
35+
feedback.Printf("Checking %s in %s\n", project.ProjectType, project.Path)
3736

3837
checkdata.Initialize(project, configuration.SchemasPath())
3938

@@ -50,23 +49,18 @@ func RunChecks(project project.Type) {
5049
}
5150

5251
// Output will be printed after all checks are finished when configured for "json" output format
53-
if configuration.OutputFormat() == outputformat.Text {
54-
fmt.Printf("Running check %s: ", checkConfiguration.ID)
55-
}
52+
feedback.Printf("Running check %s: ", checkConfiguration.ID)
53+
5654
checkResult, checkOutput := checkConfiguration.CheckFunction()
5755
reportText := result.Results.Record(project, checkConfiguration, checkResult, checkOutput)
58-
if configuration.OutputFormat() == outputformat.Text {
59-
fmt.Print(reportText)
60-
}
56+
feedback.Print(reportText)
6157
}
6258

6359
// Checks are finished for this project, so summarize its check results in the report.
6460
result.Results.AddProjectSummary(project)
6561

66-
if configuration.OutputFormat() == outputformat.Text {
67-
// Print the project check results summary.
68-
fmt.Print(result.Results.ProjectSummaryText(project))
69-
}
62+
// Print the project check results summary.
63+
feedback.Print(result.Results.ProjectSummaryText(project))
7064
}
7165

7266
// shouldRun returns whether a given check should be run for the given project under the current tool configuration.

Diff for: result/feedback/feedback.go

+14
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,23 @@ package feedback
1919
import (
2020
"fmt"
2121

22+
"github.com/arduino/arduino-check/configuration"
23+
"github.com/arduino/arduino-check/result/outputformat"
2224
"github.com/sirupsen/logrus"
2325
)
2426

27+
// Printf behaves like fmt.Printf but only prints when output format is set to `text`.
28+
func Printf(format string, v ...interface{}) {
29+
Print(fmt.Sprintf(format, v...))
30+
}
31+
32+
// Print behaves like fmt.Print but only prints when output format is set to `text`.
33+
func Print(message string) {
34+
if configuration.OutputFormat() == outputformat.Text {
35+
fmt.Printf(message)
36+
}
37+
}
38+
2539
// Errorf behaves like fmt.Printf but also logs the error.
2640
func Errorf(format string, v ...interface{}) {
2741
Error(fmt.Sprintf(format, v...))

0 commit comments

Comments
 (0)