From 7c0e865960fa595174bfc39c9c7af7f56d5a2b2f Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 30 Sep 2021 09:43:31 +0200 Subject: [PATCH] allow combination of --status and --services Signed-off-by: Nicolas De Loof --- cmd/compose/ps.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/compose/ps.go b/cmd/compose/ps.go index c32c39e90..d458aedb2 100644 --- a/cmd/compose/ps.go +++ b/cmd/compose/ps.go @@ -26,13 +26,13 @@ import ( "strings" "github.com/docker/compose/v2/cmd/formatter" + "github.com/docker/compose/v2/pkg/utils" formatter2 "github.com/docker/cli/cli/command/formatter" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/docker/compose/v2/pkg/api" - "github.com/docker/compose/v2/pkg/utils" ) type psOptions struct { @@ -103,17 +103,6 @@ func runPs(ctx context.Context, backend api.Service, services []string, opts psO 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: for _, s := range services { for _, c := range containers { @@ -139,6 +128,17 @@ SERVICES: 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, writter(containers), "NAME", "COMMAND", "SERVICE", "STATUS", "PORTS")