github.com/torfuzx/docker@v1.8.1/api/client/wait.go (about)

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