Skip to content

Commit 821c03a

Browse files
committed
match func doesn't need err anymore
1 parent 09af6d5 commit 821c03a

File tree

4 files changed

+21
-31
lines changed

4 files changed

+21
-31
lines changed

Diff for: commands/board/listall.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
4141
searchArgs = append(searchArgs, strings.Trim(s, " "))
4242
}
4343

44-
match := func(toTest []string) (bool, error) {
44+
match := func(toTest []string) bool {
4545
if len(searchArgs) == 0 {
46-
return true, nil
46+
return true
4747
}
4848

4949
for _, t := range toTest {
5050
if utils.Match(t, searchArgs) {
51-
return true, nil
51+
return true
5252
}
5353
}
54-
return false, nil
54+
return false
5555
}
5656

5757
list := &rpc.BoardListAllResponse{Boards: []*rpc.BoardListItem{}}
@@ -96,9 +96,7 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
9696

9797
toTest := append(toTest, board.Name())
9898
toTest = append(toTest, board.FQBN())
99-
if ok, err := match(toTest); err != nil {
100-
return nil, err
101-
} else if !ok {
99+
if !match(toTest) {
102100
continue
103101
}
104102

Diff for: commands/board/search.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
3838

3939
searchArgs := strings.Split(strings.Trim(req.SearchArgs, " "), " ")
4040

41-
match := func(toTest []string) (bool, error) {
41+
match := func(toTest []string) bool {
4242
if len(searchArgs) == 0 {
43-
return true, nil
43+
return true
4444
}
4545

4646
for _, t := range toTest {
4747
if utils.Match(t, searchArgs) {
48-
return true, nil
48+
return true
4949
}
5050
}
51-
return false, nil
51+
return false
5252
}
5353

5454
res := &rpc.BoardSearchResponse{Boards: []*rpc.BoardListItem{}}
@@ -89,9 +89,7 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
8989
}
9090

9191
toTest := append(strings.Split(board.Name(), " "), board.Name(), board.FQBN())
92-
if ok, err := match(toTest); err != nil {
93-
return nil, err
94-
} else if !ok {
92+
if !match(toTest) {
9593
continue
9694
}
9795

@@ -105,9 +103,7 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
105103
} else if latestPlatformRelease != nil {
106104
for _, board := range latestPlatformRelease.BoardsManifest {
107105
toTest := append(strings.Split(board.Name, " "), board.Name)
108-
if ok, err := match(toTest); err != nil {
109-
return nil, err
110-
} else if !ok {
106+
if !match(toTest) {
111107
continue
112108
}
113109

Diff for: commands/core/search.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
4848

4949
searchArgs := strings.Split(searchArgs, " ")
5050

51-
match := func(toTest []string) (bool, error) {
51+
match := func(toTest []string) bool {
5252
if len(searchArgs) == 0 {
53-
return true, nil
53+
return true
5454
}
5555

5656
for _, t := range toTest {
5757
if utils.Match(t, searchArgs) {
58-
return true, nil
58+
return true
5959
}
6060
}
61-
return false, nil
61+
return false
6262
}
6363

6464
for _, targetPackage := range pm.Packages {
@@ -91,9 +91,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
9191
}
9292

9393
// Search
94-
if ok, err := match(toTest); err != nil {
95-
return nil, err
96-
} else if !ok {
94+
if !match(toTest) {
9795
continue
9896
}
9997

Diff for: commands/lib/search.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,22 @@ func searchLibrary(req *rpc.LibrarySearchRequest, lm *librariesmanager.Libraries
4545

4646
searchArgs := strings.Split(strings.Trim(query, " "), " ")
4747

48-
match := func(toTest []string) (bool, error) {
48+
match := func(toTest []string) bool {
4949
if len(searchArgs) == 0 {
50-
return true, nil
50+
return true
5151
}
5252

5353
for _, t := range toTest {
5454
if utils.Match(t, searchArgs) {
55-
return true, nil
55+
return true
5656
}
5757
}
58-
return false, nil
58+
return false
5959
}
6060

6161
for _, lib := range lm.Index.Libraries {
6262
toTest := []string{lib.Name, lib.Latest.Paragraph, lib.Latest.Sentence}
63-
if ok, err := match(toTest); err != nil {
64-
return nil, err
65-
} else if !ok {
63+
if !match(toTest) {
6664
continue
6765
}
6866
res = append(res, indexLibraryToRPCSearchLibrary(lib))

0 commit comments

Comments
 (0)