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.

join.go 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package pubshards
  2. import (
  3. "fmt"
  4. "github.com/chzyer/readline"
  5. "github.com/spf13/cobra"
  6. cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
  7. jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
  8. "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
  9. )
  10. func init() {
  11. var opt joinOption
  12. c := &cobra.Command{
  13. Use: "join <id>",
  14. Short: "join to a pubshards",
  15. Args: cobra.ExactArgs(1),
  16. RunE: func(c *cobra.Command, args []string) error {
  17. ctx := cmd.GetCmdCtx(c)
  18. return join(c, ctx, opt, args)
  19. },
  20. }
  21. c.Flags().StringVarP(&opt.Password, "p", "p", "", "password for the pubshards")
  22. PubShardsCmd.AddCommand(c)
  23. }
  24. type joinOption struct {
  25. Password string
  26. }
  27. func join(c *cobra.Command, ctx *cmd.CommandContext, opt joinOption, args []string) error {
  28. rl, err := readline.New("> ")
  29. if err != nil {
  30. return err
  31. }
  32. defer rl.Close()
  33. if !c.Flags().Changed("p") {
  34. opt.Password = string(cmd.ReadPassword(rl, "Password"))
  35. }
  36. usName := cmd.ReadString(rl, "请输入新用户空间的名称")
  37. resp, err := ctx.Client.PubShards().Join(cliapi.PubShardsJoin{
  38. Name: usName,
  39. PubShardsID: jcstypes.PubShardsID(args[0]),
  40. Password: opt.Password,
  41. })
  42. if err != nil {
  43. return err
  44. }
  45. fmt.Printf("加入成功, 用户空间配置ID为: %v\n", resp.UserSpace.UserSpaceID)
  46. return nil
  47. }

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