Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit b5ac318

Browse files
authored
Merge pull request #1218 from docker/ps_all
Introduce --all option on compose ps
2 parents 6215445 + 9b282b6 commit b5ac318

File tree

9 files changed

+27
-16
lines changed

9 files changed

+27
-16
lines changed

aci/compose.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,19 @@ func (cs *aciComposeService) Down(ctx context.Context, projectName string, optio
124124
return err
125125
}
126126

127-
func (cs *aciComposeService) Ps(ctx context.Context, project string) ([]compose.ContainerSummary, error) {
127+
func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
128128
groupsClient, err := login.NewContainerGroupsClient(cs.ctx.SubscriptionID)
129129
if err != nil {
130130
return nil, err
131131
}
132132

133-
group, err := groupsClient.Get(ctx, cs.ctx.ResourceGroup, project)
133+
group, err := groupsClient.Get(ctx, cs.ctx.ResourceGroup, projectName)
134134
if err != nil {
135135
return nil, err
136136
}
137137

138138
if group.Containers == nil || len(*group.Containers) == 0 {
139-
return nil, fmt.Errorf("no containers found in ACI container group %s", project)
139+
return nil, fmt.Errorf("no containers found in ACI container group %s", projectName)
140140
}
141141

142142
res := []compose.ContainerSummary{}
@@ -158,7 +158,7 @@ func (cs *aciComposeService) Ps(ctx context.Context, project string) ([]compose.
158158
res = append(res, compose.ContainerSummary{
159159
ID: id,
160160
Name: id,
161-
Project: project,
161+
Project: projectName,
162162
Service: *container.Name,
163163
State: convert.GetStatus(container, group),
164164
Publishers: publishers,

api/client/compose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (c *composeService) Logs(context.Context, string, compose.LogConsumer, comp
6464
return errdefs.ErrNotImplemented
6565
}
6666

67-
func (c *composeService) Ps(context.Context, string) ([]compose.ContainerSummary, error) {
67+
func (c *composeService) Ps(context.Context, string, compose.PsOptions) ([]compose.ContainerSummary, error) {
6868
return nil, errdefs.ErrNotImplemented
6969
}
7070

api/compose/api.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Service interface {
4444
// Logs executes the equivalent to a `compose logs`
4545
Logs(ctx context.Context, projectName string, consumer LogConsumer, options LogOptions) error
4646
// Ps executes the equivalent to a `compose ps`
47-
Ps(ctx context.Context, projectName string) ([]ContainerSummary, error)
47+
Ps(ctx context.Context, projectName string, options PsOptions) ([]ContainerSummary, error)
4848
// List executes the equivalent to a `docker stack ls`
4949
List(ctx context.Context) ([]Stack, error)
5050
// Convert translate compose model into backend's native format
@@ -91,6 +91,11 @@ type RunOptions struct {
9191
Reader io.Reader
9292
}
9393

94+
// PsOptions group options of the Ps API
95+
type PsOptions struct {
96+
All bool
97+
}
98+
9499
// PortPublisher hold status about published port
95100
type PortPublisher struct {
96101
URL string

cli/cmd/compose/ps.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ import (
2727
"github.com/spf13/cobra"
2828

2929
"github.com/docker/compose-cli/api/client"
30+
"github.com/docker/compose-cli/api/compose"
3031
"github.com/docker/compose-cli/cli/formatter"
3132
)
3233

3334
type psOptions struct {
3435
*projectOptions
3536
Format string
37+
All bool
3638
Quiet bool
3739
}
3840

@@ -49,6 +51,7 @@ func psCommand(p *projectOptions) *cobra.Command {
4951
}
5052
psCmd.Flags().StringVar(&opts.Format, "format", "pretty", "Format the output. Values: [pretty | json].")
5153
psCmd.Flags().BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs")
54+
psCmd.Flags().BoolVarP(&opts.All, "all", "a", false, "Show all stopped containers (including those created by the run command)")
5255
return psCmd
5356
}
5457

@@ -62,7 +65,9 @@ func runPs(ctx context.Context, opts psOptions) error {
6265
if err != nil {
6366
return err
6467
}
65-
containers, err := c.ComposeService().Ps(ctx, projectName)
68+
containers, err := c.ComposeService().Ps(ctx, projectName, compose.PsOptions{
69+
All: opts.All,
70+
})
6671
if err != nil {
6772
return err
6873
}

cli/server/proxy/compose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (p *proxy) Services(ctx context.Context, request *composev1.ComposeServices
5959
projectName = project.Name
6060
}
6161
response := []*composev1.Service{}
62-
_, err := Client(ctx).ComposeService().Ps(ctx, projectName)
62+
_, err := Client(ctx).ComposeService().Ps(ctx, projectName, compose.PsOptions{})
6363
if err != nil {
6464
return nil, err
6565
}

ecs/local/compose.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ func (e ecsLocalSimulation) Logs(ctx context.Context, projectName string, consum
162162
return e.compose.Logs(ctx, projectName, consumer, options)
163163
}
164164

165-
func (e ecsLocalSimulation) Ps(ctx context.Context, projectName string) ([]compose.ContainerSummary, error) {
166-
return e.compose.Ps(ctx, projectName)
165+
func (e ecsLocalSimulation) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
166+
return e.compose.Ps(ctx, projectName, options)
167167
}
168168
func (e ecsLocalSimulation) List(ctx context.Context) ([]compose.Stack, error) {
169169
return e.compose.List(ctx)

ecs/ps.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import (
2222
"github.com/docker/compose-cli/api/compose"
2323
)
2424

25-
func (b *ecsAPIService) Ps(ctx context.Context, project string) ([]compose.ContainerSummary, error) {
26-
cluster, err := b.aws.GetStackClusterID(ctx, project)
25+
func (b *ecsAPIService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
26+
cluster, err := b.aws.GetStackClusterID(ctx, projectName)
2727
if err != nil {
2828
return nil, err
2929
}
30-
servicesARN, err := b.aws.ListStackServices(ctx, project)
30+
servicesARN, err := b.aws.ListStackServices(ctx, projectName)
3131
if err != nil {
3232
return nil, err
3333
}
@@ -43,7 +43,7 @@ func (b *ecsAPIService) Ps(ctx context.Context, project string) ([]compose.Conta
4343
return nil, err
4444
}
4545

46-
tasks, err := b.aws.DescribeServiceTasks(ctx, cluster, project, service.Name)
46+
tasks, err := b.aws.DescribeServiceTasks(ctx, cluster, projectName, service.Name)
4747
if err != nil {
4848
return nil, err
4949
}

kube/compose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
9494
}
9595

9696
// Ps executes the equivalent to a `compose ps`
97-
func (s *composeService) Ps(ctx context.Context, projectName string) ([]compose.ContainerSummary, error) {
97+
func (s *composeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
9898
return nil, errdefs.ErrNotImplemented
9999
}
100100

local/compose/ps.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ import (
2727
"github.com/docker/compose-cli/api/compose"
2828
)
2929

30-
func (s *composeService) Ps(ctx context.Context, projectName string) ([]compose.ContainerSummary, error) {
30+
func (s *composeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
3131
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
3232
Filters: filters.NewArgs(
3333
projectFilter(projectName),
3434
),
35+
All: options.All,
3536
})
3637
if err != nil {
3738
return nil, err

0 commit comments

Comments
 (0)