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