github.com/a4a881d4/docker@v1.9.0-rc2/runconfig/exec.go (about) 1 package runconfig 2 3 import ( 4 flag "github.com/docker/docker/pkg/mflag" 5 ) 6 7 // ExecConfig is a small subset of the Config struct that hold the configuration 8 // for the exec feature of docker. 9 type ExecConfig struct { 10 User string // User that will run the command 11 Privileged bool // Is the container in privileged mode 12 Tty bool // Attach standard streams to a tty. 13 Container string // Name of the container (to execute in) 14 AttachStdin bool // Attach the standard input, makes possible user interaction 15 AttachStderr bool // Attach the standard output 16 AttachStdout bool // Attach the standard error 17 Detach bool // Execute in detach mode 18 Cmd []string // Execution commands and args 19 } 20 21 // ParseExec parses the specified args for the specified command and generates 22 // an ExecConfig from it. 23 // If the minimal number of specified args is not right or if specified args are 24 // not valid, it will return an error. 25 func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) { 26 var ( 27 flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached") 28 flTty = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY") 29 flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run command in the background") 30 flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID (format: <name|uid>[:<group|gid>])") 31 flPrivileged = cmd.Bool([]string{"-privileged"}, false, "Give extended privileges to the command") 32 execCmd []string 33 container string 34 ) 35 cmd.Require(flag.Min, 2) 36 if err := cmd.ParseFlags(args, true); err != nil { 37 return nil, err 38 } 39 container = cmd.Arg(0) 40 parsedArgs := cmd.Args() 41 execCmd = parsedArgs[1:] 42 43 execConfig := &ExecConfig{ 44 User: *flUser, 45 Privileged: *flPrivileged, 46 Tty: *flTty, 47 Cmd: execCmd, 48 Container: container, 49 Detach: *flDetach, 50 } 51 52 // If -d is not set, attach to everything by default 53 if !*flDetach { 54 execConfig.AttachStdout = true 55 execConfig.AttachStderr = true 56 if *flStdin { 57 execConfig.AttachStdin = true 58 } 59 } 60 61 return execConfig, nil 62 }