newCopyCommand creates a new `docker cp` command
(dockerCLI command.Cli)
| 123 | |
| 124 | // newCopyCommand creates a new `docker cp` command |
| 125 | func newCopyCommand(dockerCLI command.Cli) *cobra.Command { |
| 126 | var opts copyOptions |
| 127 | |
| 128 | cmd := &cobra.Command{ |
| 129 | Use: `cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- |
| 130 | docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH`, |
| 131 | Short: "Copy files/folders between a container and the local filesystem", |
| 132 | Long: `Copy files/folders between a container and the local filesystem |
| 133 | |
| 134 | Use '-' as the source to read a tar archive from stdin |
| 135 | and extract it to a directory destination in a container. |
| 136 | Use '-' as the destination to stream a tar archive of a |
| 137 | container source to stdout.`, |
| 138 | Args: cli.ExactArgs(2), |
| 139 | RunE: func(cmd *cobra.Command, args []string) error { |
| 140 | if args[0] == "" { |
| 141 | return errors.New("source can not be empty") |
| 142 | } |
| 143 | if args[1] == "" { |
| 144 | return errors.New("destination can not be empty") |
| 145 | } |
| 146 | opts.source = args[0] |
| 147 | opts.destination = args[1] |
| 148 | if !cmd.Flag("quiet").Changed { |
| 149 | // User did not specify "quiet" flag; suppress output if no terminal is attached |
| 150 | opts.quiet = !dockerCLI.Out().IsTerminal() |
| 151 | } |
| 152 | return runCopy(cmd.Context(), dockerCLI, opts) |
| 153 | }, |
| 154 | Annotations: map[string]string{ |
| 155 | "aliases": "docker container cp, docker cp", |
| 156 | }, |
| 157 | DisableFlagsInUseLine: true, |
| 158 | } |
| 159 | |
| 160 | flags := cmd.Flags() |
| 161 | flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symlinks in SRC_PATH") |
| 162 | flags.BoolVarP(&opts.copyUIDGID, "archive", "a", false, "Archive mode (copy all uid/gid information)") |
| 163 | flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress progress output during copy. Progress output is automatically suppressed if no terminal is attached") |
| 164 | return cmd |
| 165 | } |
| 166 | |
| 167 | func progressHumanSize(n int64) string { |
| 168 | return units.HumanSizeWithPrecision(float64(n), 3) |
no test coverage detected
searching dependent graphs…