-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_home.go
94 lines (83 loc) · 2.22 KB
/
cmd_home.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
88
89
90
91
92
93
94
// Copyright 2017 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"encoding/json"
"fmt"
"strings"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
"golang.org/x/net/context"
)
type CmdHome struct {
libkb.Contextified
markViewed bool
skipTodo keybase1.HomeScreenTodoType
}
func (c *CmdHome) ParseArgv(ctx *cli.Context) error {
c.markViewed = ctx.Bool("mark-viewed")
s := ctx.String("skip-todo")
if len(s) > 0 {
var ok bool
if c.skipTodo, ok = keybase1.HomeScreenTodoTypeMap[strings.ToUpper(s)]; !ok {
return fmt.Errorf("unknown todo type: %s", s)
}
}
return nil
}
func (c *CmdHome) Run() error {
cli, err := GetHomeClient(c.G())
if err != nil {
return err
}
ctx := context.Background()
if c.skipTodo != keybase1.HomeScreenTodoType_NONE {
return c.doSkipTodo(ctx, cli)
}
return c.getHome(ctx, cli)
}
func (c *CmdHome) doSkipTodo(ctx context.Context, cli keybase1.HomeClient) error {
return cli.HomeSkipTodoType(ctx, c.skipTodo)
}
func (c *CmdHome) getHome(ctx context.Context, cli keybase1.HomeClient) error {
screen, err := cli.HomeGetScreen(ctx, keybase1.HomeGetScreenArg{MarkViewed: c.markViewed, NumFollowSuggestionsWanted: 10})
if err != nil {
return err
}
b, err := json.Marshal(screen)
if err != nil {
return err
}
return c.G().UI.GetTerminalUI().OutputDesc(OutputDescriptorHomeDump, string(b)+"\n")
}
func NewCmdHomeRunner(g *libkb.GlobalContext) *CmdHome {
return &CmdHome{Contextified: libkb.NewContextified(g)}
}
func NewCmdHome(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "home",
Usage: "Get and set the 'home' screen",
Unlisted: true,
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdHomeRunner(g), "home", c)
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "mark-viewed",
Usage: "Mark the home page as 'viewed'.",
},
cli.StringFlag{
Name: "skip-todo",
Usage: "skip a category of home TODO items",
},
},
}
}
func (c *CmdHome) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}