forked from keybase/client
/
cmd_follow.go
100 lines (86 loc) · 2.38 KB
/
cmd_follow.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
95
96
97
98
99
100
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"fmt"
"golang.org/x/net/context"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
)
type CmdTrack struct {
user string
skipProofCache bool
options keybase1.TrackOptions
libkb.Contextified
}
func NewCmdTrack(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "follow",
ArgumentHelp: "<username>",
Usage: "Verify a user's authenticity and optionally follow them",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "local, l",
Usage: "Only follow locally, don't send a public statement to the server.",
},
cli.BoolFlag{
Name: "y",
Usage: "Approve remote following without prompting.",
},
cli.BoolFlag{
Name: "s, skip-proof-cache",
Usage: "Skip cached proofs, force re-check",
},
},
Aliases: []string{"track"},
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdTrackRunner(g), "follow", c)
},
}
}
func NewCmdTrackRunner(g *libkb.GlobalContext) *CmdTrack {
return &CmdTrack{Contextified: libkb.NewContextified(g)}
}
func (v *CmdTrack) SetUser(user string) {
v.user = user
}
func (v *CmdTrack) SetOptions(options keybase1.TrackOptions) {
v.options = options
}
func (v *CmdTrack) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
return fmt.Errorf("Follow only takes one argument, the user to follow.")
}
v.user = ctx.Args()[0]
v.options = keybase1.TrackOptions{LocalOnly: ctx.Bool("local"), BypassConfirm: ctx.Bool("y")}
v.skipProofCache = ctx.Bool("skip-proof-cache")
return nil
}
func (v *CmdTrack) Run() error {
cli, err := GetTrackClient(v.G())
if err != nil {
return err
}
protocols := []rpc.Protocol{
NewIdentifyTrackUIProtocol(v.G()),
NewSecretUIProtocol(v.G()),
}
if err = RegisterProtocolsWithContext(protocols, v.G()); err != nil {
return err
}
return cli.Track(context.TODO(), keybase1.TrackArg{
UserAssertion: v.user,
Options: v.options,
ForceRemoteCheck: v.skipProofCache,
})
}
func (v *CmdTrack) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}