diff options
author | Mariusz Gronczewski <xani666@gmail.com> | 2017-10-17 16:37:09 +0200 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-10-30 09:20:06 +0900 |
commit | e8c439c2c99265737e7adea6c44d94ea18c07219 (patch) | |
tree | f83de83fc5de65933d939627ccc928ad3d2510bc | |
parent | 710db245624b2fc3e030ec7df599017051b83425 (diff) |
cli/mrt: move all options to config structure for consistency
-rw-r--r-- | gobgp/cmd/common.go | 3 | ||||
-rw-r--r-- | gobgp/cmd/mrt.go | 21 |
2 files changed, 14 insertions, 10 deletions
diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go index e5af88a3..a0904c49 100644 --- a/gobgp/cmd/common.go +++ b/gobgp/cmd/common.go @@ -111,6 +111,9 @@ var actionOpts struct { var mrtOpts struct { OutputDir string FileFormat string + Filename string `long:"filename" description:"MRT file name"` + RecordCount int `long:"count" description:"Number of records to inject"` + RecordSkip int `long:"skip" description:"Number of records to skip before injecting"` Best bool `long:"only-best" description:"only keep best path routes"` SkipV4 bool `long:"no-ipv4" description:"Skip importing IPv4 routes"` SkipV6 bool `long:"no-ipv4" description:"Skip importing IPv6 routes"` diff --git a/gobgp/cmd/mrt.go b/gobgp/cmd/mrt.go index 9a7f7629..ccd4a7f4 100644 --- a/gobgp/cmd/mrt.go +++ b/gobgp/cmd/mrt.go @@ -27,9 +27,9 @@ import ( "github.com/spf13/cobra" ) -func injectMrt(filename string, count int, skip int) error { +func injectMrt() error { - file, err := os.Open(filename) + file, err := os.Open(mrtOpts.Filename) if err != nil { return fmt.Errorf("failed to open file: %s", err) } @@ -133,12 +133,12 @@ func injectMrt(filename string, count int, skip int) error { paths = []*table.Path{best} } - if idx >= skip { + if idx >= mrtOpts.RecordSkip { ch <- paths } idx += 1 - if idx == count+skip { + if idx == mrtOpts.RecordCount + mrtOpts.RecordSkip { break } } @@ -172,23 +172,24 @@ func NewMrtCmd() *cobra.Command { if len(args) < 1 { exitWithError(fmt.Errorf("usage: gobgp mrt inject global <filename> [<count> [<skip>]]")) } - filename := args[0] - count := -1 - skip := 0 + mrtOpts.Filename = args[0] if len(args) > 1 { var err error - count, err = strconv.Atoi(args[1]) + mrtOpts.RecordCount, err = strconv.Atoi(args[1]) if err != nil { exitWithError(fmt.Errorf("invalid count value: %s", args[1])) } if len(args) > 2 { - skip, err = strconv.Atoi(args[2]) + mrtOpts.RecordSkip, err = strconv.Atoi(args[2]) if err != nil { exitWithError(fmt.Errorf("invalid skip value: %s", args[2])) } } + } else { + mrtOpts.RecordCount = -1 + mrtOpts.RecordSkip = 0 } - err := injectMrt(filename, count, skip) + err := injectMrt() if err != nil { exitWithError(err) } |