-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_simplefs_ps.go
113 lines (96 loc) · 3.03 KB
/
cmd_simplefs_ps.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
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"golang.org/x/net/context"
"encoding/hex"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
// CmdSimpleFSPs is the 'fs ps' command.
type CmdSimpleFSPs struct {
libkb.Contextified
recurse bool
}
// NewCmdSimpleFSPs creates a new cli.Command.
func NewCmdSimpleFSPs(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "ps",
Usage: "list running operations",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdSimpleFSPs{Contextified: libkb.NewContextified(g)}, "ps", c)
cl.SetNoStandalone()
},
}
}
// Run runs the command in client/server mode.
func (c *CmdSimpleFSPs) Run() error {
cli, err := GetSimpleFSClient(c.G())
if err != nil {
return err
}
ops, err := cli.SimpleFSGetOps(context.TODO())
c.output(ops)
return err
}
func getPathString(path keybase1.Path) string {
pathType, err := path.PathType()
if err != nil {
return ""
}
if pathType == keybase1.PathType_KBFS {
return path.Kbfs().Path
}
return path.Local()
}
func outputOp(ui libkb.TerminalUI, o keybase1.OpDescription) {
op, err := o.AsyncOp()
if err != nil {
ui.Printf("%s", err)
return
}
switch op {
case keybase1.AsyncOps_LIST:
list := o.List()
ui.Printf("%s\t%s\t%s\n", hex.EncodeToString(list.OpID[:]), op.String(), getPathString(list.Path))
case keybase1.AsyncOps_LIST_RECURSIVE:
list := o.ListRecursive()
ui.Printf("%s\t%s\t%s\n", hex.EncodeToString(list.OpID[:]), op.String(), getPathString(list.Path))
case keybase1.AsyncOps_READ:
read := o.Read()
ui.Printf("%s\t%s\t%s\t%d\t%d\n", hex.EncodeToString(read.OpID[:]), op.String(), getPathString(read.Path), read.Offset, read.Size)
case keybase1.AsyncOps_WRITE:
write := o.Write()
ui.Printf("%s\t%s\t%s\t%d\n", hex.EncodeToString(write.OpID[:]), op.String(), getPathString(write.Path), write.Offset)
case keybase1.AsyncOps_COPY:
copy := o.Copy()
ui.Printf("%s\t%s\t%s\t%s\n", hex.EncodeToString(copy.OpID[:]), op.String(), getPathString(copy.Src), getPathString(copy.Dest))
case keybase1.AsyncOps_MOVE:
move := o.Move()
ui.Printf("%s\t%s\t%s\t%s\n", hex.EncodeToString(move.OpID[:]), op.String(), getPathString(move.Src), getPathString(move.Dest))
case keybase1.AsyncOps_REMOVE:
remove := o.Remove()
ui.Printf("%s\t%s\t%s\n", hex.EncodeToString(remove.OpID[:]), op.String(), getPathString(remove.Path))
}
}
func (c *CmdSimpleFSPs) output(ops []keybase1.OpDescription) {
ui := c.G().UI.GetTerminalUI()
for _, e := range ops {
outputOp(ui, e)
}
}
// ParseArgv gets the optional -r switch
func (c *CmdSimpleFSPs) ParseArgv(ctx *cli.Context) error {
c.recurse = ctx.Bool("recurse")
return nil
}
// GetUsage says what this command needs to operate.
func (c *CmdSimpleFSPs) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
KbKeyring: true,
API: true,
}
}