mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Refactor CLI docker save
Signed-off-by: Hu Keping <hukeping@huawei.com>
This commit is contained in:
		
							parent
							
								
									6efe45990d
								
							
						
					
					
						commit
						22be1e443f
					
				
					 2 changed files with 13 additions and 18 deletions
				
			
		| 
						 | 
				
			
			@ -52,7 +52,7 @@ type DockerCli struct {
 | 
			
		|||
	outFd uintptr
 | 
			
		||||
	// isTerminalIn indicates whether the client's STDIN is a TTY
 | 
			
		||||
	isTerminalIn bool
 | 
			
		||||
	// isTerminalOut dindicates whether the client's STDOUT is a TTY
 | 
			
		||||
	// isTerminalOut indicates whether the client's STDOUT is a TTY
 | 
			
		||||
	isTerminalOut bool
 | 
			
		||||
	// transport holds the client transport instance.
 | 
			
		||||
	transport *http.Transport
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,13 +25,14 @@ func (cli *DockerCli) CmdSave(args ...string) error {
 | 
			
		|||
		output = cli.out
 | 
			
		||||
		err    error
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	if *outfile == "" && cli.isTerminalOut {
 | 
			
		||||
		return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
 | 
			
		||||
	}
 | 
			
		||||
	if *outfile != "" {
 | 
			
		||||
		output, err = os.Create(*outfile)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
		if output, err = os.Create(*outfile); 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{
 | 
			
		||||
| 
						 | 
				
			
			@ -39,19 +40,13 @@ func (cli *DockerCli) CmdSave(args ...string) error {
 | 
			
		|||
		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
 | 
			
		||||
		}
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue