command/maint: better arg conflict checking

This commit is contained in:
Ryan Uber 2015-01-22 11:20:32 -08:00
parent 17d2443f91
commit ae672b32f6
2 changed files with 14 additions and 2 deletions

View file

@ -78,10 +78,14 @@ func (c *MaintCommand) Run(args []string) int {
c.Ui.Error("Only one of -enable or -disable may be provided") c.Ui.Error("Only one of -enable or -disable may be provided")
return 1 return 1
} }
if disable && reason != "" { if !enable && reason != "" {
c.Ui.Error("Reason may only be provided with -enable") c.Ui.Error("Reason may only be provided with -enable")
return 1 return 1
} }
if !enable && !disable && serviceID != "" {
c.Ui.Error("Service requires either -enable or -disable")
return 1
}
// Create and test the HTTP client // Create and test the HTTP client
conf := api.DefaultConfig() conf := api.DefaultConfig()
@ -103,7 +107,7 @@ func (c *MaintCommand) Run(args []string) int {
// List mode - list nodes/services in maintenance mode // List mode - list nodes/services in maintenance mode
checks, err := a.Checks() checks, err := a.Checks()
if err != nil { if err != nil {
c.Ui.Output(fmt.Sprintf("Error getting checks: %s", err)) c.Ui.Error(fmt.Sprintf("Error getting checks: %s", err))
return 1 return 1
} }

View file

@ -23,6 +23,14 @@ func TestMaintCommandRun_ConflictingArgs(t *testing.T) {
if code := c.Run([]string{"-disable", "-reason=broken"}); code != 1 { if code := c.Run([]string{"-disable", "-reason=broken"}); code != 1 {
t.Fatalf("expected return code 1, got %d", code) t.Fatalf("expected return code 1, got %d", code)
} }
if code := c.Run([]string{"-reason=broken"}); code != 1 {
t.Fatalf("expected return code 1, got %d", code)
}
if code := c.Run([]string{"-service=redis"}); code != 1 {
t.Fatalf("expected return code 1, got %d", code)
}
} }
func TestMaintCommandRun_NoArgs(t *testing.T) { func TestMaintCommandRun_NoArgs(t *testing.T) {