mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
![Tibor Vass](/assets/img/avatar_default.png)
This patch creates a new cli package that allows to combine both client and daemon commands (there is only one daemon command: docker daemon). The `-d` and `--daemon` top-level flags are deprecated and a special message is added to prompt the user to use `docker daemon`. Providing top-level daemon-specific flags for client commands result in an error message prompting the user to use `docker daemon`. This patch does not break any old but correct usages. This also makes `-d` and `--daemon` flags, as well as the `daemon` command illegal in client-only binaries. Signed-off-by: Tibor Vass <tibor@docker.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package client
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"net/url"
|
|
"os"
|
|
|
|
Cli "github.com/docker/docker/cli"
|
|
flag "github.com/docker/docker/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) CmdSave(args ...string) error {
|
|
cmd := Cli.Subcmd("save", []string{"IMAGE [IMAGE...]"}, "Save an image(s) to a tar archive (streamed to STDOUT by default)", true)
|
|
outfile := cmd.String([]string{"o", "-output"}, "", "Write to an file, instead of STDOUT")
|
|
cmd.Require(flag.Min, 1)
|
|
|
|
cmd.ParseFlags(args, true)
|
|
|
|
var (
|
|
output io.Writer = cli.out
|
|
err error
|
|
)
|
|
if *outfile != "" {
|
|
output, err = os.Create(*outfile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
} else if cli.isTerminalOut {
|
|
return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
|
|
}
|
|
|
|
sopts := &streamOpts{
|
|
rawTerminal: true,
|
|
out: output,
|
|
}
|
|
|
|
if len(cmd.Args()) == 1 {
|
|
image := cmd.Arg(0)
|
|
if _, err := cli.stream("GET", "/images/"+image+"/get", sopts); err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
v := url.Values{}
|
|
for _, arg := range cmd.Args() {
|
|
v.Add("names", arg)
|
|
}
|
|
if _, err := cli.stream("GET", "/images/get?"+v.Encode(), sopts); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|