diff --git a/api/client/node/cmd.go b/api/client/node/cmd.go index 0588f1ee1d..96c8e5bc09 100644 --- a/api/client/node/cmd.go +++ b/api/client/node/cmd.go @@ -35,7 +35,7 @@ func NewNodeCommand(dockerCli *client.DockerCli) *cobra.Command { return cmd } -// Reference return the reference of a node. The special value "self" for a node +// Reference returns the reference of a node. The special value "self" for a node // reference is mapped to the current node, hence the node ID is retrieved using // the `/info` endpoint. func Reference(client apiclient.APIClient, ctx context.Context, ref string) (string, error) { diff --git a/api/client/stack/cmd.go b/api/client/stack/cmd.go index c095441b9c..82a7a1ffa6 100644 --- a/api/client/stack/cmd.go +++ b/api/client/stack/cmd.go @@ -29,7 +29,7 @@ func NewStackCommand(dockerCli *client.DockerCli) *cobra.Command { return cmd } -// NewTopLevelDeployCommand return a command for `docker deploy` +// NewTopLevelDeployCommand returns a command for `docker deploy` func NewTopLevelDeployCommand(dockerCli *client.DockerCli) *cobra.Command { cmd := newDeployCommand(dockerCli) // Remove the aliases at the top level diff --git a/api/client/stack/remove.go b/api/client/stack/remove.go index 1d066d42e6..9ba91e5c23 100644 --- a/api/client/stack/remove.go +++ b/api/client/stack/remove.go @@ -63,6 +63,11 @@ func runRemove(dockerCli *client.DockerCli, opts removeOptions) error { } } + if len(services) == 0 && len(networks) == 0 { + fmt.Fprintf(dockerCli.Out(), "Nothing found in stack: %s\n", namespace) + return nil + } + if hasError { return fmt.Errorf("Failed to remove some resources") } diff --git a/api/client/stack/tasks.go b/api/client/stack/tasks.go index f9546bde4b..85fa0f6cb7 100644 --- a/api/client/stack/tasks.go +++ b/api/client/stack/tasks.go @@ -3,6 +3,8 @@ package stack import ( + "fmt" + "golang.org/x/net/context" "github.com/docker/docker/api/client" @@ -43,6 +45,7 @@ func newTasksCommand(dockerCli *client.DockerCli) *cobra.Command { } func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error { + namespace := opts.namespace client := dockerCli.Client() ctx := context.Background() @@ -58,5 +61,10 @@ func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error { return err } + if len(tasks) == 0 { + fmt.Fprintf(dockerCli.Out(), "Nothing found in stack: %s\n", namespace) + return nil + } + return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve)) } diff --git a/integration-cli/docker_cli_stack_test.go b/integration-cli/docker_cli_stack_test.go new file mode 100644 index 0000000000..cbfa588a14 --- /dev/null +++ b/integration-cli/docker_cli_stack_test.go @@ -0,0 +1,28 @@ +// +build experimental + +package main + +import ( + "github.com/docker/docker/pkg/integration/checker" + "github.com/go-check/check" +) + +func (s *DockerSwarmSuite) TestStackRemove(c *check.C) { + d := s.AddDaemon(c, true, true) + + stackArgs := append([]string{"remove", "UNKNOWN_STACK"}) + + out, err := d.Cmd("stack", stackArgs...) + c.Assert(err, checker.IsNil) + c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n") +} + +func (s *DockerSwarmSuite) TestStackTasks(c *check.C) { + d := s.AddDaemon(c, true, true) + + stackArgs := append([]string{"tasks", "UNKNOWN_STACK"}) + + out, err := d.Cmd("stack", stackArgs...) + c.Assert(err, checker.IsNil) + c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n") +} diff --git a/pkg/integration/checker/checker.go b/pkg/integration/checker/checker.go index a5314994cd..d1b703a599 100644 --- a/pkg/integration/checker/checker.go +++ b/pkg/integration/checker/checker.go @@ -1,4 +1,4 @@ -// Package checker provide Docker specific implementations of the go-check.Checker interface. +// Package checker provides Docker specific implementations of the go-check.Checker interface. package checker import (