2014-09-09 00:19:32 -04:00
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ExecConfig struct {
|
|
|
|
User string
|
|
|
|
Privileged bool
|
|
|
|
Tty bool
|
|
|
|
Container string
|
|
|
|
AttachStdin bool
|
|
|
|
AttachStderr bool
|
|
|
|
AttachStdout bool
|
|
|
|
Detach bool
|
|
|
|
Cmd []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
|
|
|
|
var (
|
2015-04-10 23:26:37 -04:00
|
|
|
flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached")
|
|
|
|
flTty = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY")
|
|
|
|
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run command in the background")
|
|
|
|
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID (format: <name|uid>[:<group|gid>])")
|
|
|
|
flPrivileged = cmd.Bool([]string{"-privileged"}, false, "Give extended privileges to the command")
|
|
|
|
execCmd []string
|
|
|
|
container string
|
2014-09-09 00:19:32 -04:00
|
|
|
)
|
2014-11-05 11:57:51 -05:00
|
|
|
cmd.Require(flag.Min, 2)
|
2015-03-28 21:22:46 -04:00
|
|
|
if err := cmd.ParseFlags(args, true); err != nil {
|
2014-09-09 00:19:32 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2014-12-01 12:16:49 -05:00
|
|
|
container = cmd.Arg(0)
|
2014-10-15 17:14:12 -04:00
|
|
|
parsedArgs := cmd.Args()
|
2014-12-01 12:16:49 -05:00
|
|
|
execCmd = parsedArgs[1:]
|
2014-09-09 00:19:32 -04:00
|
|
|
|
|
|
|
execConfig := &ExecConfig{
|
2015-04-10 23:26:37 -04:00
|
|
|
User: *flUser,
|
|
|
|
Privileged: *flPrivileged,
|
2014-09-09 00:19:32 -04:00
|
|
|
Tty: *flTty,
|
|
|
|
Cmd: execCmd,
|
|
|
|
Container: container,
|
|
|
|
Detach: *flDetach,
|
|
|
|
}
|
|
|
|
|
|
|
|
// If -d is not set, attach to everything by default
|
|
|
|
if !*flDetach {
|
|
|
|
execConfig.AttachStdout = true
|
|
|
|
execConfig.AttachStderr = true
|
|
|
|
if *flStdin {
|
|
|
|
execConfig.AttachStdin = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return execConfig, nil
|
|
|
|
}
|