github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/api/client/load.go (about) 1 package client 2 3 import ( 4 "io" 5 "os" 6 7 "golang.org/x/net/context" 8 9 Cli "github.com/docker/docker/cli" 10 "github.com/docker/docker/pkg/jsonmessage" 11 flag "github.com/docker/docker/pkg/mflag" 12 ) 13 14 // CmdLoad loads an image from a tar archive. 15 // 16 // The tar archive is read from STDIN by default, or from a tar archive file. 17 // 18 // Usage: docker load [OPTIONS] 19 func (cli *DockerCli) CmdLoad(args ...string) error { 20 cmd := Cli.Subcmd("load", nil, Cli.DockerCommands["load"].Description, true) 21 infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN") 22 quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Suppress the load output") 23 cmd.Require(flag.Exact, 0) 24 cmd.ParseFlags(args, true) 25 26 var input io.Reader = cli.in 27 if *infile != "" { 28 file, err := os.Open(*infile) 29 if err != nil { 30 return err 31 } 32 defer file.Close() 33 input = file 34 } 35 if !cli.isTerminalOut { 36 *quiet = true 37 } 38 response, err := cli.client.ImageLoad(context.Background(), input, *quiet) 39 if err != nil { 40 return err 41 } 42 defer response.Body.Close() 43 44 if response.Body != nil && response.JSON { 45 return jsonmessage.DisplayJSONMessagesStream(response.Body, cli.out, cli.outFd, cli.isTerminalOut, nil) 46 } 47 48 _, err = io.Copy(cli.out, response.Body) 49 return err 50 }