github.com/dougm/docker@v1.5.0/runconfig/exec.go (about) 1 package runconfig 2 3 import ( 4 "fmt" 5 6 "github.com/docker/docker/engine" 7 flag "github.com/docker/docker/pkg/mflag" 8 "github.com/docker/docker/utils" 9 ) 10 11 type ExecConfig struct { 12 User string 13 Privileged bool 14 Tty bool 15 Container string 16 AttachStdin bool 17 AttachStderr bool 18 AttachStdout bool 19 Detach bool 20 Cmd []string 21 } 22 23 func ExecConfigFromJob(job *engine.Job) (*ExecConfig, error) { 24 execConfig := &ExecConfig{ 25 // TODO(vishh): Expose 'User' once it is supported. 26 //User: job.Getenv("User"), 27 // TODO(vishh): Expose 'Privileged' once it is supported. 28 //Privileged: job.GetenvBool("Privileged"), 29 Tty: job.GetenvBool("Tty"), 30 AttachStdin: job.GetenvBool("AttachStdin"), 31 AttachStderr: job.GetenvBool("AttachStderr"), 32 AttachStdout: job.GetenvBool("AttachStdout"), 33 } 34 cmd := job.GetenvList("Cmd") 35 if len(cmd) == 0 { 36 return nil, fmt.Errorf("No exec command specified") 37 } 38 39 execConfig.Cmd = cmd 40 41 return execConfig, nil 42 } 43 44 func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) { 45 var ( 46 flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached") 47 flTty = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY") 48 flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run command in the background") 49 execCmd []string 50 container string 51 ) 52 cmd.Require(flag.Min, 2) 53 if err := utils.ParseFlags(cmd, args, true); err != nil { 54 return nil, err 55 } 56 container = cmd.Arg(0) 57 parsedArgs := cmd.Args() 58 execCmd = parsedArgs[1:] 59 60 execConfig := &ExecConfig{ 61 // TODO(vishh): Expose '-u' flag once it is supported. 62 User: "", 63 // TODO(vishh): Expose '-p' flag once it is supported. 64 Privileged: false, 65 Tty: *flTty, 66 Cmd: execCmd, 67 Container: container, 68 Detach: *flDetach, 69 } 70 71 // If -d is not set, attach to everything by default 72 if !*flDetach { 73 execConfig.AttachStdout = true 74 execConfig.AttachStderr = true 75 if *flStdin { 76 execConfig.AttachStdin = true 77 } 78 } 79 80 return execConfig, nil 81 }