From 5049a5eb7b1e7d1b8cb8830db828a7b23bb1caf2 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Thu, 22 Jan 2015 11:20:32 -0800 Subject: [PATCH] command/maint: better arg conflict checking --- command/maint.go | 8 ++++++-- command/maint_test.go | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/command/maint.go b/command/maint.go index 4c89c34825..e1319db526 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 7b60f2b0db..92bf02b767 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) {