Skip to content

Commit cdc6ce0

Browse files
committed
Add project type matcher method
1 parent 2f07059 commit cdc6ce0

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

project/project.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,16 @@ 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, projectType projecttype.Type) (bool, projecttype.Type) {
145145
logrus.Tracef("Checking if %s is %s", potentialProjectPath, projectType)
146-
if (projectType == projecttype.All || projectType == projecttype.Sketch) && isSketch(potentialProjectPath) {
146+
if projectType.Matches(projecttype.Sketch) && isSketch(potentialProjectPath) {
147147
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.Sketch)
148148
return true, projecttype.Sketch
149-
} else if (projectType == projecttype.All || projectType == projecttype.Library) && isLibrary(potentialProjectPath) {
149+
} else if projectType.Matches(projecttype.Library) && isLibrary(potentialProjectPath) {
150150
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.Library)
151151
return true, projecttype.Library
152-
} else if (projectType == projecttype.All || projectType == projecttype.Platform) && isPlatform(potentialProjectPath) {
152+
} else if projectType.Matches(projecttype.Platform) && isPlatform(potentialProjectPath) {
153153
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.Platform)
154154
return true, projecttype.Platform
155-
} else if (projectType == projecttype.All || projectType == projecttype.PackageIndex) && isPackageIndex(potentialProjectPath) {
155+
} else if projectType.Matches(projecttype.PackageIndex) && isPackageIndex(potentialProjectPath) {
156156
logrus.Tracef("%s is %s", potentialProjectPath, projecttype.PackageIndex)
157157
return true, projecttype.PackageIndex
158158
}
@@ -162,16 +162,16 @@ func isProject(potentialProjectPath *paths.Path, projectType projecttype.Type) (
162162
// isProject determines if a file is the indicator file for an Arduino project, and if so which type.
163163
func isProjectIndicatorFile(potentialProjectFilePath *paths.Path, projectType projecttype.Type) (bool, projecttype.Type) {
164164
logrus.Tracef("Checking if %s is %s indicator file", potentialProjectFilePath, projectType)
165-
if (projectType == projecttype.All || projectType == projecttype.Sketch) && isSketchIndicatorFile(potentialProjectFilePath) {
165+
if projectType.Matches(projecttype.Sketch) && isSketchIndicatorFile(potentialProjectFilePath) {
166166
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.Sketch)
167167
return true, projecttype.Sketch
168-
} else if (projectType == projecttype.All || projectType == projecttype.Library) && isLibraryIndicatorFile(potentialProjectFilePath) {
168+
} else if projectType.Matches(projecttype.Library) && isLibraryIndicatorFile(potentialProjectFilePath) {
169169
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.Library)
170170
return true, projecttype.Library
171-
} else if (projectType == projecttype.All || projectType == projecttype.Platform) && isPlatformIndicatorFile(potentialProjectFilePath) {
171+
} else if projectType.Matches(projecttype.Platform) && isPlatformIndicatorFile(potentialProjectFilePath) {
172172
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.Platform)
173173
return true, projecttype.Platform
174-
} else if (projectType == projecttype.All || projectType == projecttype.PackageIndex) && isPackageIndexIndicatorFile(potentialProjectFilePath) {
174+
} else if projectType.Matches(projecttype.PackageIndex) && isPackageIndexIndicatorFile(potentialProjectFilePath) {
175175
logrus.Tracef("%s is %s indicator file", potentialProjectFilePath, projecttype.PackageIndex)
176176
return true, projecttype.PackageIndex
177177
}

project/projecttype/projecttype.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ const (
1313
All // any project type
1414
Not // N/A
1515
)
16+
17+
// Matches returns whether the receiver project type matches the argument project type
18+
func (projectTypeA Type) Matches(projectTypeB Type) bool {
19+
if projectTypeA == Not && projectTypeB == Not {
20+
return true
21+
} else if projectTypeA == Not || projectTypeB == Not {
22+
return false
23+
}
24+
return (projectTypeA == All || projectTypeB == All || projectTypeA == projectTypeB)
25+
}

0 commit comments

Comments
 (0)