Skip to content

Commit d7bf253

Browse files
committed
Default PROJECT_PATH argument to current working directory
This permits checks to be run with the default settings simply by executing arduino-check from the project folder.
1 parent fa4abca commit d7bf253

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

cli/cli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Root() *cobra.Command {
2727
Short: "Linter for Arduino projects.",
2828
Long: "arduino-check checks specification compliance and for other common problems with Arduino projects",
2929
DisableFlagsInUseLine: true,
30-
Use: "arduino-check [FLAG]... PROJECT_PATH...\n\nRun checks on PROJECT_PATH.",
30+
Use: "arduino-check [FLAG]... [PROJECT_PATH]...\n\nRun checks on PROJECT_PATH or current path if no PROJECT_PATH argument provided.",
3131
Run: command.ArduinoCheck,
3232
}
3333

configuration/configuration.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,25 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
7474
reportFilePathString, _ := flags.GetString("report-file")
7575
reportFilePath = paths.New(reportFilePathString)
7676

77-
for _, projectPath := range projectPaths {
78-
targetPath := paths.New(projectPath)
79-
targetPathExists, err := targetPath.ExistCheck()
77+
if len(projectPaths) == 0 {
78+
// Default to using current working directory.
79+
workingDirectoryPath, err := os.Getwd()
8080
if err != nil {
81-
return fmt.Errorf("Problem processing PROJECT_PATH argument value %v: %v", targetPath, err)
81+
return fmt.Errorf("Error when setting default PROJECT_PATH argument: %s", err)
8282
}
83-
if !targetPathExists {
84-
return fmt.Errorf("PROJECT_PATH argument %v does not exist", targetPath)
83+
targetPaths.Add(paths.New(workingDirectoryPath))
84+
} else {
85+
for _, projectPath := range projectPaths {
86+
targetPath := paths.New(projectPath)
87+
targetPathExists, err := targetPath.ExistCheck()
88+
if err != nil {
89+
return fmt.Errorf("Problem processing PROJECT_PATH argument value %v: %v", targetPath, err)
90+
}
91+
if !targetPathExists {
92+
return fmt.Errorf("PROJECT_PATH argument %v does not exist", targetPath)
93+
}
94+
targetPaths.AddIfMissing(targetPath)
8595
}
86-
targetPaths.AddIfMissing(targetPath)
8796
}
8897

8998
if officialModeString, ok := os.LookupEnv("ARDUINO_CHECK_OFFICIAL"); ok {

configuration/configuration_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ func TestInitializeReportFile(t *testing.T) {
159159
}
160160

161161
func TestInitializeProjectPath(t *testing.T) {
162+
targetPaths = nil
163+
assert.Nil(t, Initialize(test.ConfigurationFlags(), []string{}))
164+
workingDirectoryPath, err := os.Getwd()
165+
require.Nil(t, err)
166+
assert.Equal(t, paths.NewPathList(workingDirectoryPath), TargetPaths(), "Default PROJECT_PATH to current working directory")
167+
162168
targetPaths = nil
163169
assert.Nil(t, Initialize(test.ConfigurationFlags(), projectPaths))
164170
assert.Equal(t, paths.NewPathList(projectPaths[0]), TargetPaths())

0 commit comments

Comments
 (0)