forked from keybase/client
/
cmd_chat_renamechannel.go
87 lines (76 loc) · 2.37 KB
/
cmd_chat_renamechannel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package client
import (
"context"
"fmt"
"github.com/keybase/cli"
"github.com/keybase/client/go/chat/utils"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/chat1"
"github.com/keybase/client/go/protocol/keybase1"
)
type CmdChatRenameChannel struct {
libkb.Contextified
resolvingRequest chatConversationResolvingRequest
setTopicName string
nonBlock bool
team bool
}
func NewCmdChatRenameChannelRunner(g *libkb.GlobalContext) *CmdChatRenameChannel {
return &CmdChatRenameChannel{Contextified: libkb.NewContextified(g)}
}
func newCmdChatRenameChannel(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "rename-channel",
Usage: "Rename a conversation channel",
ArgumentHelp: "[conversation [new channel name]]",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdChatRenameChannelRunner(g), "rename-channel", c)
},
Flags: append(getConversationResolverFlags(),
mustGetChatFlags("set-channel", "nonblock")...),
}
}
func (c *CmdChatRenameChannel) Run() error {
c.G().StartStandaloneChat()
return chatSend(context.TODO(), c.G(), ChatSendArg{
resolvingRequest: c.resolvingRequest,
setTopicName: c.setTopicName,
nonBlock: c.nonBlock,
team: true,
message: "",
setHeadline: "",
clearHeadline: false,
hasTTY: true,
})
}
func (c *CmdChatRenameChannel) ParseArgv(ctx *cli.Context) (err error) {
c.setTopicName = utils.SanitizeTopicName(ctx.String("set-channel"))
c.nonBlock = ctx.Bool("nonblock")
var tlfName string
if len(ctx.Args()) >= 1 {
tlfName = ctx.Args().Get(0)
} else {
return fmt.Errorf("Must supply team name.")
}
if c.resolvingRequest, err = parseConversationResolvingRequest(ctx, tlfName); err != nil {
return err
}
c.resolvingRequest.MembersType = chat1.ConversationMembersType_TEAM
if c.resolvingRequest.Visibility == keybase1.TLFVisibility_ANY {
c.resolvingRequest.Visibility = keybase1.TLFVisibility_PRIVATE
}
if c.setTopicName == "" {
return fmt.Errorf("Must supply non-empty channel name.")
}
if len(ctx.Args()) > 1 {
return fmt.Errorf("cannot send text message and set channel name simultaneously")
}
return nil
}
func (c *CmdChatRenameChannel) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}