MCPcopy
hub / github.com/docker/compose / runPs

Function runPs

cmd/compose/ps.go:95–165  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, services []string, opts psOptions)

Source from the content-addressed store, hash-verified

93}
94
95func runPs(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, services []string, opts psOptions) error { //nolint:gocyclo
96 project, name, err := opts.projectOrName(ctx, dockerCli, services...)
97 if err != nil {
98 return err
99 }
100
101 if project != nil {
102 names := project.ServiceNames()
103 if len(services) > 0 {
104 for _, service := range services {
105 if !slices.Contains(names, service) {
106 return fmt.Errorf("no such service: %s", service)
107 }
108 }
109 } else if !opts.Orphans {
110 // until user asks to list orphaned services, we only include those declared in project
111 services = names
112 }
113 }
114
115 backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
116 if err != nil {
117 return err
118 }
119 containers, err := backend.Ps(ctx, name, api.PsOptions{
120 Project: project,
121 All: opts.All || len(opts.Status) != 0,
122 Services: services,
123 })
124 if err != nil {
125 return err
126 }
127
128 if len(opts.Status) != 0 {
129 containers = filterByStatus(containers, opts.Status)
130 }
131
132 sort.Slice(containers, func(i, j int) bool {
133 return containers[i].Name < containers[j].Name
134 })
135
136 if opts.Quiet {
137 for _, c := range containers {
138 _, _ = fmt.Fprintln(dockerCli.Out(), c.ID)
139 }
140 return nil
141 }
142
143 if opts.Services {
144 services := []string{}
145 for _, c := range containers {
146 s := c.Service
147 if !slices.Contains(services, s) {
148 services = append(services, s)
149 }
150 }
151 _, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(services, "\n"))
152 return nil

Callers 1

psCommandFunction · 0.85

Calls 8

NewComposeServiceFunction · 0.92
NewContainerFormatFunction · 0.92
ContainerWriteFunction · 0.92
filterByStatusFunction · 0.85
projectOrNameMethod · 0.80
PsMethod · 0.65
OutMethod · 0.45
ConfigFileMethod · 0.45

Tested by

no test coverage detected