From 0862c544b4b301b7ba30124f8447d69c8fe6f1a7 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 12 Dec 2020 00:32:46 -0800 Subject: [PATCH 1/2] Use CLI flag values for string representations of "enum" values I think this will make the output the easiest for the user to understand, and not require additional documentation beyond what is required to explain the CLI. --- configuration/checkmode/checkmode.go | 14 +++++++------- configuration/checkmode/type_string.go | 4 ++-- project/projecttype/projecttype.go | 16 ++++++++-------- project/projecttype/type_string.go | 4 ++-- result/outputformat/outputformat.go | 6 +++--- result/outputformat/type_string.go | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/configuration/checkmode/checkmode.go b/configuration/checkmode/checkmode.go index 9662a35b..03f076d5 100644 --- a/configuration/checkmode/checkmode.go +++ b/configuration/checkmode/checkmode.go @@ -32,8 +32,8 @@ const ( Strict Type = iota // strict Specification // specification Permissive // permissive - LibraryManagerSubmission // --library-manager=submit - LibraryManagerIndexed // --library-manager=update + LibraryManagerSubmission // submit + LibraryManagerIndexed // update Official // ARDUINO_CHECK_OFFICIAL Default // default ) @@ -54,11 +54,11 @@ var Types = map[Type]struct{}{ // ComplianceModeFromString parses the --compliance flag value and returns the corresponding check mode settings. func ComplianceModeFromString(complianceModeString string) (bool, bool, bool, error) { switch strings.ToLower(complianceModeString) { - case "strict": + case Strict.String(): return true, false, false, nil - case "specification": + case Specification.String(): return false, true, false, nil - case "permissive": + case Permissive.String(): return false, false, true, nil default: 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 // LibraryManagerModeFromString parses the --library-manager flag value and returns the corresponding check mode settings. func LibraryManagerModeFromString(libraryManagerModeString string) (bool, bool, error) { switch strings.ToLower(libraryManagerModeString) { - case "submit": + case LibraryManagerSubmission.String(): return true, false, nil - case "update": + case LibraryManagerIndexed.String(): return false, true, nil case "false": return false, false, nil diff --git a/configuration/checkmode/type_string.go b/configuration/checkmode/type_string.go index 0b2b775f..5905f88d 100644 --- a/configuration/checkmode/type_string.go +++ b/configuration/checkmode/type_string.go @@ -17,9 +17,9 @@ func _() { _ = x[Default-6] } -const _Type_name = "strictspecificationpermissive--library-manager=submit--library-manager=updateARDUINO_CHECK_OFFICIALdefault" +const _Type_name = "strictspecificationpermissivesubmitupdateARDUINO_CHECK_OFFICIALdefault" -var _Type_index = [...]uint8{0, 6, 19, 29, 53, 77, 99, 106} +var _Type_index = [...]uint8{0, 6, 19, 29, 35, 41, 63, 70} func (i Type) String() string { if i < 0 || i >= Type(len(_Type_index)-1) { diff --git a/project/projecttype/projecttype.go b/project/projecttype/projecttype.go index 4a2a8f9f..22e7667f 100644 --- a/project/projecttype/projecttype.go +++ b/project/projecttype/projecttype.go @@ -28,20 +28,20 @@ type Type int const ( Sketch Type = iota // sketch Library // library - Platform // boards platform - PackageIndex // Boards Manager package index - All // any project type + Platform // platform + PackageIndex // package-index + All // all Not // N/A ) // FromString parses the --project-type flag value and returns the corresponding project type. func FromString(projectTypeString string) (Type, error) { projectType, found := map[string]Type{ - "sketch": Sketch, - "library": Library, - "platform": Platform, - "package-index": PackageIndex, - "all": All, + Sketch.String(): Sketch, + Library.String(): Library, + Platform.String(): Platform, + PackageIndex.String(): PackageIndex, + All.String(): All, }[strings.ToLower(projectTypeString)] if found { diff --git a/project/projecttype/type_string.go b/project/projecttype/type_string.go index 8098ec4a..c8f7b93b 100644 --- a/project/projecttype/type_string.go +++ b/project/projecttype/type_string.go @@ -16,9 +16,9 @@ func _() { _ = x[Not-5] } -const _Type_name = "sketchlibraryboards platformBoards Manager package indexany project typeN/A" +const _Type_name = "sketchlibraryplatformpackage-indexallN/A" -var _Type_index = [...]uint8{0, 6, 13, 28, 56, 72, 75} +var _Type_index = [...]uint8{0, 6, 13, 21, 34, 37, 40} func (i Type) String() string { if i < 0 || i >= Type(len(_Type_index)-1) { diff --git a/result/outputformat/outputformat.go b/result/outputformat/outputformat.go index d02955de..746af4e8 100644 --- a/result/outputformat/outputformat.go +++ b/result/outputformat/outputformat.go @@ -27,14 +27,14 @@ type Type int const ( Text Type = iota // text - JSON // JSON + JSON // json ) // FromString parses the --format flag value and returns the corresponding output format type. func FromString(outputFormatString string) (Type, error) { formatType, found := map[string]Type{ - "text": Text, - "json": JSON, + Text.String(): Text, + JSON.String(): JSON, }[strings.ToLower(outputFormatString)] if found { diff --git a/result/outputformat/type_string.go b/result/outputformat/type_string.go index 98d3579c..1ee9b0b7 100644 --- a/result/outputformat/type_string.go +++ b/result/outputformat/type_string.go @@ -12,7 +12,7 @@ func _() { _ = x[JSON-1] } -const _Type_name = "textJSON" +const _Type_name = "textjson" var _Type_index = [...]uint8{0, 4, 8} From f3d0572fe44f60358a245cc113adc7dccf140de1 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 12 Dec 2020 00:46:28 -0800 Subject: [PATCH 2/2] Use CLI-style LM check configuration in report I think this will be the easiest for the user to understand, and not require additional documentation beyond what is required to explain the CLI. --- configuration/checkmode/checkmode.go | 11 +++++++++++ result/result.go | 14 ++++++-------- result/result_test.go | 3 +-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/configuration/checkmode/checkmode.go b/configuration/checkmode/checkmode.go index 03f076d5..defc8290 100644 --- a/configuration/checkmode/checkmode.go +++ b/configuration/checkmode/checkmode.go @@ -105,3 +105,14 @@ func Compliance(checkModes map[Type]bool) string { panic(fmt.Errorf("Unrecognized compliance configuration")) } + +// LibraryManager returns the string identifier for the Library Manager configuration mode. +func LibraryManager(checkModes map[Type]bool) string { + for key, value := range checkModes { + if value && (key == LibraryManagerSubmission || key == LibraryManagerIndexed) { + return key.String() + } + } + + return "false" +} diff --git a/result/result.go b/result/result.go index df6776ca..9b3321a6 100644 --- a/result/result.go +++ b/result/result.go @@ -56,10 +56,9 @@ type projectReportType struct { } type projectConfigurationReportType struct { - Compliance string `json:"compliance"` - LibraryManagerSubmit bool `json:"libraryManagerSubmit"` - LibraryManagerUpdate bool `json:"libraryManagerUpdate"` - Official bool `json:"official"` + Compliance string `json:"compliance"` + LibraryManager string `json:"libraryManager"` + Official bool `json:"official"` } type checkReportType struct { @@ -121,10 +120,9 @@ func (results *Type) Record(checkedProject project.Type, checkConfiguration chec Path: checkedProject.Path, ProjectType: checkedProject.ProjectType.String(), Configuration: projectConfigurationReportType{ - Compliance: checkmode.Compliance(configuration.CheckModes(checkedProject.ProjectType)), - LibraryManagerSubmit: configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerSubmission], - LibraryManagerUpdate: configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerIndexed], - Official: configuration.CheckModes(checkedProject.ProjectType)[checkmode.Official], + Compliance: checkmode.Compliance(configuration.CheckModes(checkedProject.ProjectType)), + LibraryManager: checkmode.LibraryManager(configuration.CheckModes(checkedProject.ProjectType)), + Official: configuration.CheckModes(checkedProject.ProjectType)[checkmode.Official], }, Checks: []checkReportType{}, }, diff --git a/result/result_test.go b/result/result_test.go index 3892cac4..a8bd297c 100644 --- a/result/result_test.go +++ b/result/result_test.go @@ -91,8 +91,7 @@ func TestRecord(t *testing.T) { assert.Equal(t, checkedProject.ProjectType.String(), projectReport.ProjectType) projectConfigurationReport := projectReport.Configuration assert.Equal(t, checkmode.Compliance(configuration.CheckModes(checkedProject.ProjectType)), projectConfigurationReport.Compliance) - assert.Equal(t, configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerSubmission], projectConfigurationReport.LibraryManagerSubmit) - assert.Equal(t, configuration.CheckModes(checkedProject.ProjectType)[checkmode.LibraryManagerIndexed], projectConfigurationReport.LibraryManagerUpdate) + assert.Equal(t, checkmode.LibraryManager(configuration.CheckModes(checkedProject.ProjectType)), projectConfigurationReport.LibraryManager) assert.Equal(t, configuration.CheckModes(checkedProject.ProjectType)[checkmode.Official], projectConfigurationReport.Official) assert.Equal(t, 1, len(results.Projects[0].Checks), "Passing check reports should be written to report in verbose mode") checkReport := projectReport.Checks[0]