Skip to content

Commit 336fc8f

Browse files
authored
Merge pull request #30 from arduino/per1234/official-mode
Allow setting official check mode configuration via environment variable
2 parents 27150cc + 24cae53 commit 336fc8f

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55

66
- Sketches
77
- Libraries
8+
9+
## Usage
10+
11+
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)