Skip to content

Commit 8e5f33a

Browse files
committed
Refactor subproject discovery code
Subproject discovery must be done under any circumstances. Previously, there was duplicate code to do this for both file project paths and folder project paths, resulting in the code being more difficult to maintain. In order to accomodate this change, the error message in the event of no projects being discovered was reworded to be applicable to either project path type.
1 parent 9ef0caa commit 8e5f33a

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

Diff for: internal/project/project.go

+17-23
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func FindProjects() ([]Type, error) {
5353

5454
// findProjects handles the recursion for FindProjects().
5555
func findProjects(targetPath *paths.Path) ([]Type, error) {
56-
var foundProjects []Type
56+
var foundParentProjects []Type
5757

5858
// If targetPath is a file, targetPath itself is the project, so it's only necessary to determine/verify the type.
5959
if targetPath.IsNotDir() {
@@ -82,39 +82,33 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
8282
ProjectType: projectType,
8383
SuperprojectType: projectType,
8484
}
85-
foundProjects = append(foundProjects, foundProject)
86-
87-
foundProjects = append(foundProjects, findSubprojects(foundProject, projectType)...)
88-
89-
return foundProjects, nil
85+
foundParentProjects = append(foundParentProjects, foundProject)
9086
}
91-
92-
return nil, fmt.Errorf("Specified path %s is not an Arduino project", targetPath)
93-
}
94-
95-
var foundParentProjects []Type
96-
if configuration.SuperprojectTypeFilter() == projecttype.All || configuration.Recursive() {
97-
// Project discovery and/or type detection is required.
98-
foundParentProjects = findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())
9987
} else {
100-
// Project was explicitly defined by user.
101-
foundParentProjects = append(foundParentProjects,
102-
Type{
103-
Path: targetPath,
104-
ProjectType: configuration.SuperprojectTypeFilter(),
105-
SuperprojectType: configuration.SuperprojectTypeFilter(),
106-
},
107-
)
88+
if configuration.SuperprojectTypeFilter() == projecttype.All || configuration.Recursive() {
89+
// Project discovery and/or type detection is required.
90+
foundParentProjects = findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())
91+
} else {
92+
// Project was explicitly defined by user.
93+
foundParentProjects = append(foundParentProjects,
94+
Type{
95+
Path: targetPath,
96+
ProjectType: configuration.SuperprojectTypeFilter(),
97+
SuperprojectType: configuration.SuperprojectTypeFilter(),
98+
},
99+
)
100+
}
108101
}
109102

110103
// Discover subprojects of all found projects.
104+
var foundProjects []Type
111105
for _, foundParentProject := range foundParentProjects {
112106
foundProjects = append(foundProjects, foundParentProject)
113107
foundProjects = append(foundProjects, findSubprojects(foundParentProject, foundParentProject.ProjectType)...)
114108
}
115109

116110
if foundProjects == nil {
117-
return nil, fmt.Errorf("No projects found under %s", targetPath)
111+
return nil, fmt.Errorf("No projects found with project path %s", targetPath)
118112
}
119113

120114
return foundProjects, nil

0 commit comments

Comments
 (0)