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.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package bucket
  2. import (
  3. "fmt"
  4. "github.com/jedib0t/go-pretty/v6/table"
  5. "github.com/spf13/cobra"
  6. "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 lsOpt
  11. cmd := cobra.Command{
  12. Use: "ls",
  13. Run: func(c *cobra.Command, args []string) {
  14. ctx := cmd.GetCmdCtx(c)
  15. ls(c, ctx, opt)
  16. },
  17. }
  18. cmd.Flags().BoolVarP(&opt.Long, "", "l", false, "listing in long format")
  19. BucketCmd.AddCommand(&cmd)
  20. }
  21. type lsOpt struct {
  22. Long bool
  23. }
  24. func ls(c *cobra.Command, ctx *cmd.CommandContext, opt lsOpt) {
  25. resp, err := ctx.Client.Bucket().ListAll(api.BucketListAll{})
  26. if err != nil {
  27. cmd.ErrorExitln(err.Error())
  28. }
  29. if opt.Long {
  30. fmt.Printf("total: %d\n", len(resp.Buckets))
  31. tb := table.NewWriter()
  32. tb.AppendHeader(table.Row{"Bucket ID", "Name", "Create Time"})
  33. for _, b := range resp.Buckets {
  34. tb.AppendRow(table.Row{b.BucketID, b.Name, b.CreateTime})
  35. }
  36. fmt.Println(tb.Render())
  37. } else {
  38. for _, b := range resp.Buckets {
  39. fmt.Println(b.Name)
  40. }
  41. }
  42. }

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