github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/runconfig/exec.go (about)

     1  package runconfig
     2  
     3  import (
     4  	flag "github.com/docker/docker/pkg/mflag"
     5  )
     6  
     7  type ExecConfig struct {
     8  	User         string
     9  	Privileged   bool
    10  	Tty          bool
    11  	Container    string
    12  	AttachStdin  bool
    13  	AttachStderr bool
    14  	AttachStdout bool
    15  	Detach       bool
    16  	Cmd          []string
    17  }
    18  
    19  func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
    20  	var (
    21  		flStdin      = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached")
    22  		flTty        = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY")
    23  		flDetach     = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run command in the background")
    24  		flUser       = cmd.String([]string{"u", "-user"}, "", "Username or UID (format: <name|uid>[:<group|gid>])")
    25  		flPrivileged = cmd.Bool([]string{"-privileged"}, false, "Give extended privileges to the command")
    26  		execCmd      []string
    27  		container    string
    28  	)
    29  	cmd.Require(flag.Min, 2)
    30  	if err := cmd.ParseFlags(args, true); err != nil {
    31  		return nil, err
    32  	}
    33  	container = cmd.Arg(0)
    34  	parsedArgs := cmd.Args()
    35  	execCmd = parsedArgs[1:]
    36  
    37  	execConfig := &ExecConfig{
    38  		User:       *flUser,
    39  		Privileged: *flPrivileged,
    40  		Tty:        *flTty,
    41  		Cmd:        execCmd,
    42  		Container:  container,
    43  		Detach:     *flDetach,
    44  	}
    45  
    46  	// If -d is not set, attach to everything by default
    47  	if !*flDetach {
    48  		execConfig.AttachStdout = true
    49  		execConfig.AttachStderr = true
    50  		if *flStdin {
    51  			execConfig.AttachStdin = true
    52  		}
    53  	}
    54  
    55  	return execConfig, nil
    56  }