Skip to content

Commit

Permalink
Filter compose ps output by provided compose model
Browse files Browse the repository at this point in the history
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
  • Loading branch information
laurazard committed Aug 2, 2022
1 parent 5aba225 commit 3a7e5dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/compose/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ func psCommand(p *projectOptions, backend api.Service) *cobra.Command {
}

func runPs(ctx context.Context, backend api.Service, services []string, opts psOptions) error {
projectName, err := opts.toProjectName()
project, name, err := opts.projectOrName()
if err != nil {
return err
}
containers, err := backend.Ps(ctx, projectName, api.PsOptions{
containers, err := backend.Ps(ctx, name, api.PsOptions{
Project: project,
All: opts.All,
Services: services,
})
Expand Down
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ type ListOptions struct {

// PsOptions group options of the Ps API
type PsOptions struct {
Project *types.Project
All bool
Services []string
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/compose/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options api
return nil, err
}

project := options.Project
if project == nil {
project, err = s.getProjectWithResources(ctx, containers, projectName)
if err != nil {
return nil, err
}
}

if len(options.Services) == 0 {
options.Services = project.ServiceNames()
}

containers = containers.filter(isService(options.Services...))
summary := make([]api.ContainerSummary, len(containers))
eg, ctx := errgroup.WithContext(ctx)
for i, container := range containers {
Expand Down

0 comments on commit 3a7e5dd

Please sign in to comment.