From b278d1de945fa0b140ee2a8038d12046bdbc77b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Sun, 4 May 2014 11:54:45 +0200 Subject: [PATCH] Return exit code 2 if member filter doesn't match any node --- command/members.go | 5 +++++ command/members_test.go | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/command/members.go b/command/members.go index f9244230a0..144d9739a7 100644 --- a/command/members.go +++ b/command/members.go @@ -102,6 +102,11 @@ func (c *MembersCommand) Run(args []string) int { result = append(result, line) } + // No matching members + if len(result) == 0 { + return 2 + } + // Generate the columnized version output := columnize.SimpleFormat(result) c.Ui.Output(string(output)) diff --git a/command/members_test.go b/command/members_test.go index 47a27ffb99..21a959f3e8 100644 --- a/command/members_test.go +++ b/command/members_test.go @@ -80,13 +80,17 @@ func TestMembersCommandRun_statusFilter_failed(t *testing.T) { } code := c.Run(args) - if code != 0 { + if code == 1 { t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) } if strings.Contains(ui.OutputWriter.String(), a1.config.NodeName) { t.Fatalf("bad: %#v", ui.OutputWriter.String()) } + + if code != 2 { + t.Fatalf("bad: %d", code) + } } func TestMembersCommandRun_roleFilter(t *testing.T) { @@ -122,11 +126,15 @@ func TestMembersCommandRun_roleFilter_failed(t *testing.T) { } code := c.Run(args) - if code != 0 { + if code == 1 { t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) } if strings.Contains(ui.OutputWriter.String(), a1.config.NodeName) { t.Fatalf("bad: %#v", ui.OutputWriter.String()) } + + if code != 2 { + t.Fatalf("bad: %d", code) + } }