Skip to content

Commit 09bbd6a

Browse files
committed
Use an "enum" for the output format types
1 parent 6894049 commit 09bbd6a

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

Diff for: check/check.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/arduino/arduino-check/project"
1313
"github.com/arduino/arduino-check/result"
1414
"github.com/arduino/arduino-check/result/feedback"
15+
"github.com/arduino/arduino-check/result/outputformat"
1516
"github.com/sirupsen/logrus"
1617
)
1718

@@ -34,20 +35,20 @@ func RunChecks(project project.Type) {
3435
}
3536

3637
// Output will be printed after all checks are finished when configured for "json" output format
37-
if configuration.OutputFormat() == "text" {
38+
if configuration.OutputFormat() == outputformat.Text {
3839
fmt.Printf("Running check %s: ", checkConfiguration.ID)
3940
}
4041
checkResult, checkOutput := checkConfiguration.CheckFunction()
4142
reportText := result.Results.Record(project, checkConfiguration, checkResult, checkOutput)
42-
if configuration.OutputFormat() == "text" {
43+
if configuration.OutputFormat() == outputformat.Text {
4344
fmt.Print(reportText)
4445
}
4546
}
4647

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

50-
if configuration.OutputFormat() == "text" {
51+
if configuration.OutputFormat() == outputformat.Text {
5152
// Print the project check results summary.
5253
fmt.Print(result.Results.ProjectSummaryText(project))
5354
}

Diff for: configuration/configuration.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package configuration
44
import (
55
"github.com/arduino/arduino-check/configuration/checkmode"
66
"github.com/arduino/arduino-check/project/projecttype"
7+
"github.com/arduino/arduino-check/result/outputformat"
78
"github.com/arduino/go-paths-helper"
89
"github.com/sirupsen/logrus"
910
)
@@ -25,7 +26,7 @@ func Initialize() {
2526
// customCheckModes[checkmode.Official] = false
2627
// superprojectType = projecttype.All
2728

28-
outputFormat = "json"
29+
outputFormat = outputformat.JSON
2930
//reportFilePath = paths.New("report.json")
3031

3132
logrus.SetLevel(logrus.PanicLevel)
@@ -58,10 +59,10 @@ func Recursive() bool {
5859
return recursive
5960
}
6061

61-
var outputFormat string
62+
var outputFormat outputformat.Type
6263

6364
// OutputFormat returns the tool output format configuration value.
64-
func OutputFormat() string {
65+
func OutputFormat() outputformat.Type {
6566
return outputFormat
6667
}
6768

Diff for: configuration/defaults.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ package configuration
55
import (
66
"github.com/arduino/arduino-check/configuration/checkmode"
77
"github.com/arduino/arduino-check/project/projecttype"
8+
"github.com/arduino/arduino-check/result/outputformat"
89
)
910

1011
func setDefaults() {
1112
superprojectTypeFilter = projecttype.All
1213
recursive = true
13-
outputFormat = "text"
14+
outputFormat = outputformat.Text
1415
// TODO: targetPath defaults to current path
1516
}
1617

Diff for: main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/arduino/arduino-check/project"
1010
"github.com/arduino/arduino-check/result"
1111
"github.com/arduino/arduino-check/result/feedback"
12+
"github.com/arduino/arduino-check/result/outputformat"
1213
)
1314

1415
func main() {
@@ -29,7 +30,7 @@ func main() {
2930
// All projects have been checked, so summarize their check results in the report.
3031
result.Results.AddSummary()
3132

32-
if configuration.OutputFormat() == "text" {
33+
if configuration.OutputFormat() == outputformat.Text {
3334
if len(projects) > 1 {
3435
// There are multiple projects, print the summary of check results for all projects.
3536
fmt.Print(result.Results.SummaryText())

Diff for: result/outputformat/outputformat.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Package projecttype defines the output formats
2+
package outputformat
3+
4+
// Type is the type for output formats
5+
//go:generate stringer -type=Type -linecomment
6+
type Type int
7+
8+
const (
9+
Text Type = iota // text
10+
JSON // JSON
11+
)

Diff for: result/outputformat/type_string.go

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)