diff --git a/command/maint.go b/command/maint.go index 4c89c3482..e1319db52 100644 --- a/command/maint.go +++ b/command/maint.go @@ -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 } diff --git a/command/maint_test.go b/command/maint_test.go index 7b60f2b0d..92bf02b76 100644 --- a/command/maint_test.go +++ b/command/maint_test.go @@ -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) {