57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package pubshards
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/chzyer/readline"
|
|
"github.com/spf13/cobra"
|
|
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
|
|
jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
|
|
"gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
|
|
)
|
|
|
|
func init() {
|
|
var opt joinOption
|
|
c := &cobra.Command{
|
|
Use: "join <id>",
|
|
Short: "join to a pubshards",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(c *cobra.Command, args []string) error {
|
|
ctx := cmd.GetCmdCtx(c)
|
|
return join(c, ctx, opt, args)
|
|
},
|
|
}
|
|
c.Flags().StringVarP(&opt.Password, "p", "p", "", "password for the pubshards")
|
|
PubShardsCmd.AddCommand(c)
|
|
}
|
|
|
|
type joinOption struct {
|
|
Password string
|
|
}
|
|
|
|
func join(c *cobra.Command, ctx *cmd.CommandContext, opt joinOption, args []string) error {
|
|
rl, err := readline.New("> ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rl.Close()
|
|
|
|
if !c.Flags().Changed("p") {
|
|
opt.Password = string(cmd.ReadPassword(rl, "Password"))
|
|
}
|
|
|
|
usName := cmd.ReadString(rl, "请输入新用户空间的名称")
|
|
|
|
resp, err := ctx.Client.PubShards().Join(cliapi.PubShardsJoin{
|
|
Name: usName,
|
|
PubShardsID: jcstypes.PubShardsID(args[0]),
|
|
Password: opt.Password,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("加入成功, 用户空间配置ID为: %v\n", resp.UserSpace.UserSpaceID)
|
|
return nil
|
|
}
|