Ver código fonte

Merge pull request #11893 from runcom/11892-refactor-utils-flags

Refactor utils/flags.go
Michael Crosby 10 anos atrás
pai
commit
00a15227f8

+ 1 - 1
api/client/attach.go

@@ -23,7 +23,7 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
 	)
 	)
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 	name := cmd.Arg(0)
 	name := cmd.Arg(0)
 
 
 	stream, _, err := cli.call("GET", "/containers/"+name+"/json", nil, nil)
 	stream, _, err := cli.call("GET", "/containers/"+name+"/json", nil, nil)

+ 1 - 2
api/client/build.go

@@ -58,8 +58,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
 	flCPUSetCpus := cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)")
 	flCPUSetCpus := cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)")
 
 
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
-
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var (
 	var (
 		context  archive.Archive
 		context  archive.Archive

+ 1 - 2
api/client/commit.go

@@ -11,7 +11,6 @@ import (
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/runconfig"
 	"github.com/docker/docker/runconfig"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdCommit creates a new image from a container's changes.
 // CmdCommit creates a new image from a container's changes.
@@ -28,7 +27,7 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
 	flConfig := cmd.String([]string{"#run", "#-run"}, "", "This option is deprecated and will be removed in a future version in favor of inline Dockerfile-compatible commands")
 	flConfig := cmd.String([]string{"#run", "#-run"}, "", "This option is deprecated and will be removed in a future version in favor of inline Dockerfile-compatible commands")
 	cmd.Require(flag.Max, 2)
 	cmd.Require(flag.Max, 2)
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var (
 	var (
 		name            = cmd.Arg(0)
 		name            = cmd.Arg(0)

+ 1 - 2
api/client/cp.go

@@ -8,7 +8,6 @@ import (
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/archive"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdCp copies files/folders from a path on the container to a directory on the host running the command.
 // CmdCp copies files/folders from a path on the container to a directory on the host running the command.
@@ -20,7 +19,7 @@ func (cli *DockerCli) CmdCp(args ...string) error {
 	cmd := cli.Subcmd("cp", "CONTAINER:PATH HOSTDIR|-", "Copy files/folders from a PATH on the container to a HOSTDIR on the host\nrunning the command. Use '-' to write the data\nas a tar file to STDOUT.", true)
 	cmd := cli.Subcmd("cp", "CONTAINER:PATH HOSTDIR|-", "Copy files/folders from a PATH on the container to a HOSTDIR on the host\nrunning the command. Use '-' to write the data\nas a tar file to STDOUT.", true)
 	cmd.Require(flag.Exact, 2)
 	cmd.Require(flag.Exact, 2)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var copyData engine.Env
 	var copyData engine.Env
 	info := strings.Split(cmd.Arg(0), ":")
 	info := strings.Split(cmd.Arg(0), ":")

+ 1 - 1
api/client/create.go

@@ -142,7 +142,7 @@ func (cli *DockerCli) CmdCreate(args ...string) error {
 
 
 	config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
 	config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
 	if err != nil {
 	if err != nil {
-		utils.ReportError(cmd, err.Error(), true)
+		cmd.ReportError(err.Error(), true)
 	}
 	}
 	if config.Image == "" {
 	if config.Image == "" {
 		cmd.Usage()
 		cmd.Usage()

+ 1 - 2
api/client/diff.go

@@ -6,7 +6,6 @@ import (
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/archive"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdDiff shows changes on a container's filesystem.
 // CmdDiff shows changes on a container's filesystem.
@@ -18,7 +17,7 @@ func (cli *DockerCli) CmdDiff(args ...string) error {
 	cmd := cli.Subcmd("diff", "CONTAINER", "Inspect changes on a container's filesystem", true)
 	cmd := cli.Subcmd("diff", "CONTAINER", "Inspect changes on a container's filesystem", true)
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	body, _, err := readBody(cli.call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil, nil))
 	body, _, err := readBody(cli.call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil, nil))
 
 

+ 1 - 2
api/client/events.go

@@ -9,7 +9,6 @@ import (
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/parsers/filters"
 	"github.com/docker/docker/pkg/parsers/filters"
 	"github.com/docker/docker/pkg/timeutils"
 	"github.com/docker/docker/pkg/timeutils"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdEvents prints a live stream of real time events from the server.
 // CmdEvents prints a live stream of real time events from the server.
@@ -23,7 +22,7 @@ func (cli *DockerCli) CmdEvents(args ...string) error {
 	cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
 	cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
 	cmd.Require(flag.Exact, 0)
 	cmd.Require(flag.Exact, 0)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var (
 	var (
 		v               = url.Values{}
 		v               = url.Values{}

+ 1 - 2
api/client/export.go

@@ -7,7 +7,6 @@ import (
 	"os"
 	"os"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdExport exports a filesystem as a tar archive.
 // CmdExport exports a filesystem as a tar archive.
@@ -20,7 +19,7 @@ func (cli *DockerCli) CmdExport(args ...string) error {
 	outfile := cmd.String([]string{"o", "-output"}, "", "Write to a file, instead of STDOUT")
 	outfile := cmd.String([]string{"o", "-output"}, "", "Write to a file, instead of STDOUT")
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var (
 	var (
 		output io.Writer = cli.out
 		output io.Writer = cli.out

+ 1 - 1
api/client/history.go

@@ -21,7 +21,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
 	noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
 	noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	body, _, err := readBody(cli.call("GET", "/images/"+cmd.Arg(0)+"/history", nil, nil))
 	body, _, err := readBody(cli.call("GET", "/images/"+cmd.Arg(0)+"/history", nil, nil))
 	if err != nil {
 	if err != nil {

+ 1 - 1
api/client/images.go

@@ -102,7 +102,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
 	cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
 	cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
 	cmd.Require(flag.Max, 1)
 	cmd.Require(flag.Max, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	// Consolidate all filter flags, and sanity check them early.
 	// Consolidate all filter flags, and sanity check them early.
 	// They'll get process in the daemon/server.
 	// They'll get process in the daemon/server.

+ 1 - 2
api/client/import.go

@@ -9,7 +9,6 @@ import (
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdImport creates an empty filesystem image, imports the contents of the tarball into the image, and optionally tags the image.
 // CmdImport creates an empty filesystem image, imports the contents of the tarball into the image, and optionally tags the image.
@@ -23,7 +22,7 @@ func (cli *DockerCli) CmdImport(args ...string) error {
 	cmd.Var(&flChanges, []string{"c", "-change"}, "Apply Dockerfile instruction to the created image")
 	cmd.Var(&flChanges, []string{"c", "-change"}, "Apply Dockerfile instruction to the created image")
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var (
 	var (
 		v          = url.Values{}
 		v          = url.Values{}

+ 1 - 2
api/client/info.go

@@ -9,7 +9,6 @@ import (
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/units"
 	"github.com/docker/docker/pkg/units"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdInfo displays system-wide information.
 // CmdInfo displays system-wide information.
@@ -18,7 +17,7 @@ import (
 func (cli *DockerCli) CmdInfo(args ...string) error {
 func (cli *DockerCli) CmdInfo(args ...string) error {
 	cmd := cli.Subcmd("info", "", "Display system-wide information", true)
 	cmd := cli.Subcmd("info", "", "Display system-wide information", true)
 	cmd.Require(flag.Exact, 0)
 	cmd.Require(flag.Exact, 0)
-	utils.ParseFlags(cmd, args, false)
+	cmd.ParseFlags(args, false)
 
 
 	body, _, err := readBody(cli.call("GET", "/info", nil, nil))
 	body, _, err := readBody(cli.call("GET", "/info", nil, nil))
 	if err != nil {
 	if err != nil {

+ 1 - 1
api/client/inspect.go

@@ -20,7 +20,7 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
 	tmplStr := cmd.String([]string{"f", "#format", "-format"}, "", "Format the output using the given go template")
 	tmplStr := cmd.String([]string{"f", "#format", "-format"}, "", "Format the output using the given go template")
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var tmpl *template.Template
 	var tmpl *template.Template
 	if *tmplStr != "" {
 	if *tmplStr != "" {

+ 1 - 2
api/client/kill.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"fmt"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdKill kills one or more running container using SIGKILL or a specified signal.
 // CmdKill kills one or more running container using SIGKILL or a specified signal.
@@ -15,7 +14,7 @@ func (cli *DockerCli) CmdKill(args ...string) error {
 	signal := cmd.String([]string{"s", "-signal"}, "KILL", "Signal to send to the container")
 	signal := cmd.String([]string{"s", "-signal"}, "KILL", "Signal to send to the container")
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var encounteredError error
 	var encounteredError error
 	for _, name := range cmd.Args() {
 	for _, name := range cmd.Args() {

+ 1 - 2
api/client/load.go

@@ -5,7 +5,6 @@ import (
 	"os"
 	"os"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdLoad loads an image from a tar archive.
 // CmdLoad loads an image from a tar archive.
@@ -18,7 +17,7 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
 	infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN")
 	infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN")
 	cmd.Require(flag.Exact, 0)
 	cmd.Require(flag.Exact, 0)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var (
 	var (
 		input io.Reader = cli.in
 		input io.Reader = cli.in

+ 1 - 2
api/client/login.go

@@ -14,7 +14,6 @@ import (
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/term"
 	"github.com/docker/docker/pkg/term"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdLogin logs in or registers a user to a Docker registry service.
 // CmdLogin logs in or registers a user to a Docker registry service.
@@ -32,7 +31,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
 	cmd.StringVar(&password, []string{"p", "-password"}, "", "Password")
 	cmd.StringVar(&password, []string{"p", "-password"}, "", "Password")
 	cmd.StringVar(&email, []string{"e", "-email"}, "", "Email")
 	cmd.StringVar(&email, []string{"e", "-email"}, "", "Email")
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	serverAddress := registry.IndexServerAddress()
 	serverAddress := registry.IndexServerAddress()
 	if len(cmd.Args()) > 0 {
 	if len(cmd.Args()) > 0 {

+ 1 - 2
api/client/logout.go

@@ -5,7 +5,6 @@ import (
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdLogout logs a user out from a Docker registry.
 // CmdLogout logs a user out from a Docker registry.
@@ -17,7 +16,7 @@ func (cli *DockerCli) CmdLogout(args ...string) error {
 	cmd := cli.Subcmd("logout", "[SERVER]", "Log out from a Docker registry, if no server is\nspecified \""+registry.IndexServerAddress()+"\" is the default.", true)
 	cmd := cli.Subcmd("logout", "[SERVER]", "Log out from a Docker registry, if no server is\nspecified \""+registry.IndexServerAddress()+"\" is the default.", true)
 	cmd.Require(flag.Max, 1)
 	cmd.Require(flag.Max, 1)
 
 
-	utils.ParseFlags(cmd, args, false)
+	cmd.ParseFlags(args, false)
 	serverAddress := registry.IndexServerAddress()
 	serverAddress := registry.IndexServerAddress()
 	if len(cmd.Args()) > 0 {
 	if len(cmd.Args()) > 0 {
 		serverAddress = cmd.Arg(0)
 		serverAddress = cmd.Arg(0)

+ 1 - 2
api/client/logs.go

@@ -6,7 +6,6 @@ import (
 
 
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdLogs fetches the logs of a given container.
 // CmdLogs fetches the logs of a given container.
@@ -21,7 +20,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
 	)
 	)
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	name := cmd.Arg(0)
 	name := cmd.Arg(0)
 
 

+ 1 - 2
api/client/pause.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"fmt"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdPause pauses all processes within one or more containers.
 // CmdPause pauses all processes within one or more containers.
@@ -13,7 +12,7 @@ import (
 func (cli *DockerCli) CmdPause(args ...string) error {
 func (cli *DockerCli) CmdPause(args ...string) error {
 	cmd := cli.Subcmd("pause", "CONTAINER [CONTAINER...]", "Pause all processes within a container", true)
 	cmd := cli.Subcmd("pause", "CONTAINER [CONTAINER...]", "Pause all processes within a container", true)
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
-	utils.ParseFlags(cmd, args, false)
+	cmd.ParseFlags(args, false)
 
 
 	var encounteredError error
 	var encounteredError error
 	for _, name := range cmd.Args() {
 	for _, name := range cmd.Args() {

+ 1 - 2
api/client/port.go

@@ -7,7 +7,6 @@ import (
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/nat"
 	"github.com/docker/docker/nat"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdPort lists port mappings for a container.
 // CmdPort lists port mappings for a container.
@@ -17,7 +16,7 @@ import (
 func (cli *DockerCli) CmdPort(args ...string) error {
 func (cli *DockerCli) CmdPort(args ...string) error {
 	cmd := cli.Subcmd("port", "CONTAINER [PRIVATE_PORT[/PROTO]]", "List port mappings for the CONTAINER, or lookup the public-facing port that\nis NAT-ed to the PRIVATE_PORT", true)
 	cmd := cli.Subcmd("port", "CONTAINER [PRIVATE_PORT[/PROTO]]", "List port mappings for the CONTAINER, or lookup the public-facing port that\nis NAT-ed to the PRIVATE_PORT", true)
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	stream, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/json", nil, nil)
 	stream, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/json", nil, nil)
 	if err != nil {
 	if err != nil {

+ 1 - 1
api/client/ps.go

@@ -43,7 +43,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
 
 
 	cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
 	cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 	if *last == -1 && *nLatest {
 	if *last == -1 && *nLatest {
 		*last = 1
 		*last = 1
 	}
 	}

+ 1 - 1
api/client/pull.go

@@ -19,7 +19,7 @@ func (cli *DockerCli) CmdPull(args ...string) error {
 	allTags := cmd.Bool([]string{"a", "-all-tags"}, false, "Download all tagged images in the repository")
 	allTags := cmd.Bool([]string{"a", "-all-tags"}, false, "Download all tagged images in the repository")
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var (
 	var (
 		v         = url.Values{}
 		v         = url.Values{}

+ 1 - 2
api/client/push.go

@@ -7,7 +7,6 @@ import (
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdPush pushes an image or repository to the registry.
 // CmdPush pushes an image or repository to the registry.
@@ -17,7 +16,7 @@ func (cli *DockerCli) CmdPush(args ...string) error {
 	cmd := cli.Subcmd("push", "NAME[:TAG]", "Push an image or a repository to the registry", true)
 	cmd := cli.Subcmd("push", "NAME[:TAG]", "Push an image or a repository to the registry", true)
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	name := cmd.Arg(0)
 	name := cmd.Arg(0)
 
 

+ 1 - 2
api/client/restart.go

@@ -6,7 +6,6 @@ import (
 	"strconv"
 	"strconv"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdRestart restarts one or more running containers.
 // CmdRestart restarts one or more running containers.
@@ -17,7 +16,7 @@ func (cli *DockerCli) CmdRestart(args ...string) error {
 	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing the container")
 	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing the container")
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	v := url.Values{}
 	v := url.Values{}
 	v.Set("t", strconv.Itoa(*nSeconds))
 	v.Set("t", strconv.Itoa(*nSeconds))

+ 1 - 2
api/client/rm.go

@@ -5,7 +5,6 @@ import (
 	"net/url"
 	"net/url"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 func (cli *DockerCli) CmdRm(args ...string) error {
 func (cli *DockerCli) CmdRm(args ...string) error {
@@ -15,7 +14,7 @@ func (cli *DockerCli) CmdRm(args ...string) error {
 	force := cmd.Bool([]string{"f", "-force"}, false, "Force the removal of a running container (uses SIGKILL)")
 	force := cmd.Bool([]string{"f", "-force"}, false, "Force the removal of a running container (uses SIGKILL)")
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	val := url.Values{}
 	val := url.Values{}
 	if *v {
 	if *v {

+ 1 - 2
api/client/rmi.go

@@ -6,7 +6,6 @@ import (
 
 
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdRmi removes all images with the specified name(s).
 // CmdRmi removes all images with the specified name(s).
@@ -20,7 +19,7 @@ func (cli *DockerCli) CmdRmi(args ...string) error {
 	)
 	)
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	v := url.Values{}
 	v := url.Values{}
 	if *force {
 	if *force {

+ 1 - 1
api/client/run.go

@@ -58,7 +58,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
 	config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
 	config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
 	// just in case the Parse does not exit
 	// just in case the Parse does not exit
 	if err != nil {
 	if err != nil {
-		utils.ReportError(cmd, err.Error(), true)
+		cmd.ReportError(err.Error(), true)
 	}
 	}
 
 
 	if len(hostConfig.Dns) > 0 {
 	if len(hostConfig.Dns) > 0 {

+ 1 - 2
api/client/save.go

@@ -7,7 +7,6 @@ import (
 	"os"
 	"os"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdSave saves one or more images to a tar archive.
 // CmdSave saves one or more images to a tar archive.
@@ -20,7 +19,7 @@ func (cli *DockerCli) CmdSave(args ...string) error {
 	outfile := cmd.String([]string{"o", "-output"}, "", "Write to an file, instead of STDOUT")
 	outfile := cmd.String([]string{"o", "-output"}, "", "Write to an file, instead of STDOUT")
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var (
 	var (
 		output io.Writer = cli.out
 		output io.Writer = cli.out

+ 1 - 1
api/client/search.go

@@ -24,7 +24,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
 	stars := cmd.Int([]string{"s", "#stars", "-stars"}, 0, "Only displays with at least x stars")
 	stars := cmd.Int([]string{"s", "#stars", "-stars"}, 0, "Only displays with at least x stars")
 	cmd.Require(flag.Exact, 1)
 	cmd.Require(flag.Exact, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	name := cmd.Arg(0)
 	name := cmd.Arg(0)
 	v := url.Values{}
 	v := url.Values{}

+ 1 - 1
api/client/start.go

@@ -54,7 +54,7 @@ func (cli *DockerCli) CmdStart(args ...string) error {
 	)
 	)
 
 
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	if *attach || *openStdin {
 	if *attach || *openStdin {
 		if cmd.NArg() > 1 {
 		if cmd.NArg() > 1 {

+ 1 - 2
api/client/stats.go

@@ -13,7 +13,6 @@ import (
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/units"
 	"github.com/docker/docker/pkg/units"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 type containerStats struct {
 type containerStats struct {
@@ -114,7 +113,7 @@ func (s *containerStats) Display(w io.Writer) error {
 func (cli *DockerCli) CmdStats(args ...string) error {
 func (cli *DockerCli) CmdStats(args ...string) error {
 	cmd := cli.Subcmd("stats", "CONTAINER [CONTAINER...]", "Display a live stream of one or more containers' resource usage statistics", true)
 	cmd := cli.Subcmd("stats", "CONTAINER [CONTAINER...]", "Display a live stream of one or more containers' resource usage statistics", true)
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	names := cmd.Args()
 	names := cmd.Args()
 	sort.Strings(names)
 	sort.Strings(names)

+ 1 - 2
api/client/stop.go

@@ -6,7 +6,6 @@ import (
 	"strconv"
 	"strconv"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdStop stops one or more running containers.
 // CmdStop stops one or more running containers.
@@ -19,7 +18,7 @@ func (cli *DockerCli) CmdStop(args ...string) error {
 	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing it")
 	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing it")
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	v := url.Values{}
 	v := url.Values{}
 	v.Set("t", strconv.Itoa(*nSeconds))
 	v.Set("t", strconv.Itoa(*nSeconds))

+ 1 - 2
api/client/tag.go

@@ -6,7 +6,6 @@ import (
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdTag tags an image into a repository.
 // CmdTag tags an image into a repository.
@@ -17,7 +16,7 @@ func (cli *DockerCli) CmdTag(args ...string) error {
 	force := cmd.Bool([]string{"f", "#force", "-force"}, false, "Force")
 	force := cmd.Bool([]string{"f", "#force", "-force"}, false, "Force")
 	cmd.Require(flag.Exact, 2)
 	cmd.Require(flag.Exact, 2)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var (
 	var (
 		repository, tag = parsers.ParseRepositoryTag(cmd.Arg(1))
 		repository, tag = parsers.ParseRepositoryTag(cmd.Arg(1))

+ 1 - 2
api/client/top.go

@@ -8,7 +8,6 @@ import (
 
 
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdTop displays the running processes of a container.
 // CmdTop displays the running processes of a container.
@@ -18,7 +17,7 @@ func (cli *DockerCli) CmdTop(args ...string) error {
 	cmd := cli.Subcmd("top", "CONTAINER [ps OPTIONS]", "Display the running processes of a container", true)
 	cmd := cli.Subcmd("top", "CONTAINER [ps OPTIONS]", "Display the running processes of a container", true)
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	val := url.Values{}
 	val := url.Values{}
 	if cmd.NArg() > 1 {
 	if cmd.NArg() > 1 {

+ 1 - 2
api/client/unpause.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"fmt"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdUnpause unpauses all processes within a container, for one or more containers.
 // CmdUnpause unpauses all processes within a container, for one or more containers.
@@ -13,7 +12,7 @@ import (
 func (cli *DockerCli) CmdUnpause(args ...string) error {
 func (cli *DockerCli) CmdUnpause(args ...string) error {
 	cmd := cli.Subcmd("unpause", "CONTAINER [CONTAINER...]", "Unpause all processes within a container", true)
 	cmd := cli.Subcmd("unpause", "CONTAINER [CONTAINER...]", "Unpause all processes within a container", true)
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
-	utils.ParseFlags(cmd, args, false)
+	cmd.ParseFlags(args, false)
 
 
 	var encounteredError error
 	var encounteredError error
 	for _, name := range cmd.Args() {
 	for _, name := range cmd.Args() {

+ 1 - 2
api/client/version.go

@@ -9,7 +9,6 @@ import (
 	"github.com/docker/docker/autogen/dockerversion"
 	"github.com/docker/docker/autogen/dockerversion"
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdVersion shows Docker version information.
 // CmdVersion shows Docker version information.
@@ -21,7 +20,7 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
 	cmd := cli.Subcmd("version", "", "Show the Docker version information.", true)
 	cmd := cli.Subcmd("version", "", "Show the Docker version information.", true)
 	cmd.Require(flag.Exact, 0)
 	cmd.Require(flag.Exact, 0)
 
 
-	utils.ParseFlags(cmd, args, false)
+	cmd.ParseFlags(args, false)
 
 
 	if dockerversion.VERSION != "" {
 	if dockerversion.VERSION != "" {
 		fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION)
 		fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION)

+ 1 - 2
api/client/wait.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"fmt"
 
 
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 // CmdWait blocks until a container stops, then prints its exit code.
 // CmdWait blocks until a container stops, then prints its exit code.
@@ -16,7 +15,7 @@ func (cli *DockerCli) CmdWait(args ...string) error {
 	cmd := cli.Subcmd("wait", "CONTAINER [CONTAINER...]", "Block until a container stops, then print its exit code.", true)
 	cmd := cli.Subcmd("wait", "CONTAINER [CONTAINER...]", "Block until a container stops, then print its exit code.", true)
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	utils.ParseFlags(cmd, args, true)
+	cmd.ParseFlags(args, true)
 
 
 	var encounteredError error
 	var encounteredError error
 	for _, name := range cmd.Args() {
 	for _, name := range cmd.Args() {

+ 36 - 0
pkg/mflag/flag.go

@@ -1054,6 +1054,42 @@ func (f *FlagSet) Parse(arguments []string) error {
 	return nil
 	return nil
 }
 }
 
 
+// ParseFlags is a utility function that adds a help flag if withHelp is true,
+// calls cmd.Parse(args) and prints a relevant error message if there are
+// incorrect number of arguments. It returns error only if error handling is
+// set to ContinueOnError and parsing fails. If error handling is set to
+// ExitOnError, it's safe to ignore the return value.
+func (cmd *FlagSet) ParseFlags(args []string, withHelp bool) error {
+	var help *bool
+	if withHelp {
+		help = cmd.Bool([]string{"#help", "-help"}, false, "Print usage")
+	}
+	if err := cmd.Parse(args); err != nil {
+		return err
+	}
+	if help != nil && *help {
+		cmd.Usage()
+		// just in case Usage does not exit
+		os.Exit(0)
+	}
+	if str := cmd.CheckArgs(); str != "" {
+		cmd.ReportError(str, withHelp)
+	}
+	return nil
+}
+
+func (cmd *FlagSet) ReportError(str string, withHelp bool) {
+	if withHelp {
+		if os.Args[0] == cmd.Name() {
+			str += ". See '" + os.Args[0] + " --help'"
+		} else {
+			str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'"
+		}
+	}
+	fmt.Fprintf(cmd.Out(), "docker: %s.\n", str)
+	os.Exit(1)
+}
+
 // Parsed reports whether f.Parse has been called.
 // Parsed reports whether f.Parse has been called.
 func (f *FlagSet) Parsed() bool {
 func (f *FlagSet) Parsed() bool {
 	return f.parsed
 	return f.parsed

+ 1 - 2
runconfig/exec.go

@@ -5,7 +5,6 @@ import (
 
 
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/docker/utils"
 )
 )
 
 
 type ExecConfig struct {
 type ExecConfig struct {
@@ -50,7 +49,7 @@ func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
 		container string
 		container string
 	)
 	)
 	cmd.Require(flag.Min, 2)
 	cmd.Require(flag.Min, 2)
-	if err := utils.ParseFlags(cmd, args, true); err != nil {
+	if err := cmd.ParseFlags(args, true); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 	container = cmd.Arg(0)
 	container = cmd.Arg(0)

+ 1 - 1
runconfig/parse.go

@@ -96,7 +96,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
 
 
 	cmd.Require(flag.Min, 1)
 	cmd.Require(flag.Min, 1)
 
 
-	if err := utils.ParseFlags(cmd, args, true); err != nil {
+	if err := cmd.ParseFlags(args, true); err != nil {
 		return nil, nil, cmd, err
 		return nil, nil, cmd, err
 	}
 	}
 
 

+ 0 - 45
utils/flags.go

@@ -1,45 +0,0 @@
-package utils
-
-import (
-	"fmt"
-	"os"
-
-	flag "github.com/docker/docker/pkg/mflag"
-)
-
-// ParseFlags is a utility function that adds a help flag if withHelp is true,
-// calls cmd.Parse(args) and prints a relevant error message if there are
-// incorrect number of arguments. It returns error only if error handling is
-// set to ContinueOnError and parsing fails. If error handling is set to
-// ExitOnError, it's safe to ignore the return value.
-// TODO: move this to a better package than utils
-func ParseFlags(cmd *flag.FlagSet, args []string, withHelp bool) error {
-	var help *bool
-	if withHelp {
-		help = cmd.Bool([]string{"#help", "-help"}, false, "Print usage")
-	}
-	if err := cmd.Parse(args); err != nil {
-		return err
-	}
-	if help != nil && *help {
-		cmd.Usage()
-		// just in case Usage does not exit
-		os.Exit(0)
-	}
-	if str := cmd.CheckArgs(); str != "" {
-		ReportError(cmd, str, withHelp)
-	}
-	return nil
-}
-
-func ReportError(cmd *flag.FlagSet, str string, withHelp bool) {
-	if withHelp {
-		if os.Args[0] == cmd.Name() {
-			str += ". See '" + os.Args[0] + " --help'"
-		} else {
-			str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'"
-		}
-	}
-	fmt.Fprintf(cmd.Out(), "docker: %s.\n", str)
-	os.Exit(1)
-}