Skip to content

Commit a1ca032

Browse files
committed
Remove fuzzy logic from board listall command
1 parent 93a727b commit a1ca032

File tree

2 files changed

+20
-39
lines changed

2 files changed

+20
-39
lines changed

commands/board/listall.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"errors"
2121
"strings"
2222

23+
"github.com/arduino/arduino-cli/arduino/utils"
2324
"github.com/arduino/arduino-cli/commands"
2425
rpc "github.com/arduino/arduino-cli/rpc/commands"
25-
"github.com/lithammer/fuzzysearch/fuzzy"
2626
)
2727

2828
// maximumSearchDistance is the maximum Levenshtein distance accepted when using fuzzy search.
@@ -36,18 +36,26 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllRe
3636
return nil, errors.New("invalid instance")
3737
}
3838

39-
searchArgs := strings.Join(req.SearchArgs, " ")
39+
searchArgs := []string{}
40+
for _, s := range req.SearchArgs {
41+
searchArgs = append(searchArgs, strings.Trim(s, " "))
42+
}
4043

41-
match := func(toTest []string) bool {
44+
match := func(toTest []string) (bool, error) {
4245
if len(searchArgs) == 0 {
43-
return true
46+
return true, nil
4447
}
45-
for _, rank := range fuzzy.RankFindNormalizedFold(searchArgs, toTest) {
46-
if rank.Distance < maximumSearchDistance {
47-
return true
48+
49+
for _, t := range toTest {
50+
matches, err := utils.Match(t, searchArgs)
51+
if err != nil {
52+
return false, err
53+
}
54+
if matches {
55+
return matches, nil
4856
}
4957
}
50-
return false
58+
return false, nil
5159
}
5260

5361
list := &rpc.BoardListAllResp{Boards: []*rpc.BoardListItem{}}
@@ -90,10 +98,11 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllRe
9098
continue
9199
}
92100

93-
toTest := toTest
94-
toTest = append(toTest, strings.Split(board.Name(), " ")...)
101+
toTest := append(toTest, board.Name())
95102
toTest = append(toTest, board.FQBN())
96-
if !match(toTest) {
103+
if ok, err := match(toTest); err != nil {
104+
return nil, err
105+
} else if !ok {
97106
continue
98107
}
99108

test/test_board.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -455,34 +455,6 @@ def test_board_listall_with_manually_installed_platform(run_command, data_dir):
455455
assert "Arduino SAMD (32-bits ARM Cortex-M0+) Boards" == platform["Name"]
456456

457457

458-
def test_board_listall_fuzzy_search(run_command, data_dir):
459-
assert run_command("update")
460-
461-
# Install from platform manager
462-
assert run_command("core install arduino:[email protected]")
463-
464-
# Manually installs a core in sketchbooks hardware folder
465-
git_url = "https://github.com/arduino/ArduinoCore-samd.git"
466-
repo_dir = Path(data_dir, "hardware", "arduino-beta-development", "samd")
467-
assert Repo.clone_from(git_url, repo_dir, multi_options=["-b 1.8.11"])
468-
469-
res = run_command("board listall --format json samd")
470-
assert res.ok
471-
data = json.loads(res.stdout)
472-
boards = {b["FQBN"]: b for b in data["boards"]}
473-
assert len(boards) == 17
474-
assert "arduino-beta-development:samd:mkr1000" in boards
475-
assert "arduino:avr:uno" not in boards
476-
477-
res = run_command("board listall --format json avr")
478-
assert res.ok
479-
data = json.loads(res.stdout)
480-
boards = {b["FQBN"]: b for b in data["boards"]}
481-
assert len(boards) == 26
482-
assert "arduino:avr:uno" in boards
483-
assert "arduino-beta-development:samd:mkr1000" not in boards
484-
485-
486458
def test_board_details(run_command):
487459
run_command("core update-index")
488460
# Download samd core pinned to 1.8.6

0 commit comments

Comments
 (0)