Initial commit
This commit is contained in:
42
vendor/github.com/hyperhq/hypercli/api/client/save.go
generated
vendored
Normal file
42
vendor/github.com/hyperhq/hypercli/api/client/save.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
Cli "github.com/hyperhq/hypercli/cli"
|
||||
flag "github.com/hyperhq/hypercli/pkg/mflag"
|
||||
)
|
||||
|
||||
// CmdSave saves one or more images to a tar archive.
|
||||
//
|
||||
// The tar archive is written to STDOUT by default, or written to a file.
|
||||
//
|
||||
// Usage: docker save [OPTIONS] IMAGE [IMAGE...]
|
||||
func (cli *DockerCli) Save(args ...string) error {
|
||||
cmd := Cli.Subcmd("save", []string{"IMAGE [IMAGE...]"}, Cli.DockerCommands["save"].Description+" (streamed to STDOUT by default)", true)
|
||||
outfile := cmd.String([]string{"o", "-output"}, "", "Write to a file, instead of STDOUT")
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
if *outfile == "" && cli.isTerminalOut {
|
||||
return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
|
||||
}
|
||||
|
||||
responseBody, err := cli.client.ImageSave(context.Background(), cmd.Args())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer responseBody.Close()
|
||||
|
||||
if *outfile == "" {
|
||||
_, err := io.Copy(cli.out, responseBody)
|
||||
return err
|
||||
}
|
||||
|
||||
return copyToFile(*outfile, responseBody)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user