Skip to content

Unify CLI flag strings with strings shown in output #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions configuration/checkmode/checkmode.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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"
}
4 changes: 2 additions & 2 deletions configuration/checkmode/type_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions project/projecttype/projecttype.go
Original file line number Diff line number Diff line change
@@ -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 {
4 changes: 2 additions & 2 deletions project/projecttype/type_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions result/outputformat/outputformat.go
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 1 addition & 1 deletion result/outputformat/type_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions result/result.go
Original file line number Diff line number Diff line change
@@ -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{},
},
3 changes: 1 addition & 2 deletions result/result_test.go
Original file line number Diff line number Diff line change
@@ -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]