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

Function writeTo

cli/command/context/export.go:35–59  ·  view source on GitHub ↗
(dockerCli command.Cli, reader io.Reader, dest string)

Source from the content-addressed store, hash-verified

33}
34
35func writeTo(dockerCli command.Cli, reader io.Reader, dest string) error {
36 var writer io.Writer
37 var printDest bool
38 if dest == "-" {
39 if dockerCli.Out().IsTerminal() {
40 return errors.New("cowardly refusing to export to a terminal, specify a file path")
41 }
42 writer = dockerCli.Out()
43 } else {
44 f, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600)
45 if err != nil {
46 return err
47 }
48 defer f.Close()
49 writer = f
50 printDest = true
51 }
52 if _, err := io.Copy(writer, reader); err != nil {
53 return err
54 }
55 if printDest {
56 fmt.Fprintf(dockerCli.Err(), "Written file %q\n", dest)
57 }
58 return nil
59}
60
61// runExport exports a Docker context.
62func runExport(dockerCLI command.Cli, contextName string, dest string) error {

Callers 1

runExportFunction · 0.85

Calls 4

OutMethod · 0.65
ErrMethod · 0.65
IsTerminalMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…