Skip to content

Commit 9d2fd89

Browse files
cmagliealessio-perugini
authored andcommitted
Adapt arguuments completion to use PlatformSearch instead of PlatformList
1 parent 24a1dd3 commit 9d2fd89

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

internal/cli/arguments/completion.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,18 @@ func GetInstalledProgrammers() []string {
8383
func GetUninstallableCores() []string {
8484
inst := instance.CreateAndInit()
8585

86-
platforms, _ := core.PlatformList(&rpc.PlatformListRequest{
87-
Instance: inst,
88-
UpdatableOnly: false,
89-
All: false,
86+
platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{
87+
Instance: inst,
88+
AllVersions: false,
9089
})
90+
9191
var res []string
9292
// transform the data structure for the completion
93-
for _, i := range platforms.InstalledPlatforms {
94-
res = append(res, i.Id+"\t"+i.Name)
93+
for _, i := range platforms.GetSearchOutput() {
94+
if i.InstalledVersion == "" {
95+
continue
96+
}
97+
res = append(res, i.GetMetadata().GetId()+"\t"+i.GetInstalledRelease().GetName())
9598
}
9699
return res
97100
}
@@ -109,7 +112,7 @@ func GetInstallableCores() []string {
109112
var res []string
110113
// transform the data structure for the completion
111114
for _, i := range platforms.SearchOutput {
112-
res = append(res, i.Id+"\t"+i.Name)
115+
res = append(res, i.GetMetadata().GetId()+"\t"+i.GetReleases()[i.GetLatestVersion()].GetName())
113116
}
114117
return res
115118
}

internal/cli/arguments/reference.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func ParseReference(arg string) (*Reference, error) {
6666
if arg == "" {
6767
return nil, fmt.Errorf(tr("invalid empty core argument"))
6868
}
69+
6970
toks := strings.SplitN(arg, "@", 2)
7071
if toks[0] == "" {
7172
return nil, fmt.Errorf(tr("invalid empty core reference '%s'"), arg)
@@ -85,23 +86,27 @@ func ParseReference(arg string) (*Reference, error) {
8586
if toks[0] == "" {
8687
return nil, fmt.Errorf(tr("invalid empty core name '%s'"), arg)
8788
}
88-
ret.PackageName = toks[0]
8989
if toks[1] == "" {
9090
return nil, fmt.Errorf(tr("invalid empty core architecture '%s'"), arg)
9191
}
92+
ret.PackageName = toks[0]
9293
ret.Architecture = toks[1]
9394

9495
// Now that we have the required informations in `ret` we can
9596
// try to use core.PlatformList to optimize what the user typed
9697
// (by replacing the PackageName and Architecture in ret with the content of core.GetPlatform())
97-
platforms, _ := core.PlatformList(&rpc.PlatformListRequest{
98-
Instance: instance.CreateAndInit(),
99-
UpdatableOnly: false,
100-
All: true, // this is true because we want also the installable platforms
98+
platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{
99+
Instance: instance.CreateAndInit(),
100+
AllVersions: false,
101101
})
102102
foundPlatforms := []string{}
103-
for _, platform := range platforms.InstalledPlatforms {
104-
platformID := platform.GetId()
103+
for _, platform := range platforms.GetSearchOutput() {
104+
installedRelease := platform.GetInstalledRelease()
105+
if installedRelease == nil {
106+
continue
107+
}
108+
109+
platformID := platform.GetMetadata().GetId()
105110
platformUser := ret.PackageName + ":" + ret.Architecture
106111
// At first we check if the platform the user is searching for matches an available one,
107112
// this way we do not need to adapt the casing and we can return it directly
@@ -110,7 +115,6 @@ func ParseReference(arg string) (*Reference, error) {
110115
}
111116
if strings.EqualFold(platformUser, platformID) {
112117
logrus.Infof("Found possible match for reference %s -> %s", platformUser, platformID)
113-
toks = strings.Split(platformID, ":")
114118
foundPlatforms = append(foundPlatforms, platformID)
115119
}
116120
}
@@ -122,6 +126,7 @@ func ParseReference(arg string) (*Reference, error) {
122126
if len(foundPlatforms) > 1 {
123127
return nil, &arduino.MultiplePlatformsError{Platforms: foundPlatforms, UserPlatform: arg}
124128
}
129+
toks = strings.Split(foundPlatforms[0], ":")
125130
ret.PackageName = toks[0]
126131
ret.Architecture = toks[1]
127132
return ret, nil

0 commit comments

Comments
 (0)