forked from genuinetools/bpfd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
49 lines (38 loc) · 1.08 KB
/
list.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
package main
import (
"context"
"flag"
"fmt"
"os"
"text/tabwriter"
"github.com/genuinetools/bpfd/api/grpc"
)
const listHelp = `List rules.`
func (cmd *listCommand) Name() string { return "ls" }
func (cmd *listCommand) Args() string { return "[OPTIONS]" }
func (cmd *listCommand) ShortHelp() string { return listHelp }
func (cmd *listCommand) LongHelp() string { return listHelp }
func (cmd *listCommand) Hidden() bool { return false }
func (cmd *listCommand) Register(fs *flag.FlagSet) {
}
type listCommand struct {
}
func (cmd *listCommand) Run(ctx context.Context, args []string) error {
// Create the grpc client.
c, err := getClient(ctx, grpcAddress)
if err != nil {
return err
}
// List the rules.
resp, err := c.ListRules(context.Background(), &grpc.ListRulesRequest{})
if err != nil {
return fmt.Errorf("sending ListRules request failed: %v", err)
}
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
fmt.Fprint(w, "NAME\tTRACER\n")
for _, rule := range resp.Rules {
fmt.Fprintf(w, "%s\t%s\n", rule.Name, rule.Tracer)
}
w.Flush()
return nil
}