Browse Source

Move ParseExec to the client where it is used.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin 9 years ago
parent
commit
4c0d586bd3
5 changed files with 46 additions and 52 deletions
  1. 45 2
      api/client/exec.go
  2. 1 1
      api/client/exec_test.go
  3. 0 0
      runconfig/client/parse.go
  4. 0 0
      runconfig/client/parse_test.go
  5. 0 49
      runconfig/exec.go

+ 45 - 2
api/client/exec.go

@@ -7,8 +7,8 @@ import (
 	"github.com/Sirupsen/logrus"
 	"github.com/docker/docker/api/types"
 	Cli "github.com/docker/docker/cli"
+	flag "github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/promise"
-	"github.com/docker/docker/runconfig"
 )
 
 // CmdExec runs a command in a running container.
@@ -18,7 +18,7 @@ func (cli *DockerCli) CmdExec(args ...string) error {
 	cmd := Cli.Subcmd("exec", []string{"CONTAINER COMMAND [ARG...]"}, Cli.DockerCommands["exec"].Description, true)
 	detachKeys := cmd.String([]string{"-detach-keys"}, "", "Override the key sequence for detaching a container")
 
-	execConfig, err := runconfig.ParseExec(cmd, args)
+	execConfig, err := ParseExec(cmd, args)
 	// just in case the ParseExec does not exit
 	if execConfig.Container == "" || err != nil {
 		return Cli.StatusError{StatusCode: 1}
@@ -113,3 +113,46 @@ func (cli *DockerCli) CmdExec(args ...string) error {
 
 	return nil
 }
+
+// ParseExec parses the specified args for the specified command and generates
+// an ExecConfig from it.
+// If the minimal number of specified args is not right or if specified args are
+// not valid, it will return an error.
+func ParseExec(cmd *flag.FlagSet, args []string) (*types.ExecConfig, error) {
+	var (
+		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
+	)
+	cmd.Require(flag.Min, 2)
+	if err := cmd.ParseFlags(args, true); err != nil {
+		return nil, err
+	}
+	container = cmd.Arg(0)
+	parsedArgs := cmd.Args()
+	execCmd = parsedArgs[1:]
+
+	execConfig := &types.ExecConfig{
+		User:       *flUser,
+		Privileged: *flPrivileged,
+		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
+}

+ 1 - 1
runconfig/exec_test.go → api/client/exec_test.go

@@ -1,4 +1,4 @@
-package runconfig
+package client
 
 import (
 	"fmt"

+ 0 - 0
runconfig/parse.go → runconfig/client/parse.go


+ 0 - 0
runconfig/parse_test.go → runconfig/client/parse_test.go


+ 0 - 49
runconfig/exec.go

@@ -1,49 +0,0 @@
-package runconfig
-
-import (
-	"github.com/docker/docker/api/types"
-	flag "github.com/docker/docker/pkg/mflag"
-)
-
-// ParseExec parses the specified args for the specified command and generates
-// an ExecConfig from it.
-// If the minimal number of specified args is not right or if specified args are
-// not valid, it will return an error.
-func ParseExec(cmd *flag.FlagSet, args []string) (*types.ExecConfig, error) {
-	var (
-		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
-	)
-	cmd.Require(flag.Min, 2)
-	if err := cmd.ParseFlags(args, true); err != nil {
-		return nil, err
-	}
-	container = cmd.Arg(0)
-	parsedArgs := cmd.Args()
-	execCmd = parsedArgs[1:]
-
-	execConfig := &types.ExecConfig{
-		User:       *flUser,
-		Privileged: *flPrivileged,
-		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
-}