-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_chat_search_bots.go
78 lines (69 loc) · 1.75 KB
/
cmd_chat_search_bots.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
package client
import (
"errors"
"fmt"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
context "golang.org/x/net/context"
)
type CmdChatSearchBots struct {
libkb.Contextified
query string
limit int
}
func NewCmdChatSearchBotsRunner(g *libkb.GlobalContext) *CmdChatSearchBots {
return &CmdChatSearchBots{
Contextified: libkb.NewContextified(g),
}
}
func newCmdChatSearchBots(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "search-bots",
Usage: "Search chat bots available on Keybase.",
ArgumentHelp: "<query>",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdChatSearchBotsRunner(g), "search-bots", c)
cl.SetNoStandalone()
cl.SetLogForward(libcmdline.LogForwardNone)
},
Flags: []cli.Flag{
cli.IntFlag{
Name: "n, number",
Usage: fmt.Sprintf("Number of bots to display, defaults to %d", defaultFeaturedBotsLimit),
Value: defaultFeaturedBotsLimit,
},
},
}
}
func (c *CmdChatSearchBots) Run() (err error) {
cli, err := GetFeaturedBotsClient(c.G())
if err != nil {
return err
}
res, err := cli.SearchLocal(context.Background(), keybase1.SearchLocalArg{
Query: c.query,
Limit: c.limit,
SkipCache: true,
})
if err != nil {
return err
}
err = displayFeaturedBots(c.G(), res.Bots)
return err
}
func (c *CmdChatSearchBots) ParseArgv(ctx *cli.Context) (err error) {
if len(ctx.Args()) != 1 {
return errors.New("usage: keybase chat search-bots <query>")
}
c.query = ctx.Args().Get(0)
c.limit = ctx.Int("number")
return nil
}
func (c *CmdChatSearchBots) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}