Skip to content

Commit f1e5094

Browse files
committed
Use Name instead of CanonicalName in LibraryList
This fixes also `lib list` and `lib examples`.
1 parent c3231a3 commit f1e5094

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

Diff for: commands/lib/list.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
4848

4949
nameFilter := strings.ToLower(req.GetName())
5050

51-
installedLibs := []*rpc.InstalledLibrary{}
52-
res := listLibraries(lm, req.GetUpdatable(), req.GetAll())
51+
allLibs := listLibraries(lm, req.GetUpdatable(), req.GetAll())
5352
if f := req.GetFqbn(); f != "" {
5453
fqbn, err := cores.ParseFQBN(req.GetFqbn())
5554
if err != nil {
@@ -61,15 +60,16 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
6160
}
6261

6362
filteredRes := map[string]*installedLib{}
64-
for _, lib := range res {
63+
for _, lib := range allLibs {
6564
if cp := lib.Library.ContainerPlatform; cp != nil {
6665
if cp != boardPlatform && cp != refBoardPlatform {
6766
// Filter all libraries from extraneous platforms
6867
continue
6968
}
7069
}
71-
if latest, has := filteredRes[lib.Library.CanonicalName]; has {
70+
if latest, has := filteredRes[lib.Library.Name]; has {
7271
if latest.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) >= lib.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) {
72+
// Pick library with the best priority
7373
continue
7474
}
7575
}
@@ -86,17 +86,18 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
8686
f: compatible,
8787
}
8888

89-
filteredRes[lib.Library.CanonicalName] = lib
89+
filteredRes[lib.Library.Name] = lib
9090
}
9191

92-
res = []*installedLib{}
92+
allLibs = []*installedLib{}
9393
for _, lib := range filteredRes {
94-
res = append(res, lib)
94+
allLibs = append(allLibs, lib)
9595
}
9696
}
9797

98-
for _, lib := range res {
99-
if nameFilter != "" && strings.ToLower(lib.Library.CanonicalName) != nameFilter {
98+
installedLibs := []*rpc.InstalledLibrary{}
99+
for _, lib := range allLibs {
100+
if nameFilter != "" && strings.ToLower(lib.Library.Name) != nameFilter {
100101
continue
101102
}
102103
var release *rpc.LibraryRelease
@@ -105,7 +106,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
105106
}
106107
rpcLib, err := lib.Library.ToRPCLibrary()
107108
if err != nil {
108-
return nil, &arduino.PermissionDeniedError{Message: tr("Error getting information for library %s", lib.Library.CanonicalName), Cause: err}
109+
return nil, &arduino.PermissionDeniedError{Message: tr("Error getting information for library %s", lib.Library.Name), Cause: err}
109110
}
110111
installedLibs = append(installedLibs, &rpc.InstalledLibrary{
111112
Library: rpcLib,

Diff for: internal/integrationtest/lib/lib_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ func TestLibUpgradeCommand(t *testing.T) {
6565
requirejson.Query(t, stdOut, `.[].library | select(.name=="Servo") | .version`, servoVersion)
6666
}
6767

68+
func TestLibCommandsUsingNameInsteadOfCanonicalName(t *testing.T) {
69+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
70+
defer env.CleanUp()
71+
72+
_, _, err := cli.Run("lib", "install", "Robot Motor")
73+
require.NoError(t, err)
74+
75+
jsonOut, _, err := cli.Run("lib", "examples", "Robot Motor", "--format", "json")
76+
require.NoError(t, err)
77+
requirejson.Len(t, jsonOut, 1, "Library 'Robot Motor' not matched in lib examples command.")
78+
79+
jsonOut, _, err = cli.Run("lib", "list", "Robot Motor", "--format", "json")
80+
require.NoError(t, err)
81+
requirejson.Len(t, jsonOut, 1, "Library 'Robot Motor' not matched in lib list command.")
82+
}
83+
6884
func TestLibInstallMultipleSameLibrary(t *testing.T) {
6985
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
7086
defer env.CleanUp()

0 commit comments

Comments
 (0)