/
cmd_account_reset_timetravel.go
70 lines (60 loc) · 1.81 KB
/
cmd_account_reset_timetravel.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
package client
import (
"errors"
"time"
"github.com/keybase/cli"
"github.com/adamwalz/keybase-client/go/libcmdline"
"github.com/adamwalz/keybase-client/go/libkb"
gregor1 "github.com/adamwalz/keybase-client/go/protocol/gregor1"
"github.com/adamwalz/keybase-client/go/protocol/keybase1"
"golang.org/x/net/context"
)
// Cancel the reset pipeline
type CmdAccountResetTimeTravel struct {
libkb.Contextified
username string
duration time.Duration
}
func NewCmdAccountResetTimeTravel(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "reset-time-travel",
Usage: "Time travel further into the reset process [devel-only]",
Action: func(c *cli.Context) {
cmd := NewCmdAccountResetTimeTravelRunner(g)
cl.ChooseCommand(cmd, "reset-time-travel", c)
cl.SetSkipAccountResetCheck()
},
}
}
func NewCmdAccountResetTimeTravelRunner(g *libkb.GlobalContext) *CmdAccountResetTimeTravel {
return &CmdAccountResetTimeTravel{Contextified: libkb.NewContextified(g)}
}
func (c *CmdAccountResetTimeTravel) ParseArgv(ctx *cli.Context) (err error) {
if len(ctx.Args()) != 1 && len(ctx.Args()) != 2 {
return errors.New("invalid usage, expected [username?] [duration]")
}
if len(ctx.Args()) == 2 {
// [username] [duration]
c.username = ctx.Args().Get(0)
c.duration, err = time.ParseDuration(ctx.Args().Get(1))
return err
}
c.duration, err = time.ParseDuration(ctx.Args().Get(0))
return err
}
func (c *CmdAccountResetTimeTravel) Run() error {
cli, err := GetAccountClient(c.G())
if err != nil {
return err
}
return cli.TimeTravelReset(context.Background(), keybase1.TimeTravelResetArg{
Duration: gregor1.ToDurationSec(c.duration),
Username: c.username,
})
}
func (c *CmdAccountResetTimeTravel) GetUsage() libkb.Usage {
return libkb.Usage{
API: true,
Config: true,
}
}