mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
return err when stack name does not exist
Signed-off-by: allencloud <allen.sun@daocloud.io>
This commit is contained in:
parent
bd37b83052
commit
416613f2e5
6 changed files with 44 additions and 3 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
28
integration-cli/docker_cli_stack_test.go
Normal file
28
integration-cli/docker_cli_stack_test.go
Normal file
|
@ -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")
|
||||
}
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in a new issue