-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathlist.go
52 lines (43 loc) · 1.03 KB
/
list.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
48
49
50
51
52
package cmd
import (
"fmt"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
"github.com/kubesphere/ksbuilder/pkg/cloud"
"github.com/kubesphere/ksbuilder/pkg/utils"
)
type listOptions struct{}
func listCmd() *cobra.Command {
o := listOptions{}
cmd := &cobra.Command{
Use: "list",
Short: "List all extensions of the current user on KubeSphere Cloud",
Args: cobra.NoArgs,
RunE: o.list,
}
return cmd
}
func (o *listOptions) list(_ *cobra.Command, _ []string) error {
client, err := cloud.NewClient()
if err != nil {
return fmt.Errorf("login failed: %v", err)
}
extensions, err := client.ListExtensions()
if err != nil {
return err
}
rows := make([]table.Row, 0)
for _, extension := range extensions.Extensions {
rows = append(rows, table.Row{
extension.ExtensionID,
extension.Name,
extension.Status,
extension.LatestVersion.Version,
})
}
t := utils.NewTableWriter()
t.AppendHeader(table.Row{"ID", "Name", "Status", "Latest version"})
t.AppendRows(rows)
t.Render()
return nil
}