From 79f9af24751f05666f1fb2611aac31fa8884b8cb Mon Sep 17 00:00:00 2001 From: Boaz Shuster Date: Wed, 30 Aug 2017 13:47:53 +0300 Subject: [PATCH] When nothing found in stack exit with exit code 1 To keep on a consistent behaviour such as in docker-service-ps if docker-stack-ps didn't find a given stack, the command line should exit with exit code 1. Signed-off-by: Boaz Shuster --- cli/command/stack/ps.go | 3 +-- cli/command/stack/ps_test.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cli/command/stack/ps.go b/cli/command/stack/ps.go index 25bd1eee10..d586b1e1e4 100644 --- a/cli/command/stack/ps.go +++ b/cli/command/stack/ps.go @@ -57,8 +57,7 @@ func runPS(dockerCli command.Cli, options psOptions) error { } if len(tasks) == 0 { - fmt.Fprintf(dockerCli.Err(), "Nothing found in stack: %s\n", namespace) - return nil + return fmt.Errorf("nothing found in stack: %s", namespace) } format := options.format diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index 282e5e01da..3bb22609b5 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -60,9 +60,9 @@ func TestStackPsEmptyStack(t *testing.T) { cmd := newPsCommand(fakeCli) cmd.SetArgs([]string{"foo"}) - assert.NoError(t, cmd.Execute()) + assert.Error(t, cmd.Execute()) + assert.EqualError(t, cmd.Execute(), "nothing found in stack: foo") assert.Equal(t, "", fakeCli.OutBuffer().String()) - assert.Equal(t, "Nothing found in stack: foo\n", fakeCli.ErrBuffer().String()) } func TestStackPsWithQuietOption(t *testing.T) {