From 9a4cbb358d7b839611b86856c73683e0499d681d Mon Sep 17 00:00:00 2001 From: Ma Shimiao Date: Fri, 3 Jul 2015 17:26:09 +0800 Subject: [PATCH] api/client: unify format of args check Signed-off-by: Ma Shimiao --- api/client/attach.go | 11 ++++------- api/client/build.go | 2 +- api/client/commit.go | 1 + api/client/diff.go | 1 + api/client/history.go | 1 + api/client/images.go | 1 + api/client/info.go | 1 + api/client/inspect.go | 1 - api/client/logout.go | 1 + api/client/logs.go | 12 +++++------- api/client/pause.go | 1 + api/client/port.go | 1 + api/client/push.go | 4 +--- api/client/rename.go | 1 + api/client/rmi.go | 9 ++++----- api/client/start.go | 14 +++++++------- api/client/stats.go | 1 + api/client/unpause.go | 1 + 18 files changed, 33 insertions(+), 31 deletions(-) diff --git a/api/client/attach.go b/api/client/attach.go index ee53b96508..389d342f7e 100644 --- a/api/client/attach.go +++ b/api/client/attach.go @@ -16,17 +16,14 @@ import ( // // Usage: docker attach [OPTIONS] CONTAINER func (cli *DockerCli) CmdAttach(args ...string) error { - var ( - cmd = cli.Subcmd("attach", []string{"CONTAINER"}, "Attach to a running container", true) - noStdin = cmd.Bool([]string{"#nostdin", "-no-stdin"}, false, "Do not attach STDIN") - proxy = cmd.Bool([]string{"#sig-proxy", "-sig-proxy"}, true, "Proxy all received signals to the process") - ) + cmd := cli.Subcmd("attach", []string{"CONTAINER"}, "Attach to a running container", true) + noStdin := cmd.Bool([]string{"#nostdin", "-no-stdin"}, false, "Do not attach STDIN") + proxy := cmd.Bool([]string{"#sig-proxy", "-sig-proxy"}, true, "Proxy all received signals to the process") cmd.Require(flag.Exact, 1) cmd.ParseFlags(args, true) - name := cmd.Arg(0) - stream, _, _, err := cli.call("GET", "/containers/"+name+"/json", nil, nil) + stream, _, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/json", nil, nil) if err != nil { return err } diff --git a/api/client/build.go b/api/client/build.go index 05d4eaacf2..6a2778f1a5 100644 --- a/api/client/build.go +++ b/api/client/build.go @@ -60,8 +60,8 @@ func (cli *DockerCli) CmdBuild(args ...string) error { flCPUSetCpus := cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)") flCPUSetMems := cmd.String([]string{"-cpuset-mems"}, "", "MEMs in which to allow execution (0-3, 0,1)") flCgroupParent := cmd.String([]string{"-cgroup-parent"}, "", "Optional parent cgroup for the container") - cmd.Require(flag.Exact, 1) + cmd.ParseFlags(args, true) var ( diff --git a/api/client/commit.go b/api/client/commit.go index 55ff3d7e53..0f98c67182 100644 --- a/api/client/commit.go +++ b/api/client/commit.go @@ -27,6 +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") cmd.Require(flag.Max, 2) cmd.Require(flag.Min, 1) + cmd.ParseFlags(args, true) var ( diff --git a/api/client/diff.go b/api/client/diff.go index 91669c2abd..f3c3d319da 100644 --- a/api/client/diff.go +++ b/api/client/diff.go @@ -19,6 +19,7 @@ import ( func (cli *DockerCli) CmdDiff(args ...string) error { cmd := cli.Subcmd("diff", []string{"CONTAINER"}, "Inspect changes on a container's filesystem", true) cmd.Require(flag.Exact, 1) + cmd.ParseFlags(args, true) if cmd.Arg(0) == "" { diff --git a/api/client/history.go b/api/client/history.go index ece42c07d9..ad40bb73bd 100644 --- a/api/client/history.go +++ b/api/client/history.go @@ -22,6 +22,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error { quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only show numeric IDs") noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output") cmd.Require(flag.Exact, 1) + cmd.ParseFlags(args, true) rdr, _, _, err := cli.call("GET", "/images/"+cmd.Arg(0)+"/history", nil, nil) diff --git a/api/client/images.go b/api/client/images.go index 701e19fcbb..a9740a4e74 100644 --- a/api/client/images.go +++ b/api/client/images.go @@ -30,6 +30,7 @@ func (cli *DockerCli) CmdImages(args ...string) error { flFilter := opts.NewListOpts(nil) cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided") cmd.Require(flag.Max, 1) + cmd.ParseFlags(args, true) // Consolidate all filter flags, and sanity check them early. diff --git a/api/client/info.go b/api/client/info.go index 4cfa76d5ff..503dddd04d 100644 --- a/api/client/info.go +++ b/api/client/info.go @@ -16,6 +16,7 @@ import ( func (cli *DockerCli) CmdInfo(args ...string) error { cmd := cli.Subcmd("info", nil, "Display system-wide information", true) cmd.Require(flag.Exact, 0) + cmd.ParseFlags(args, true) rdr, _, _, err := cli.call("GET", "/info", nil, nil) diff --git a/api/client/inspect.go b/api/client/inspect.go index fb22335dce..b09646afa9 100644 --- a/api/client/inspect.go +++ b/api/client/inspect.go @@ -19,7 +19,6 @@ func (cli *DockerCli) CmdInspect(args ...string) error { cmd := cli.Subcmd("inspect", []string{"CONTAINER|IMAGE [CONTAINER|IMAGE...]"}, "Return low-level information on a container or image", true) tmplStr := cmd.String([]string{"f", "#format", "-format"}, "", "Format the output using the given go template") inspectType := cmd.String([]string{"-type"}, "", "Return JSON for specified type, (e.g image or container)") - cmd.Require(flag.Min, 1) cmd.ParseFlags(args, true) diff --git a/api/client/logout.go b/api/client/logout.go index 482261aed4..76d1cd143a 100644 --- a/api/client/logout.go +++ b/api/client/logout.go @@ -17,6 +17,7 @@ func (cli *DockerCli) CmdLogout(args ...string) error { cmd.Require(flag.Max, 1) cmd.ParseFlags(args, true) + serverAddress := registry.IndexServerAddress() if len(cmd.Args()) > 0 { serverAddress = cmd.Arg(0) diff --git a/api/client/logs.go b/api/client/logs.go index 62924dac47..2bcfb35cfd 100644 --- a/api/client/logs.go +++ b/api/client/logs.go @@ -15,13 +15,11 @@ import ( // // docker logs [OPTIONS] CONTAINER func (cli *DockerCli) CmdLogs(args ...string) error { - var ( - cmd = cli.Subcmd("logs", []string{"CONTAINER"}, "Fetch the logs of a container", true) - follow = cmd.Bool([]string{"f", "-follow"}, false, "Follow log output") - since = cmd.String([]string{"-since"}, "", "Show logs since timestamp") - times = cmd.Bool([]string{"t", "-timestamps"}, false, "Show timestamps") - tail = cmd.String([]string{"-tail"}, "all", "Number of lines to show from the end of the logs") - ) + cmd := cli.Subcmd("logs", []string{"CONTAINER"}, "Fetch the logs of a container", true) + follow := cmd.Bool([]string{"f", "-follow"}, false, "Follow log output") + since := cmd.String([]string{"-since"}, "", "Show logs since timestamp") + times := cmd.Bool([]string{"t", "-timestamps"}, false, "Show timestamps") + tail := cmd.String([]string{"-tail"}, "all", "Number of lines to show from the end of the logs") cmd.Require(flag.Exact, 1) cmd.ParseFlags(args, true) diff --git a/api/client/pause.go b/api/client/pause.go index 0612863da7..46285755f6 100644 --- a/api/client/pause.go +++ b/api/client/pause.go @@ -12,6 +12,7 @@ import ( func (cli *DockerCli) CmdPause(args ...string) error { cmd := cli.Subcmd("pause", []string{"CONTAINER [CONTAINER...]"}, "Pause all processes within a container", true) cmd.Require(flag.Min, 1) + cmd.ParseFlags(args, true) var errNames []string diff --git a/api/client/port.go b/api/client/port.go index ec98184c7a..5bbc920109 100644 --- a/api/client/port.go +++ b/api/client/port.go @@ -16,6 +16,7 @@ import ( func (cli *DockerCli) CmdPort(args ...string) error { cmd := cli.Subcmd("port", []string{"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.ParseFlags(args, true) stream, _, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/json", nil, nil) diff --git a/api/client/push.go b/api/client/push.go index e0bfe82cb1..2d99a51298 100644 --- a/api/client/push.go +++ b/api/client/push.go @@ -18,9 +18,7 @@ func (cli *DockerCli) CmdPush(args ...string) error { cmd.ParseFlags(args, true) - name := cmd.Arg(0) - - remote, tag := parsers.ParseRepositoryTag(name) + remote, tag := parsers.ParseRepositoryTag(cmd.Arg(0)) // Resolve the Repository name from fqn to RepositoryInfo repoInfo, err := registry.ParseRepositoryInfo(remote) diff --git a/api/client/rename.go b/api/client/rename.go index 04cf258648..caad597d00 100644 --- a/api/client/rename.go +++ b/api/client/rename.go @@ -12,6 +12,7 @@ import ( func (cli *DockerCli) CmdRename(args ...string) error { cmd := cli.Subcmd("rename", []string{"OLD_NAME NEW_NAME"}, "Rename a container", true) cmd.Require(flag.Exact, 2) + cmd.ParseFlags(args, true) oldName := cmd.Arg(0) diff --git a/api/client/rmi.go b/api/client/rmi.go index 19f2f61b5d..fc4629b76b 100644 --- a/api/client/rmi.go +++ b/api/client/rmi.go @@ -13,12 +13,11 @@ import ( // // Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] func (cli *DockerCli) CmdRmi(args ...string) error { - var ( - cmd = cli.Subcmd("rmi", []string{"IMAGE [IMAGE...]"}, "Remove one or more images", true) - force = cmd.Bool([]string{"f", "-force"}, false, "Force removal of the image") - noprune = cmd.Bool([]string{"-no-prune"}, false, "Do not delete untagged parents") - ) + cmd := cli.Subcmd("rmi", []string{"IMAGE [IMAGE...]"}, "Remove one or more images", true) + force := cmd.Bool([]string{"f", "-force"}, false, "Force removal of the image") + noprune := cmd.Bool([]string{"-no-prune"}, false, "Do not delete untagged parents") cmd.Require(flag.Min, 1) + cmd.ParseFlags(args, true) v := url.Values{} diff --git a/api/client/start.go b/api/client/start.go index a04bc564a7..1639af1154 100644 --- a/api/client/start.go +++ b/api/client/start.go @@ -44,18 +44,18 @@ func (cli *DockerCli) forwardAllSignals(cid string) chan os.Signal { // // Usage: docker start [OPTIONS] CONTAINER [CONTAINER...] func (cli *DockerCli) CmdStart(args ...string) error { + cmd := cli.Subcmd("start", []string{"CONTAINER [CONTAINER...]"}, "Start one or more stopped containers", true) + attach := cmd.Bool([]string{"a", "-attach"}, false, "Attach STDOUT/STDERR and forward signals") + openStdin := cmd.Bool([]string{"i", "-interactive"}, false, "Attach container's STDIN") + cmd.Require(flag.Min, 1) + + cmd.ParseFlags(args, true) + var ( cErr chan error tty bool - - cmd = cli.Subcmd("start", []string{"CONTAINER [CONTAINER...]"}, "Start one or more stopped containers", true) - attach = cmd.Bool([]string{"a", "-attach"}, false, "Attach STDOUT/STDERR and forward signals") - openStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Attach container's STDIN") ) - cmd.Require(flag.Min, 1) - cmd.ParseFlags(args, true) - if *attach || *openStdin { if cmd.NArg() > 1 { return fmt.Errorf("You cannot start and attach multiple containers at once.") diff --git a/api/client/stats.go b/api/client/stats.go index 408d58f9a1..e76ca71547 100644 --- a/api/client/stats.go +++ b/api/client/stats.go @@ -127,6 +127,7 @@ func (cli *DockerCli) CmdStats(args ...string) error { cmd := cli.Subcmd("stats", []string{"CONTAINER [CONTAINER...]"}, "Display a live stream of one or more containers' resource usage statistics", true) noStream := cmd.Bool([]string{"-no-stream"}, false, "Disable streaming stats and only pull the first result") cmd.Require(flag.Min, 1) + cmd.ParseFlags(args, true) names := cmd.Args() diff --git a/api/client/unpause.go b/api/client/unpause.go index ca7aad4e98..0c9dc882db 100644 --- a/api/client/unpause.go +++ b/api/client/unpause.go @@ -12,6 +12,7 @@ import ( func (cli *DockerCli) CmdUnpause(args ...string) error { cmd := cli.Subcmd("unpause", []string{"CONTAINER [CONTAINER...]"}, "Unpause all processes within a container", true) cmd.Require(flag.Min, 1) + cmd.ParseFlags(args, true) var errNames []string