mirror of https://github.com/docker/cli.git
Merge pull request #27236 from allencloud/return-nil-when-no-node-or-service
return nil when no node or service to avoid additional api call
This commit is contained in:
commit
cfc3b1a3ff
|
@ -45,6 +45,7 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
|
|
||||||
func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
||||||
client := dockerCli.Client()
|
client := dockerCli.Client()
|
||||||
|
out := dockerCli.Out()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
nodes, err := client.NodeList(
|
nodes, err := client.NodeList(
|
||||||
|
@ -54,17 +55,20 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := client.Info(ctx)
|
if len(nodes) > 0 && !opts.quiet {
|
||||||
if err != nil {
|
// only non-empty nodes and not quiet, should we call /info api
|
||||||
return err
|
info, err := client.Info(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
printTable(out, nodes, info)
|
||||||
|
} else if !opts.quiet {
|
||||||
|
// no nodes and not quiet, print only one line with columns ID, HOSTNAME, ...
|
||||||
|
printTable(out, nodes, types.Info{})
|
||||||
|
} else {
|
||||||
|
printQuiet(out, nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
out := dockerCli.Out()
|
|
||||||
if opts.quiet {
|
|
||||||
printQuiet(out, nodes)
|
|
||||||
} else {
|
|
||||||
printTable(out, nodes, info)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,16 +49,15 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client := dockerCli.Client()
|
client := dockerCli.Client()
|
||||||
|
out := dockerCli.Out()
|
||||||
|
|
||||||
services, err := client.ServiceList(ctx, types.ServiceListOptions{Filter: opts.filter.Value()})
|
services, err := client.ServiceList(ctx, types.ServiceListOptions{Filter: opts.filter.Value()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
out := dockerCli.Out()
|
if len(services) > 0 && !opts.quiet {
|
||||||
if opts.quiet {
|
// only non-empty services and not quiet, should we call TaskList and NodeList api
|
||||||
PrintQuiet(out, services)
|
|
||||||
} else {
|
|
||||||
taskFilter := filters.NewArgs()
|
taskFilter := filters.NewArgs()
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
taskFilter.Add("service", service.ID)
|
taskFilter.Add("service", service.ID)
|
||||||
|
@ -75,7 +74,13 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintNotQuiet(out, services, nodes, tasks)
|
PrintNotQuiet(out, services, nodes, tasks)
|
||||||
|
} else if !opts.quiet {
|
||||||
|
// no services and not quiet, print only one line with columns ID, NAME, REPLICAS...
|
||||||
|
PrintNotQuiet(out, services, []swarm.Node{}, []swarm.Task{})
|
||||||
|
} else {
|
||||||
|
PrintQuiet(out, services)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,14 +58,14 @@ func PrettyPrint(i interface{}) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PromptForConfirmation request and check confirmation from user.
|
// PromptForConfirmation requests and checks confirmation from user.
|
||||||
// This will display the provided message followed by ' [y/N] '. If
|
// This will display the provided message followed by ' [y/N] '. If
|
||||||
// the user input 'y' or 'Y' it returns true other false. If no
|
// the user input 'y' or 'Y' it returns true other false. If no
|
||||||
// message is provided "Are you sure you want to proceeed? [y/N] "
|
// message is provided "Are you sure you want to proceed? [y/N] "
|
||||||
// will be used instead.
|
// will be used instead.
|
||||||
func PromptForConfirmation(ins *InStream, outs *OutStream, message string) bool {
|
func PromptForConfirmation(ins *InStream, outs *OutStream, message string) bool {
|
||||||
if message == "" {
|
if message == "" {
|
||||||
message = "Are you sure you want to proceeed?"
|
message = "Are you sure you want to proceed?"
|
||||||
}
|
}
|
||||||
message += " [y/N] "
|
message += " [y/N] "
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue