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")
return 1
}
if disable && reason != "" {
if !enable && reason != "" {
c.Ui.Error("Reason may only be provided with -enable")
return 1
}
if !enable && !disable && serviceID != "" {
c.Ui.Error("Service requires either -enable or -disable")
return 1
}
// Create and test the HTTP client
conf := api.DefaultConfig()
@ -103,7 +107,7 @@ func (c *MaintCommand) Run(args []string) int {
// List mode - list nodes/services in maintenance mode
checks, err := a.Checks()
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
}

View File

@ -23,6 +23,14 @@ func TestMaintCommandRun_ConflictingArgs(t *testing.T) {
if code := c.Run([]string{"-disable", "-reason=broken"}); code != 1 {
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) {