Skip to content

Commit 3d8592b

Browse files
authored
Merge pull request #104 from arduino/per1234/output-mirror-cli
Unify CLI flag strings with strings shown in output
2 parents b67f86c + f3d0572 commit 3d8592b

File tree

8 files changed

+41
-33
lines changed

8 files changed

+41
-33
lines changed

configuration/checkmode/checkmode.go

+18-7
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const (
3232
Strict Type = iota // strict
3333
Specification // specification
3434
Permissive // permissive
35-
LibraryManagerSubmission // --library-manager=submit
36-
LibraryManagerIndexed // --library-manager=update
35+
LibraryManagerSubmission // submit
36+
LibraryManagerIndexed // update
3737
Official // ARDUINO_CHECK_OFFICIAL
3838
Default // default
3939
)
@@ -54,11 +54,11 @@ var Types = map[Type]struct{}{
5454
// ComplianceModeFromString parses the --compliance flag value and returns the corresponding check mode settings.
5555
func ComplianceModeFromString(complianceModeString string) (bool, bool, bool, error) {
5656
switch strings.ToLower(complianceModeString) {
57-
case "strict":
57+
case Strict.String():
5858
return true, false, false, nil
59-
case "specification":
59+
case Specification.String():
6060
return false, true, false, nil
61-
case "permissive":
61+
case Permissive.String():
6262
return false, false, true, nil
6363
default:
6464
return false, false, false, fmt.Errorf("No matching compliance mode for string %s", complianceModeString)
@@ -68,9 +68,9 @@ func ComplianceModeFromString(complianceModeString string) (bool, bool, bool, er
6868
// LibraryManagerModeFromString parses the --library-manager flag value and returns the corresponding check mode settings.
6969
func LibraryManagerModeFromString(libraryManagerModeString string) (bool, bool, error) {
7070
switch strings.ToLower(libraryManagerModeString) {
71-
case "submit":
71+
case LibraryManagerSubmission.String():
7272
return true, false, nil
73-
case "update":
73+
case LibraryManagerIndexed.String():
7474
return false, true, nil
7575
case "false":
7676
return false, false, nil
@@ -105,3 +105,14 @@ func Compliance(checkModes map[Type]bool) string {
105105

106106
panic(fmt.Errorf("Unrecognized compliance configuration"))
107107
}
108+
109+
// LibraryManager returns the string identifier for the Library Manager configuration mode.
110+
func LibraryManager(checkModes map[Type]bool) string {
111+
for key, value := range checkModes {
112+
if value && (key == LibraryManagerSubmission || key == LibraryManagerIndexed) {
113+
return key.String()
114+
}
115+
}
116+
117+
return "false"
118+
}

configuration/checkmode/type_string.go

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

project/projecttype/projecttype.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ type Type int
2828
const (
2929
Sketch Type = iota // sketch
3030
Library // library
31-
Platform // boards platform
32-
PackageIndex // Boards Manager package index
33-
All // any project type
31+
Platform // platform
32+
PackageIndex // package-index
33+
All // all
3434
Not // N/A
3535
)
3636

3737
// FromString parses the --project-type flag value and returns the corresponding project type.
3838
func FromString(projectTypeString string) (Type, error) {
3939
projectType, found := map[string]Type{
40-
"sketch": Sketch,
41-
"library": Library,
42-
"platform": Platform,
43-
"package-index": PackageIndex,
44-
"all": All,
40+
Sketch.String(): Sketch,
41+
Library.String(): Library,
42+
Platform.String(): Platform,
43+
PackageIndex.String(): PackageIndex,
44+
All.String(): All,
4545
}[strings.ToLower(projectTypeString)]
4646

4747
if found {

project/projecttype/type_string.go

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

result/outputformat/outputformat.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ type Type int
2727

2828
const (
2929
Text Type = iota // text
30-
JSON // JSON
30+
JSON // json
3131
)
3232

3333
// FromString parses the --format flag value and returns the corresponding output format type.
3434
func FromString(outputFormatString string) (Type, error) {
3535
formatType, found := map[string]Type{
36-
"text": Text,
37-
"json": JSON,
36+
Text.String(): Text,
37+
JSON.String(): JSON,
3838
}[strings.ToLower(outputFormatString)]
3939

4040
if found {

result/outputformat/type_string.go

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

result/result.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ type projectReportType struct {
5656
}
5757

5858
type projectConfigurationReportType struct {
59-
Compliance string `json:"compliance"`
60-
LibraryManagerSubmit bool `json:"libraryManagerSubmit"`
61-
LibraryManagerUpdate bool `json:"libraryManagerUpdate"`
62-
Official bool `json:"official"`
59+
Compliance string `json:"compliance"`
60+
LibraryManager string `json:"libraryManager"`
61+
Official bool `json:"official"`
6362
}
6463

6564
type checkReportType struct {
@@ -121,10 +120,9 @@ func (results *Type) Record(checkedProject project.Type, checkConfiguration chec
121120
Path: checkedProject.Path,
122121
ProjectType: checkedProject.ProjectType.String(),
123122
Configuration: projectConfigurationReportType{
124-
Compliance: checkmode.Compliance(configuration.CheckModes(checkedProject.ProjectType)),
125-
LibraryManagerSubmit: configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerSubmission],
126-
LibraryManagerUpdate: configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerIndexed],
127-
Official: configuration.CheckModes(checkedProject.ProjectType)[checkmode.Official],
123+
Compliance: checkmode.Compliance(configuration.CheckModes(checkedProject.ProjectType)),
124+
LibraryManager: checkmode.LibraryManager(configuration.CheckModes(checkedProject.ProjectType)),
125+
Official: configuration.CheckModes(checkedProject.ProjectType)[checkmode.Official],
128126
},
129127
Checks: []checkReportType{},
130128
},

result/result_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ func TestRecord(t *testing.T) {
9191
assert.Equal(t, checkedProject.ProjectType.String(), projectReport.ProjectType)
9292
projectConfigurationReport := projectReport.Configuration
9393
assert.Equal(t, checkmode.Compliance(configuration.CheckModes(checkedProject.ProjectType)), projectConfigurationReport.Compliance)
94-
assert.Equal(t, configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerSubmission], projectConfigurationReport.LibraryManagerSubmit)
95-
assert.Equal(t, configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerIndexed], projectConfigurationReport.LibraryManagerUpdate)
94+
assert.Equal(t, checkmode.LibraryManager(configuration.CheckModes(checkedProject.ProjectType)), projectConfigurationReport.LibraryManager)
9695
assert.Equal(t, configuration.CheckModes(checkedProject.ProjectType)[checkmode.Official], projectConfigurationReport.Official)
9796
assert.Equal(t, 1, len(results.Projects[0].Checks), "Passing check reports should be written to report in verbose mode")
9897
checkReport := projectReport.Checks[0]

0 commit comments

Comments
 (0)