(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions)
| 40 | } |
| 41 | |
| 42 | func copyCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command { |
| 43 | opts := copyOptions{ |
| 44 | ProjectOptions: p, |
| 45 | } |
| 46 | copyCmd := &cobra.Command{ |
| 47 | Use: `cp [OPTIONS] SERVICE:SRC_PATH DEST_PATH|- |
| 48 | docker compose cp [OPTIONS] SRC_PATH|- SERVICE:DEST_PATH`, |
| 49 | Short: "Copy files/folders between a service container and the local filesystem", |
| 50 | Args: cli.ExactArgs(2), |
| 51 | PreRunE: Adapt(func(ctx context.Context, args []string) error { |
| 52 | if args[0] == "" { |
| 53 | return errors.New("source can not be empty") |
| 54 | } |
| 55 | if args[1] == "" { |
| 56 | return errors.New("destination can not be empty") |
| 57 | } |
| 58 | return nil |
| 59 | }), |
| 60 | RunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error { |
| 61 | opts.source = args[0] |
| 62 | opts.destination = args[1] |
| 63 | return runCopy(ctx, dockerCli, backendOptions, opts) |
| 64 | }), |
| 65 | ValidArgsFunction: completeServiceNames(dockerCli, p), |
| 66 | } |
| 67 | |
| 68 | flags := copyCmd.Flags() |
| 69 | flags.IntVar(&opts.index, "index", 0, "Index of the container if service has multiple replicas") |
| 70 | flags.BoolVar(&opts.all, "all", false, "Include containers created by the run command") |
| 71 | flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symbol link in SRC_PATH") |
| 72 | flags.BoolVarP(&opts.copyUIDGID, "archive", "a", false, "Archive mode (copy all uid/gid information)") |
| 73 | |
| 74 | return copyCmd |
| 75 | } |
| 76 | |
| 77 | func runCopy(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts copyOptions) error { |
| 78 | name, err := opts.toProjectName(ctx, dockerCli) |
no test coverage detected