|
@@ -49,16 +49,15 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
|
func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
|
|
ctx := context.Background()
|
|
|
client := dockerCli.Client()
|
|
|
+ out := dockerCli.Out()
|
|
|
|
|
|
services, err := client.ServiceList(ctx, types.ServiceListOptions{Filter: opts.filter.Value()})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- out := dockerCli.Out()
|
|
|
- if opts.quiet {
|
|
|
- PrintQuiet(out, services)
|
|
|
- } else {
|
|
|
+ if len(services) > 0 && !opts.quiet {
|
|
|
+ // only non-empty services and not quiet, should we call TaskList and NodeList api
|
|
|
taskFilter := filters.NewArgs()
|
|
|
for _, service := range services {
|
|
|
taskFilter.Add("service", service.ID)
|
|
@@ -75,7 +74,13 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|