|
- package pubshards
-
- import (
- "fmt"
-
- "github.com/jedib0t/go-pretty/v6/table"
- "github.com/spf13/cobra"
- cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
- "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
- )
-
- func init() {
- var opt lsOption
- c := &cobra.Command{
- Use: "ls",
- Short: "list all pub shards",
- Args: cobra.NoArgs,
- RunE: func(c *cobra.Command, args []string) error {
- ctx := cmd.GetCmdCtx(c)
- return ls(c, ctx, opt, args)
- },
- }
- PubShardsCmd.AddCommand(c)
- c.Flags().BoolVarP(&opt.Long, "long", "l", false, "show more details")
- }
-
- type lsOption struct {
- Long bool
- }
-
- func ls(c *cobra.Command, ctx *cmd.CommandContext, opt lsOption, args []string) error {
- resp, err := ctx.Client.PubShards().List(cliapi.PubShardsList{})
- if err != nil {
- return err
- }
-
- if !opt.Long {
- for _, p := range resp.PubShards {
- fmt.Printf("%v\n", p.Name)
- }
- return nil
- }
-
- tb := table.NewWriter()
- tb.AppendHeader(table.Row{"PubShards ID", "PubShards Name", "UserSpace Name"})
- for i := range resp.PubShards {
- tb.AppendRow(table.Row{resp.PubShards[i].PubShardsID, resp.PubShards[i].Name, resp.UserSpaces[i].Name})
- }
- fmt.Println(tb.Render())
- return nil
- }
|