Browse Source

Merge pull request #2207 from grange74/leave-command-args-check

add extra check for unexpected args to leave command
pull/2211/head
James Phillips 8 years ago committed by GitHub
parent
commit
2de8a3f7fb
  1. 6
      command/leave.go
  2. 14
      command/leave_test.go

6
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 {

14
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")
}
}

Loading…
Cancel
Save