You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ls.go 1.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package pubshards
  2. import (
  3. "fmt"
  4. "github.com/jedib0t/go-pretty/v6/table"
  5. "github.com/spf13/cobra"
  6. cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
  7. "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
  8. )
  9. func init() {
  10. var opt lsOption
  11. c := &cobra.Command{
  12. Use: "ls",
  13. Short: "list all pub shards",
  14. Args: cobra.NoArgs,
  15. RunE: func(c *cobra.Command, args []string) error {
  16. ctx := cmd.GetCmdCtx(c)
  17. return ls(c, ctx, opt, args)
  18. },
  19. }
  20. PubShardsCmd.AddCommand(c)
  21. c.Flags().BoolVarP(&opt.Long, "long", "l", false, "show more details")
  22. }
  23. type lsOption struct {
  24. Long bool
  25. }
  26. func ls(c *cobra.Command, ctx *cmd.CommandContext, opt lsOption, args []string) error {
  27. resp, err := ctx.Client.PubShards().List(cliapi.PubShardsList{})
  28. if err != nil {
  29. return err
  30. }
  31. if !opt.Long {
  32. for _, p := range resp.PubShards {
  33. fmt.Printf("%v\n", p.Name)
  34. }
  35. return nil
  36. }
  37. tb := table.NewWriter()
  38. tb.AppendHeader(table.Row{"PubShards ID", "PubShards Name", "UserSpace Name"})
  39. for i := range resp.PubShards {
  40. tb.AppendRow(table.Row{resp.PubShards[i].PubShardsID, resp.PubShards[i].Name, resp.UserSpaces[i].Name})
  41. }
  42. fmt.Println(tb.Render())
  43. return nil
  44. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。