/
cmd_trace.go
45 lines (37 loc) · 1.07 KB
/
cmd_trace.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
package app
import (
"fmt"
"github.com/gookit/color"
"github.com/spf13/cobra"
)
type TraceCmdOptions struct {
Args []string
}
func NewTraceCmd(cli Cli) *cobra.Command {
var opts TraceCmdOptions
cmd := &cobra.Command{
Use: "trace [flags]",
Short: "Trace packets across data path",
Args: cobra.ArbitraryArgs,
DisableFlagParsing: true,
RunE: func(cmd *cobra.Command, args []string) error {
opts.Args = args
return runTraceCmd(cli, opts)
},
}
return cmd
}
func runTraceCmd(cli Cli, opts TraceCmdOptions) error {
args := append([]string{"--print"}, opts.Args...)
// TODO: improve usage of trace command
// - automatically use ping as default command
// - consider selecting IP and source network namespace automatically
// - consider allowing users to simply select component names for ping src/dst
stdout, stderr, err := cli.Exec(fmt.Sprintf("vpp-probe --env=%s trace", defaultVppProbeEnv), args, false)
if err != nil {
return err
}
color.Fprintln(cli.Out(), stdout)
color.Fprintln(cli.Err(), stderr)
return nil
}