Skip to content

Commit 7f31e34

Browse files
committed
Support multiple PROJECT_PATH arguments
1 parent 0101aa0 commit 7f31e34

File tree

5 files changed

+35
-24
lines changed

5 files changed

+35
-24
lines changed

Diff for: 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.",
3131
Run: command.ArduinoCheck,
3232
}
3333

Diff for: configuration/configuration.go

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

77-
// TODO support multiple paths
78-
targetPath = paths.New(projectPaths[0])
79-
targetPathExists, err := targetPath.ExistCheck()
80-
if err != nil {
81-
return fmt.Errorf("Problem processing PROJECT_PATH argument value %v: %v", projectPaths[0], err)
82-
}
83-
if !targetPathExists {
84-
return fmt.Errorf("PROJECT_PATH argument %v does not exist", projectPaths[0])
77+
for _, projectPath := range projectPaths {
78+
targetPath := paths.New(projectPath)
79+
targetPathExists, err := targetPath.ExistCheck()
80+
if err != nil {
81+
return fmt.Errorf("Problem processing PROJECT_PATH argument value %v: %v", targetPath, err)
82+
}
83+
if !targetPathExists {
84+
return fmt.Errorf("PROJECT_PATH argument %v does not exist", targetPath)
85+
}
86+
targetPaths.AddIfMissing(targetPath)
8587
}
8688

8789
if officialModeString, ok := os.LookupEnv("ARDUINO_CHECK_OFFICIAL"); ok {
@@ -101,7 +103,7 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
101103
"superproject type filter": SuperprojectTypeFilter(),
102104
"recursive": Recursive(),
103105
"report file": ReportFilePath(),
104-
"projects path": TargetPath(),
106+
"projects path": TargetPaths(),
105107
}).Debug("Configuration initialized")
106108

107109
return nil
@@ -154,11 +156,11 @@ func ReportFilePath() *paths.Path {
154156
return reportFilePath
155157
}
156158

157-
var targetPath *paths.Path
159+
var targetPaths paths.PathList
158160

159-
// TargetPath returns the projects search path.
160-
func TargetPath() *paths.Path {
161-
return targetPath
161+
// TargetPaths returns the projects search paths.
162+
func TargetPaths() paths.PathList {
163+
return targetPaths
162164
}
163165

164166
// SchemasPath returns the path to the folder containing the JSON schemas.

Diff for: configuration/configuration_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestInitialize(t *testing.T) {
130130
assert.Equal(t, reportFilePath, ReportFilePath())
131131

132132
assert.Nil(t, Initialize(flags, projectPaths))
133-
assert.Equal(t, paths.New(projectPaths[0]), TargetPath())
133+
assert.Equal(t, paths.NewPathList(projectPaths[0]), TargetPaths())
134134

135135
assert.Error(t, Initialize(flags, []string{"/nonexistent"}))
136136

Diff for: project/project.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,26 @@ type Type struct {
3939
// FindProjects searches the target path configured by the user for projects of the type configured by the user as well as the subprojects of those project.
4040
// It returns a slice containing the definitions of each found project.
4141
func FindProjects() ([]Type, error) {
42-
targetPath := configuration.TargetPath()
43-
superprojectTypeFilter := configuration.SuperprojectTypeFilter()
44-
recursive := configuration.Recursive()
42+
var foundProjects []Type
43+
44+
for _, targetPath := range configuration.TargetPaths() {
45+
foundProjectsForTargetPath, err := findProjects(targetPath)
46+
if err != nil {
47+
return nil, err
48+
}
49+
foundProjects = append(foundProjects, foundProjectsForTargetPath...)
50+
}
51+
return foundProjects, nil
52+
}
4553

54+
func findProjects(targetPath *paths.Path) ([]Type, error) {
4655
var foundProjects []Type
4756

4857
// If targetPath is a file, targetPath itself is the project, so it's only necessary to determine/verify the type.
4958
if targetPath.IsNotDir() {
5059
logrus.Debug("Projects path is file")
5160
// The filename provides additional information about the project type. So rather than using isProject(), which doesn't make use this information, use a specialized function that does.
52-
isProject, projectType := isProjectIndicatorFile(targetPath, superprojectTypeFilter)
61+
isProject, projectType := isProjectIndicatorFile(targetPath, configuration.SuperprojectTypeFilter())
5362
if isProject {
5463
foundProject := Type{
5564
Path: targetPath.Parent(),
@@ -66,7 +75,7 @@ func FindProjects() ([]Type, error) {
6675
return nil, fmt.Errorf("specified path %s is not an Arduino project", targetPath)
6776
}
6877

69-
foundProjects = append(foundProjects, findProjectsUnderPath(targetPath, superprojectTypeFilter, recursive)...)
78+
foundProjects = append(foundProjects, findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())...)
7079

7180
if foundProjects == nil {
7281
return nil, fmt.Errorf("no projects found under %s", targetPath)

Diff for: result/result.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ type Type struct {
4444
}
4545

4646
type toolConfigurationReportType struct {
47-
Paths []*paths.Path `json:"paths"`
48-
ProjectType string `json:"projectType"`
49-
Recursive bool `json:"recursive"`
47+
Paths paths.PathList `json:"paths"`
48+
ProjectType string `json:"projectType"`
49+
Recursive bool `json:"recursive"`
5050
}
5151

5252
type projectReportType struct {
@@ -84,7 +84,7 @@ type summaryReportType struct {
8484
// Initialize adds the tool configuration data to the results data.
8585
func (results *Type) Initialize() {
8686
results.Configuration = toolConfigurationReportType{
87-
Paths: []*paths.Path{configuration.TargetPath()},
87+
Paths: configuration.TargetPaths(),
8888
ProjectType: configuration.SuperprojectTypeFilter().String(),
8989
Recursive: configuration.Recursive(),
9090
}

0 commit comments

Comments
 (0)