@@ -26,6 +26,7 @@ import (
2626 "github.com/arduino/arduino-cli/arduino/cores/packageindex"
2727 paths "github.com/arduino/go-paths-helper"
2828 properties "github.com/arduino/go-properties-orderedmap"
29+ "github.com/schollz/closestmatch"
2930 "github.com/sirupsen/logrus"
3031 semver "go.bug.st/relaxed-semver"
3132)
@@ -129,6 +130,22 @@ func (pm *PackageManager) FindBoardWithFQBN(fqbnIn string) (*cores.Board, error)
129130 return board, err
130131}
131132
133+ func (pm *PackageManager) findClosestMatchFqbn(fqbn *cores.FQBN) string {
134+ // Create closestmatch DB
135+ wordsToTest := []string{}
136+ name := fqbn.Package + ":" + fqbn.PlatformArch + ":" + fqbn.BoardID
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+
132149// ResolveFQBN returns, in order:
133150//
134151// - the Package pointed by the fqbn
@@ -174,8 +191,10 @@ func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) (
174191 // Find board
175192 board := platformRelease.Boards[fqbn.BoardID]
176193 if board == nil {
194+ // Try looking for the closest match; if found, suggest it
195+ suggestion := pm.findClosestMatchFqbn(fqbn)
177196 return targetPackage, platformRelease, nil, nil, nil,
178- fmt.Errorf("board %s:%s not found", platformRelease, fqbn.BoardID)
197+ fmt.Errorf("board %s:%s not found, did you mean %s? ", platformRelease, fqbn.BoardID, suggestion )
179198 }
180199
181200 buildProperties, err := board.GetBuildProperties(fqbn.Configs)
0 commit comments