2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-03-24 23:57:23 -04:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdLoad loads an image from a tar archive.
|
|
|
|
//
|
|
|
|
// The tar archive is read from STDIN by default, or from a tar archive file.
|
|
|
|
//
|
|
|
|
// Usage: docker load [OPTIONS]
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdLoad(args ...string) error {
|
2015-05-05 00:18:28 -04:00
|
|
|
cmd := Cli.Subcmd("load", nil, "Load an image from a tar archive or STDIN", true)
|
2015-03-24 23:57:23 -04:00
|
|
|
infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN")
|
|
|
|
cmd.Require(flag.Exact, 0)
|
|
|
|
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
|
|
|
var (
|
|
|
|
input io.Reader = cli.in
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if *infile != "" {
|
|
|
|
input, err = os.Open(*infile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 14:23:44 -04:00
|
|
|
sopts := &streamOpts{
|
|
|
|
rawTerminal: true,
|
|
|
|
in: input,
|
|
|
|
out: cli.out,
|
|
|
|
}
|
2015-06-04 09:30:14 -04:00
|
|
|
if _, err := cli.stream("POST", "/images/load", sopts); err != nil {
|
2015-03-24 23:57:23 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|