-
Notifications
You must be signed in to change notification settings - Fork 6
/
versions.go
47 lines (40 loc) · 1.19 KB
/
versions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package kubernetes
import (
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
)
// VersionsCommand creates the "kubernetes versions" command
func VersionsCommand() commands.Command {
return &versionsCommand{
BaseCommand: commands.New("versions", "List available versions for Kubernetes clusters", "upctl kubernetes versions"),
}
}
type versionsCommand struct {
*commands.BaseCommand
}
// ExecuteWithoutArguments implements commands.NoArgumentCommand
func (s *versionsCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) {
svc := exec.All()
versions, err := svc.GetKubernetesVersions(exec.Context(), &request.GetKubernetesVersionsRequest{})
if err != nil {
return nil, err
}
rows := []output.TableRow{}
for _, version := range versions {
rows = append(rows, output.TableRow{
version.Id,
version.Version,
})
}
return output.MarshaledWithHumanOutput{
Value: versions,
Output: output.Table{
Columns: []output.TableColumn{
{Key: "id", Header: "ID"},
{Key: "version", Header: "Version"},
},
Rows: rows,
},
}, nil
}