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

Function runVol

cmd/compose/volumes.go:59–98  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, services []string, options volumesOptions)

Source from the content-addressed store, hash-verified

57}
58
59func 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}

Callers 1

volumesCommandFunction · 0.85

Calls 4

NewComposeServiceFunction · 0.92
projectOrNameMethod · 0.80
VolumesMethod · 0.65
OutMethod · 0.45

Tested by

no test coverage detected