Skip to content

Commit c80d0ff

Browse files
cmagliealessio-perugini
authored andcommitted
Adapt 'core list' to use PlatformSearch instead of PlatformList
1 parent 9d2fd89 commit c80d0ff

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

internal/cli/core/list.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,32 @@ func List(inst *rpc.Instance, all bool, updatableOnly bool) {
5959
}
6060

6161
// GetList returns a list of installed platforms.
62-
func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.Platform {
63-
platforms, err := core.PlatformList(&rpc.PlatformListRequest{
64-
Instance: inst,
65-
UpdatableOnly: updatableOnly,
66-
All: all,
62+
func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.PlatformSummary {
63+
platforms, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
64+
Instance: inst,
65+
AllVersions: true,
6766
})
6867
if err != nil {
6968
feedback.Fatal(tr("Error listing platforms: %v", err), feedback.ErrGeneric)
7069
}
71-
return platforms.InstalledPlatforms
70+
71+
result := []*rpc.PlatformSummary{}
72+
for _, platform := range platforms.GetSearchOutput() {
73+
if !all && platform.InstalledVersion == "" {
74+
continue
75+
}
76+
if updatableOnly && platform.InstalledVersion == platform.LatestVersion {
77+
continue
78+
}
79+
result = append(result, platform)
80+
}
81+
return result
7282
}
7383

7484
// output from this command requires special formatting, let's create a dedicated
7585
// feedback.Result implementation
7686
type installedResult struct {
77-
platforms []*rpc.Platform
87+
platforms []*rpc.PlatformSummary
7888
}
7989

8090
func (ir installedResult) Data() interface{} {
@@ -87,12 +97,18 @@ func (ir installedResult) String() string {
8797
}
8898
t := table.New()
8999
t.SetHeader(tr("ID"), tr("Installed"), tr("Latest"), tr("Name"))
90-
for _, p := range ir.platforms {
91-
name := p.Name
92-
if p.Deprecated {
100+
for _, platform := range ir.platforms {
101+
installedRelease := platform.GetInstalledRelease()
102+
latestRelease := platform.GetLatestRelease()
103+
104+
name := installedRelease.GetName()
105+
if name == "" {
106+
name = latestRelease.GetName()
107+
}
108+
if platform.Metadata.Deprecated {
93109
name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), name)
94110
}
95-
t.AddRow(p.Id, p.Installed, p.Latest, name)
111+
t.AddRow(platform.Metadata.Id, platform.InstalledVersion, platform.LatestVersion, name)
96112
}
97113

98114
return t.Render()

0 commit comments

Comments
 (0)