-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathremove.go
52 lines (42 loc) · 1.19 KB
/
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
package main
import (
"context"
"errors"
"flag"
"fmt"
"strings"
"github.com/genuinetools/bpfd/api/grpc"
"github.com/sirupsen/logrus"
)
const removeHelp = `Remove one or more rules.`
func (cmd *removeCommand) Name() string { return "rm" }
func (cmd *removeCommand) Args() string { return "[OPTIONS] RULE_NAME [RULE_NAME...]" }
func (cmd *removeCommand) ShortHelp() string { return removeHelp }
func (cmd *removeCommand) LongHelp() string { return removeHelp }
func (cmd *removeCommand) Hidden() bool { return false }
func (cmd *removeCommand) Register(fs *flag.FlagSet) {
}
type removeCommand struct {
}
func (cmd *removeCommand) Run(ctx context.Context, args []string) error {
if len(args) < 1 {
return errors.New("must pass at least one rule")
}
// Create the grpc client.
c, err := getClient(ctx, grpcAddress)
if err != nil {
return err
}
logrus.Debugf("Removing rules: %s", strings.Join(args, ", "))
// Remove the rules.
for _, name := range args {
_, err := c.RemoveRule(ctx, &grpc.RemoveRuleRequest{
Name: name,
})
if err != nil {
return fmt.Errorf("sending RemoveRule request for name %s failed: %v", name, err)
}
fmt.Println(name)
}
return nil
}