Skip to content

Commit 35115a2

Browse files
committed
Refactor project identification functions
Consolidate the redundant logging code in these functions.
1 parent 100b2dd commit 35115a2

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

project/project.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,40 +143,46 @@ func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) [
143143
// isProject determines if a path contains an Arduino project, and if so which type.
144144
func isProject(potentialProjectPath *paths.Path, projectTypeFilter projecttype.Type) (bool, projecttype.Type) {
145145
logrus.Tracef("Checking if %s is %s", potentialProjectPath, projectTypeFilter)
146+
147+
projectType := projecttype.Not
146148
if projectTypeFilter.Matches(projecttype.Sketch) && isSketch(potentialProjectPath) {
147-
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.Sketch)
148-
return true, projecttype.Sketch
149+
projectType = projecttype.Sketch
149150
} else if projectTypeFilter.Matches(projecttype.Library) && isLibrary(potentialProjectPath) {
150-
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.Library)
151-
return true, projecttype.Library
151+
projectType = projecttype.Library
152152
} else if projectTypeFilter.Matches(projecttype.Platform) && isPlatform(potentialProjectPath) {
153-
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.Platform)
154-
return true, projecttype.Platform
153+
projectType = projecttype.Platform
155154
} else if projectTypeFilter.Matches(projecttype.PackageIndex) && isPackageIndex(potentialProjectPath) {
156-
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.PackageIndex)
157-
return true, projecttype.PackageIndex
155+
projectType = projecttype.PackageIndex
156+
}
157+
158+
if projectType == projecttype.Not {
159+
return false, projectType
158160
}
159-
return false, projecttype.Not
161+
logrus.Tracef("%s is %s", potentialProjectPath, projectType)
162+
return true, projectType
160163
}
161164

162165
// isProject determines if a file is the indicator file for an Arduino project, and if so which type.
163166
func isProjectIndicatorFile(potentialProjectFilePath *paths.Path, projectTypeFilter projecttype.Type) (bool, projecttype.Type) {
164167
logrus.Tracef("Checking if %s is %s indicator file", potentialProjectFilePath, projectTypeFilter)
168+
169+
projectType := projecttype.Not
165170
if projectTypeFilter.Matches(projecttype.Sketch) && isSketchIndicatorFile(potentialProjectFilePath) {
166-
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.Sketch)
167-
return true, projecttype.Sketch
171+
projectType = projecttype.Sketch
168172
} else if projectTypeFilter.Matches(projecttype.Library) && isLibraryIndicatorFile(potentialProjectFilePath) {
169-
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.Library)
170-
return true, projecttype.Library
173+
projectType = projecttype.Library
171174
} else if projectTypeFilter.Matches(projecttype.Platform) && isPlatformIndicatorFile(potentialProjectFilePath) {
172-
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.Platform)
173-
return true, projecttype.Platform
175+
projectType = projecttype.Platform
174176
} else if projectTypeFilter.Matches(projecttype.PackageIndex) && isPackageIndexIndicatorFile(potentialProjectFilePath) {
175-
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.PackageIndex)
176-
return true, projecttype.PackageIndex
177+
projectType = projecttype.PackageIndex
178+
}
179+
180+
if projectType == projecttype.Not {
181+
logrus.Tracef("%s is not indicator file", potentialProjectFilePath)
182+
return false, projectType
177183
}
178-
logrus.Tracef("%s is not indicator file", potentialProjectFilePath)
179-
return false, projecttype.Not
184+
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projectType)
185+
return true, projectType
180186
}
181187

182188
// isSketch determines whether a path is an Arduino sketch.

0 commit comments

Comments
 (0)