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-05-26 17:02:10 -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>])")
|
|
|
|
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-05-26 17:02:10 -04:00
|
|
|
User: *flUser,
|
|
|
|
// TODO(vishh): Expose 'Privileged' once it is supported.
|
|
|
|
// + //Privileged: job.GetenvBool("Privileged"),
|
|
|
|
Tty: *flTty,
|
|
|
|
Cmd: execCmd,
|
|
|
|
Container: container,
|
|
|
|
Detach: *flDetach,
|
2014-09-09 00:19:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|