-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add list subcommand to list extensions on KubeSphere Cloud
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters