(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, services []string, options volumesOptions)
| 57 | } |
| 58 | |
| 59 | func runVol(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, services []string, options volumesOptions) error { |
| 60 | project, name, err := options.projectOrName(ctx, dockerCli, services...) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | if project != nil { |
| 66 | names := project.ServiceNames() |
| 67 | for _, service := range services { |
| 68 | if !slices.Contains(names, service) { |
| 69 | return fmt.Errorf("no such service: %s", service) |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...) |
| 75 | if err != nil { |
| 76 | return err |
| 77 | } |
| 78 | volumes, err := backend.Volumes(ctx, name, api.VolumesOptions{ |
| 79 | Services: services, |
| 80 | }) |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | |
| 85 | if options.Quiet { |
| 86 | for _, v := range volumes { |
| 87 | _, _ = fmt.Fprintln(dockerCli.Out(), v.Name) |
| 88 | } |
| 89 | return nil |
| 90 | } |
| 91 | |
| 92 | volumeCtx := formatter.Context{ |
| 93 | Output: dockerCli.Out(), |
| 94 | Format: formatter.NewVolumeFormat(options.Format, options.Quiet), |
| 95 | } |
| 96 | |
| 97 | return formatter.VolumeWrite(volumeCtx, volumes) |
| 98 | } |
no test coverage detected