MCPcopy Index your code
hub / github.com/docker/cli / newCopyCommand

Function newCopyCommand

cli/command/container/cp.go:125–165  ·  view source on GitHub ↗

newCopyCommand creates a new `docker cp` command

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

123
124// newCopyCommand creates a new `docker cp` command
125func 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
134Use '-' as the source to read a tar archive from stdin
135and extract it to a directory destination in a container.
136Use '-' as the destination to stream a tar archive of a
137container 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
167func progressHumanSize(n int64) string {
168 return units.HumanSizeWithPrecision(float64(n), 3)

Callers 1

newContainerCommandFunction · 0.85

Calls 3

runCopyFunction · 0.85
OutMethod · 0.65
IsTerminalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…