Skip to content

Commit 24cae53

Browse files
committed
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.
1 parent 16e6e94 commit 24cae53

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
## Usage
1010

1111
After installing `arduino-check`, run the command `arduino-check --help` for usage documentation.
12+
13+
Set the `ARDUINO_CHECK_OFFICIAL` environment variable to "true" to run the checks that only apply to official Arduino
14+
projects.

Diff for: configuration/configuration.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package configuration
1919
import (
2020
"fmt"
2121
"os"
22+
"strconv"
2223
"strings"
2324

2425
"github.com/arduino/arduino-check/configuration/checkmode"
@@ -83,8 +84,12 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
8384
return fmt.Errorf("PROJECT_PATH argument %v does not exist", projectPaths[0])
8485
}
8586

86-
// TODO: set via environment variable
87-
// customCheckModes[checkmode.Official] = false
87+
if officialModeString, ok := os.LookupEnv("ARDUINO_CHECK_OFFICIAL"); ok {
88+
customCheckModes[checkmode.Official], err = strconv.ParseBool(officialModeString)
89+
if err != nil {
90+
return fmt.Errorf("ARDUINO_CHECK_OFFICIAL environment variable value %s not valid", officialModeString)
91+
}
92+
}
8893

8994
logrus.WithFields(logrus.Fields{
9095
"output format": OutputFormat(),

Diff for: configuration/configuration_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,15 @@ func TestInitialize(t *testing.T) {
133133
assert.Equal(t, paths.New(projectPaths[0]), TargetPath())
134134

135135
assert.Error(t, Initialize(flags, []string{"/nonexistent"}))
136+
137+
os.Setenv("ARDUINO_CHECK_OFFICIAL", "true")
138+
assert.Nil(t, Initialize(test.ConfigurationFlags(), projectPaths))
139+
assert.True(t, customCheckModes[checkmode.Official])
140+
141+
os.Setenv("ARDUINO_CHECK_OFFICIAL", "false")
142+
assert.Nil(t, Initialize(test.ConfigurationFlags(), projectPaths))
143+
assert.False(t, customCheckModes[checkmode.Official])
144+
145+
os.Setenv("ARDUINO_CHECK_OFFICIAL", "invalid value")
146+
assert.Error(t, Initialize(test.ConfigurationFlags(), projectPaths))
136147
}

0 commit comments

Comments
 (0)