diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-01-11 09:27:16 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-01-12 21:36:57 +0900 |
commit | 91beb15057e951ec7376218a4d6e176f061d6d7e (patch) | |
tree | 9ba705047a8d314e54bfb5f3abee0f067eabab30 | |
parent | 5ef8b8db3fd783a55a853febe1e274702056549a (diff) |
client: Make MonitorNeighborState to get single argument
Currently, Client.MonitorNeighborState uses only first neighbor address
even if it take variable length arguments (the second and following
neighbor address is ignored implicitly).
This patch fixes this function to take a single neighbor address and
prevents user confusion.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r-- | client/client.go | 9 | ||||
-rw-r--r-- | gobgp/cmd/monitor.go | 12 |
2 files changed, 10 insertions, 11 deletions
diff --git a/client/client.go b/client/client.go index 90de1c60..a48f3c17 100644 --- a/client/client.go +++ b/client/client.go @@ -993,14 +993,7 @@ func (c *MonitorNeighborStateClient) Recv() (*config.Neighbor, error) { return api.NewNeighborFromAPIStruct(p) } -func (cli *Client) MonitorNeighborState(names ...string) (*MonitorNeighborStateClient, error) { - if len(names) > 1 { - return nil, fmt.Errorf("support one name at most: %d", len(names)) - } - name := "" - if len(names) > 0 { - name = names[0] - } +func (cli *Client) MonitorNeighborState(name string) (*MonitorNeighborStateClient, error) { stream, err := cli.cli.MonitorPeerState(context.Background(), &api.Arguments{ Name: name, }) diff --git a/gobgp/cmd/monitor.go b/gobgp/cmd/monitor.go index d62f98cb..9a0f25b6 100644 --- a/gobgp/cmd/monitor.go +++ b/gobgp/cmd/monitor.go @@ -21,9 +21,10 @@ import ( "io" "net" + "github.com/spf13/cobra" + "github.com/osrg/gobgp/packet/bgp" "github.com/osrg/gobgp/table" - "github.com/spf13/cobra" ) func makeMonitorRouteArgs(p *table.Path, showIdentifier bgp.BGPAddPathMode) []interface{} { @@ -122,9 +123,14 @@ func NewMonitorCmd() *cobra.Command { globalCmd.AddCommand(ribCmd) neighborCmd := &cobra.Command{ - Use: CMD_NEIGHBOR, + Use: fmt.Sprintf("%s [<neighbor address>]", CMD_NEIGHBOR), + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - stream, err := client.MonitorNeighborState(args...) + name := "" + if len(args) > 0 { + name = args[0] + } + stream, err := client.MonitorNeighborState(name) if err != nil { exitWithError(err) } |