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

Function runLoad

cli/command/image/load.go:55–101  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, opts loadOptions)

Source from the content-addressed store, hash-verified

53}
54
55func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error {
56 var input io.Reader = dockerCli.In()
57
58 // TODO(thaJeztah): add support for "-" as STDIN to match other commands, possibly making it a required positional argument.
59 switch opts.input {
60 case "":
61 // To avoid getting stuck, verify that a tar file is given either in
62 // the input flag or through stdin and if not display an error message and exit.
63 if dockerCli.In().IsTerminal() {
64 return errors.New("requested load from stdin, but stdin is empty")
65 }
66 default:
67 // We use sequential.Open to use sequential file access on Windows, avoiding
68 // depleting the standby list un-necessarily. On Linux, this equates to a regular os.Open.
69 file, err := sequential.Open(opts.input)
70 if err != nil {
71 return err
72 }
73 defer func() { _ = file.Close() }()
74 input = file
75 }
76
77 var options []client.ImageLoadOption
78 if opts.quiet || !dockerCli.Out().IsTerminal() {
79 options = append(options, client.ImageLoadWithQuiet(true))
80 }
81
82 platformList := []ocispec.Platform{}
83 for _, p := range opts.platform {
84 pp, err := platforms.Parse(p)
85 if err != nil {
86 return fmt.Errorf("invalid platform: %w", err)
87 }
88 platformList = append(platformList, pp)
89 }
90 if len(platformList) > 0 {
91 options = append(options, client.ImageLoadWithPlatforms(platformList...))
92 }
93
94 res, err := dockerCli.Client().ImageLoad(ctx, input, options...)
95 if err != nil {
96 return err
97 }
98 defer func() { _ = res.Close() }()
99
100 return jsonstream.Display(ctx, res, dockerCli.Out())
101}

Callers 1

newLoadCommandFunction · 0.85

Calls 6

ImageLoadMethod · 0.80
InMethod · 0.65
OutMethod · 0.65
ClientMethod · 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…