@@ -26,6 +26,7 @@ import (
26
26
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
27
27
paths "github.com/arduino/go-paths-helper"
28
28
properties "github.com/arduino/go-properties-orderedmap"
29
+ "github.com/schollz/closestmatch"
29
30
"github.com/sirupsen/logrus"
30
31
semver "go.bug.st/relaxed-semver"
31
32
)
@@ -129,6 +130,22 @@ func (pm *PackageManager) FindBoardWithFQBN(fqbnIn string) (*cores.Board, error)
129
130
return board , err
130
131
}
131
132
133
+ func (pm * PackageManager ) findClosestMatchFqbn (fqbn * cores.FQBN ) string {
134
+ // Create closestmatch DB
135
+ wordsToTest := []string {}
136
+ name := fqbn .StringWithoutConfig ()
137
+ for _ , board := range pm .InstalledBoards () {
138
+ wordsToTest = append (wordsToTest , board .FQBN ())
139
+ }
140
+ // Choose a set of bag sizes, more is more accurate but slower
141
+ bagSizes := []int {2 }
142
+
143
+ // Create a closestmatch object and find the best matching name
144
+ cm := closestmatch .New (wordsToTest , bagSizes )
145
+ closestName := cm .Closest (name )
146
+ return closestName
147
+ }
148
+
132
149
// ResolveFQBN returns, in order:
133
150
//
134
151
// - the Package pointed by the fqbn
@@ -174,8 +191,10 @@ func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) (
174
191
// Find board
175
192
board := platformRelease .Boards [fqbn .BoardID ]
176
193
if board == nil {
194
+ // Try looking for the closest match; if found, suggest it
195
+ suggestion := pm .findClosestMatchFqbn (fqbn )
177
196
return targetPackage , platformRelease , nil , nil , nil ,
178
- fmt .Errorf ("board %s:%s not found" , platformRelease , fqbn .BoardID )
197
+ fmt .Errorf ("board %s not found, did you mean %s ?" , fqbn .StringWithoutConfig (), suggestion )
179
198
}
180
199
181
200
buildProperties , err := board .GetBuildProperties (fqbn .Configs )
0 commit comments