From 16e6e94c99abfb9654fbc568cd3e820158011475 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 23 Nov 2020 00:28:03 -0800 Subject: [PATCH 1/2] Add usage instructions --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d8375e3a..136d3752 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,7 @@ - Sketches - Libraries + +## Usage + +After installing `arduino-check`, run the command `arduino-check --help` for usage documentation. From 24cae538fb072bb517c9ceb39699940b5f397486 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 23 Nov 2020 00:18:28 -0800 Subject: [PATCH 2/2] Allow setting official check mode configuration via environment variable Since the official mode should only be used when checking official Arduino projects, I thought it was not a good idea to add a flag for this setting, since it could cause confusion to the those using the tool to check 3rd party projects, who have no use for this setting. --- README.md | 3 +++ configuration/configuration.go | 9 +++++++-- configuration/configuration_test.go | 11 +++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 136d3752..faae3ed8 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,6 @@ ## Usage After installing `arduino-check`, run the command `arduino-check --help` for usage documentation. + +Set the `ARDUINO_CHECK_OFFICIAL` environment variable to "true" to run the checks that only apply to official Arduino +projects. diff --git a/configuration/configuration.go b/configuration/configuration.go index 2646ed3d..19374152 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -19,6 +19,7 @@ package configuration import ( "fmt" "os" + "strconv" "strings" "github.com/arduino/arduino-check/configuration/checkmode" @@ -83,8 +84,12 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error { return fmt.Errorf("PROJECT_PATH argument %v does not exist", projectPaths[0]) } - // TODO: set via environment variable - // customCheckModes[checkmode.Official] = false + if officialModeString, ok := os.LookupEnv("ARDUINO_CHECK_OFFICIAL"); ok { + customCheckModes[checkmode.Official], err = strconv.ParseBool(officialModeString) + if err != nil { + return fmt.Errorf("ARDUINO_CHECK_OFFICIAL environment variable value %s not valid", officialModeString) + } + } logrus.WithFields(logrus.Fields{ "output format": OutputFormat(), diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index 8f8d1624..d0eb8d33 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -133,4 +133,15 @@ func TestInitialize(t *testing.T) { assert.Equal(t, paths.New(projectPaths[0]), TargetPath()) assert.Error(t, Initialize(flags, []string{"/nonexistent"})) + + os.Setenv("ARDUINO_CHECK_OFFICIAL", "true") + assert.Nil(t, Initialize(test.ConfigurationFlags(), projectPaths)) + assert.True(t, customCheckModes[checkmode.Official]) + + os.Setenv("ARDUINO_CHECK_OFFICIAL", "false") + assert.Nil(t, Initialize(test.ConfigurationFlags(), projectPaths)) + assert.False(t, customCheckModes[checkmode.Official]) + + os.Setenv("ARDUINO_CHECK_OFFICIAL", "invalid value") + assert.Error(t, Initialize(test.ConfigurationFlags(), projectPaths)) }