github.com/hamo/docker@v1.11.1/api/client/wait.go (about)

     1  package client
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"golang.org/x/net/context"
     8  
     9  	Cli "github.com/docker/docker/cli"
    10  	flag "github.com/docker/docker/pkg/mflag"
    11  )
    12  
    13  // CmdWait blocks until a container stops, then prints its exit code.
    14  //
    15  // If more than one container is specified, this will wait synchronously on each container.
    16  //
    17  // Usage: docker wait CONTAINER [CONTAINER...]
    18  func (cli *DockerCli) CmdWait(args ...string) error {
    19  	cmd := Cli.Subcmd("wait", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["wait"].Description, true)
    20  	cmd.Require(flag.Min, 1)
    21  
    22  	cmd.ParseFlags(args, true)
    23  
    24  	var errs []string
    25  	for _, name := range cmd.Args() {
    26  		status, err := cli.client.ContainerWait(context.Background(), name)
    27  		if err != nil {
    28  			errs = append(errs, err.Error())
    29  		} else {
    30  			fmt.Fprintf(cli.out, "%d\n", status)
    31  		}
    32  	}
    33  	if len(errs) > 0 {
    34  		return fmt.Errorf("%s", strings.Join(errs, "\n"))
    35  	}
    36  	return nil
    37  }