Skip to content

Allow setting official check mode configuration via environment variable #30

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
Nov 23, 2020
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@

- Sketches
- Libraries

## 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.
9 changes: 7 additions & 2 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package configuration
import (
"fmt"
"os"
"strconv"
"strings"

"github.com/arduino/arduino-check/configuration/checkmode"
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 11 additions & 0 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}