Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

‎check/check.go‎

Lines changed: 4 additions & 3 deletions
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
}

‎configuration/configuration.go‎

Lines changed: 4 additions & 3 deletions
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

‎configuration/defaults.go‎

Lines changed: 2 additions & 1 deletion
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

‎main.go‎

Lines changed: 2 additions & 1 deletion
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())

‎result/outputformat/outputformat.go‎

Lines changed: 11 additions & 0 deletions
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+
)

‎result/outputformat/type_string.go‎

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /