/
cmd_simplefs_remove.go
102 lines (88 loc) · 2.3 KB
/
cmd_simplefs_remove.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"errors"
"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"
)
// CmdSimpleFSRemove is the 'fs rm' command.
type CmdSimpleFSRemove struct {
libkb.Contextified
paths []keybase1.Path
}
// NewCmdSimpleFSRemove creates a new cli.Command.
func NewCmdSimpleFSRemove(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "rm",
ArgumentHelp: "<path> [path...]",
Usage: "remove one or more directory elements",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdSimpleFSRemove{Contextified: libkb.NewContextified(g)}, "rm", c)
cl.SetNoStandalone()
},
}
}
// Run runs the command in client/server mode.
func (c *CmdSimpleFSRemove) Run() error {
cli, err := GetSimpleFSClient(c.G())
if err != nil {
return err
}
ctx := context.TODO()
paths, err := doSimpleFSGlob(ctx, c.G(), cli, c.paths)
if err != nil {
return err
}
for _, path := range paths {
opid, err2 := cli.SimpleFSMakeOpid(ctx)
if err2 != nil {
return err2
}
defer cli.SimpleFSClose(ctx, opid)
c.G().Log.Debug("SimpleFSRemove %s", path.Kbfs())
err = cli.SimpleFSRemove(ctx, keybase1.SimpleFSRemoveArg{
OpID: opid,
Path: path,
})
if err != nil {
break
}
err = cli.SimpleFSWait(ctx, opid)
if err != nil {
break
}
}
return err
}
// ParseArgv gets the required path argument for this command.
func (c *CmdSimpleFSRemove) ParseArgv(ctx *cli.Context) error {
nargs := len(ctx.Args())
var err error
if nargs < 1 {
return errors.New("rm requires at least one KBFS path argument")
}
for _, src := range ctx.Args() {
argPath := makeSimpleFSPath(c.G(), src)
pathType, err := argPath.PathType()
if err != nil {
return err
}
if pathType != keybase1.PathType_KBFS {
return errors.New("rm requires KBFS path arguments")
}
c.paths = append(c.paths, argPath)
}
return err
}
// GetUsage says what this command needs to operate.
func (c *CmdSimpleFSRemove) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
KbKeyring: true,
API: true,
}
}