From e564282d76374d674bb1afb963d4a554b07544a4 Mon Sep 17 00:00:00 2001 From: "nick.grange" Date: Sun, 24 Jul 2016 00:36:59 +1000 Subject: [PATCH] add extra check for unexpected args to leave command --- command/leave.go | 6 ++++++ command/leave_test.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/command/leave.go b/command/leave.go index b402f9e35d..819e10d67d 100644 --- a/command/leave.go +++ b/command/leave.go @@ -33,6 +33,12 @@ func (c *LeaveCommand) Run(args []string) int { if err := cmdFlags.Parse(args); err != nil { return 1 } + nonFlagArgs := cmdFlags.Args() + if len(nonFlagArgs) > 0 { + c.Ui.Error(fmt.Sprintf("Error found unexpected args: %v", nonFlagArgs)) + c.Ui.Output(c.Help()) + return 1 + } client, err := RPCClient(*rpcAddr) if err != nil { diff --git a/command/leave_test.go b/command/leave_test.go index 2a5caaccd7..865df8e754 100644 --- a/command/leave_test.go +++ b/command/leave_test.go @@ -27,3 +27,17 @@ func TestLeaveCommandRun(t *testing.T) { t.Fatalf("bad: %#v", ui.OutputWriter.String()) } } + +func TestLeaveCommandFailOnNonFlagArgs(t *testing.T) { + a1 := testAgent(t) + defer a1.Shutdown() + + ui := new(cli.MockUi) + c := &LeaveCommand{Ui: ui} + args := []string{"-rpc-addr=" + a1.addr, "appserver1"} + + code := c.Run(args) + if code == 0 { + t.Fatalf("bad: failed to check for unexpected args") + } +}