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