Skip to content

Commit

Permalink
Merge pull request #69 from arduino/per1234/non-json-output
Browse files Browse the repository at this point in the history
Suppress text output when in --format json mode
  • Loading branch information
per1234 authored Nov 26, 2020
2 parents 06764f5 + b3e72ed commit 21ea159
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
18 changes: 6 additions & 12 deletions check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ import (
"github.com/arduino/arduino-check/project"
"github.com/arduino/arduino-check/result"
"github.com/arduino/arduino-check/result/feedback"
"github.com/arduino/arduino-check/result/outputformat"
"github.com/sirupsen/logrus"
)

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

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

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

// Output will be printed after all checks are finished when configured for "json" output format
if configuration.OutputFormat() == outputformat.Text {
fmt.Printf("Running check %s: ", checkConfiguration.ID)
}
feedback.Printf("Running check %s: ", checkConfiguration.ID)

checkResult, checkOutput := checkConfiguration.CheckFunction()
reportText := result.Results.Record(project, checkConfiguration, checkResult, checkOutput)
if configuration.OutputFormat() == outputformat.Text {
fmt.Print(reportText)
}
feedback.Print(reportText)
}

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

if configuration.OutputFormat() == outputformat.Text {
// Print the project check results summary.
fmt.Print(result.Results.ProjectSummaryText(project))
}
// Print the project check results summary.
feedback.Print(result.Results.ProjectSummaryText(project))
}

// shouldRun returns whether a given check should be run for the given project under the current tool configuration.
Expand Down
14 changes: 14 additions & 0 deletions result/feedback/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,23 @@ package feedback
import (
"fmt"

"github.com/arduino/arduino-check/configuration"
"github.com/arduino/arduino-check/result/outputformat"
"github.com/sirupsen/logrus"
)

// Printf behaves like fmt.Printf but only prints when output format is set to `text`.
func Printf(format string, v ...interface{}) {
Print(fmt.Sprintf(format, v...))
}

// Print behaves like fmt.Print but only prints when output format is set to `text`.
func Print(message string) {
if configuration.OutputFormat() == outputformat.Text {
fmt.Printf(message)
}
}

// Errorf behaves like fmt.Printf but also logs the error.
func Errorf(format string, v ...interface{}) {
Error(fmt.Sprintf(format, v...))
Expand Down

0 comments on commit 21ea159

Please sign in to comment.