Merge pull request #1829 from ndeloof/ps_command

This commit is contained in:
Nicolas De loof 2021-06-23 08:28:47 +02:00 committed by GitHub
commit 99c39c8b3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 11 deletions

View File

@ -22,8 +22,10 @@ import (
"io"
"os"
"sort"
"strconv"
"strings"
formatter2 "github.com/docker/cli/cli/command/formatter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -141,10 +143,11 @@ func runPs(ctx context.Context, backend api.Service, services []string, opts psO
} else if status == "exited" || status == "dead" {
status = fmt.Sprintf("%s (%d)", container.State, container.ExitCode)
}
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", container.Name, container.Service, status, strings.Join(ports, ", "))
command := formatter2.Ellipsis(container.Command, 20)
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", container.Name, strconv.Quote(command), container.Service, status, strings.Join(ports, ", "))
}
},
"NAME", "SERVICE", "STATUS", "PORTS")
"NAME", "COMMAND", "SERVICE", "STATUS", "PORTS")
}
func filterByStatus(containers []api.ContainerSummary, status string) []api.ContainerSummary {

View File

@ -102,13 +102,13 @@ func TestLocalComposeUp(t *testing.T) {
t.Run("check healthcheck output", func(t *testing.T) {
c.WaitForCmdResult(c.NewDockerCmd("compose", "-p", projectName, "ps", "--format", "json"),
StdoutContains(`"Name":"compose-e2e-demo_web_1","Project":"compose-e2e-demo","Service":"web","State":"running","Health":"healthy"`),
StdoutContains(`"Name":"compose-e2e-demo_web_1","Command":"/dispatcher","Project":"compose-e2e-demo","Service":"web","State":"running","Health":"healthy"`),
5*time.Second, 1*time.Second)
res := c.RunDockerCmd("compose", "-p", projectName, "ps")
res.Assert(t, icmd.Expected{Out: `NAME SERVICE STATUS PORTS`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo_web_1 web running (healthy) 0.0.0.0:90->80/tcp`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo_db_1 db running 5432/tcp`})
res.Assert(t, icmd.Expected{Out: `NAME COMMAND SERVICE STATUS PORTS`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo_web_1 "/dispatcher" web running (healthy) 0.0.0.0:90->80/tcp, :::90->80/tcp`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo_db_1 "docker-entrypoint.s…" db running 5432/tcp`})
})
t.Run("images", func(t *testing.T) {

View File

@ -34,8 +34,8 @@ func TestRestart(t *testing.T) {
getServiceRegx := func(service string, status string) string {
// match output with random spaces like:
// e2e-start-stop_db_1 db running
return fmt.Sprintf("%s_%s_1\\s+%s\\s+%s", projectName, service, service, status)
// e2e-start-stop_db_1 "echo hello" db running
return fmt.Sprintf("%s_%s_1.+%s\\s+%s", projectName, service, service, status)
}
t.Run("Up a project", func(t *testing.T) {

View File

@ -39,8 +39,8 @@ func TestStartStop(t *testing.T) {
getServiceRegx := func(service string, status string) string {
// match output with random spaces like:
// e2e-start-stop_db_1 db running
return fmt.Sprintf("%s_%s_1\\s+%s\\s+%s", projectName, service, service, status)
// e2e-start-stop_db_1 "echo hello" db running
return fmt.Sprintf("%s_%s_1.+%s\\s+%s", projectName, service, service, status)
}
t.Run("Up a project", func(t *testing.T) {

View File

@ -285,6 +285,7 @@ type PortPublisher struct {
type ContainerSummary struct {
ID string
Name string
Command string
Project string
Service string
State string

View File

@ -21,8 +21,9 @@ import (
"fmt"
"sort"
"github.com/docker/compose-cli/pkg/api"
"golang.org/x/sync/errgroup"
"github.com/docker/compose-cli/pkg/api"
)
func (s *composeService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) {
@ -83,6 +84,7 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options api
Name: getCanonicalContainerName(container),
Project: container.Labels[api.ProjectLabel],
Service: container.Labels[api.ServiceLabel],
Command: container.Command,
State: container.State,
Health: health,
ExitCode: exitCode,