allow combination of --status and --services

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-09-30 09:43:31 +02:00
parent 7365917244
commit 7c0e865960
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
1 changed files with 12 additions and 12 deletions

View File

@ -26,13 +26,13 @@ import (
"strings" "strings"
"github.com/docker/compose/v2/cmd/formatter" "github.com/docker/compose/v2/cmd/formatter"
"github.com/docker/compose/v2/pkg/utils"
formatter2 "github.com/docker/cli/cli/command/formatter" formatter2 "github.com/docker/cli/cli/command/formatter"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
) )
type psOptions struct { type psOptions struct {
@ -103,17 +103,6 @@ func runPs(ctx context.Context, backend api.Service, services []string, opts psO
return err return err
} }
if opts.Services {
services := []string{}
for _, s := range containers {
if !utils.StringContains(services, s.Service) {
services = append(services, s.Service)
}
}
fmt.Println(strings.Join(services, "\n"))
return nil
}
SERVICES: SERVICES:
for _, s := range services { for _, s := range services {
for _, c := range containers { for _, c := range containers {
@ -139,6 +128,17 @@ SERVICES:
return nil return nil
} }
if opts.Services {
services := []string{}
for _, s := range containers {
if !utils.StringContains(services, s.Service) {
services = append(services, s.Service)
}
}
fmt.Println(strings.Join(services, "\n"))
return nil
}
return formatter.Print(containers, opts.Format, os.Stdout, return formatter.Print(containers, opts.Format, os.Stdout,
writter(containers), writter(containers),
"NAME", "COMMAND", "SERVICE", "STATUS", "PORTS") "NAME", "COMMAND", "SERVICE", "STATUS", "PORTS")