From 2b0927c9ac23b66d8a05761801d1c5f882ba8dfb Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Thu, 8 Oct 2015 08:46:21 -0400 Subject: [PATCH] Use consistent command description Signed-off-by: Lei Jitang --- api/client/attach.go | 2 +- api/client/build.go | 2 +- api/client/commit.go | 2 +- api/client/cp.go | 4 +-- api/client/create.go | 2 +- api/client/diff.go | 2 +- api/client/events.go | 2 +- api/client/exec.go | 2 +- api/client/export.go | 2 +- api/client/history.go | 2 +- api/client/images.go | 2 +- api/client/import.go | 2 +- api/client/info.go | 2 +- api/client/inspect.go | 2 +- api/client/kill.go | 2 +- api/client/load.go | 2 +- api/client/login.go | 2 +- api/client/logout.go | 2 +- api/client/logs.go | 2 +- api/client/pause.go | 2 +- api/client/port.go | 2 +- api/client/ps.go | 2 +- api/client/pull.go | 2 +- api/client/push.go | 2 +- api/client/rename.go | 2 +- api/client/restart.go | 2 +- api/client/rm.go | 2 +- api/client/rmi.go | 2 +- api/client/run.go | 2 +- api/client/save.go | 2 +- api/client/search.go | 2 +- api/client/start.go | 2 +- api/client/stats.go | 2 +- api/client/stop.go | 2 +- api/client/tag.go | 2 +- api/client/top.go | 2 +- api/client/unpause.go | 2 +- api/client/version.go | 2 +- api/client/volume.go | 2 +- api/client/wait.go | 2 +- cli/common.go | 58 +++++++++++++++++++++++++++++++ docker/docker.go | 2 +- docker/flags.go | 66 +++++++++--------------------------- docker/flags_experimental.go | 8 +++-- 44 files changed, 122 insertions(+), 94 deletions(-) diff --git a/api/client/attach.go b/api/client/attach.go index 584c53ea06..8d0569b07d 100644 --- a/api/client/attach.go +++ b/api/client/attach.go @@ -17,7 +17,7 @@ import ( // // Usage: docker attach [OPTIONS] CONTAINER func (cli *DockerCli) CmdAttach(args ...string) error { - cmd := Cli.Subcmd("attach", []string{"CONTAINER"}, "Attach to a running container", true) + cmd := Cli.Subcmd("attach", []string{"CONTAINER"}, Cli.DockerCommands["attach"].Description, 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") diff --git a/api/client/build.go b/api/client/build.go index 965fbe696c..66dfbf6c24 100644 --- a/api/client/build.go +++ b/api/client/build.go @@ -49,7 +49,7 @@ const ( // // Usage: docker build [OPTIONS] PATH | URL | - func (cli *DockerCli) CmdBuild(args ...string) error { - cmd := Cli.Subcmd("build", []string{"PATH | URL | -"}, "Build a new image from the source code at PATH", true) + cmd := Cli.Subcmd("build", []string{"PATH | URL | -"}, Cli.DockerCommands["build"].Description, true) tag := cmd.String([]string{"t", "-tag"}, "", "Repository name (and optionally a tag) for the image") suppressOutput := cmd.Bool([]string{"q", "-quiet"}, false, "Suppress the verbose output generated by the containers") noCache := cmd.Bool([]string{"#no-cache", "-no-cache"}, false, "Do not use cache when building the image") diff --git a/api/client/commit.go b/api/client/commit.go index fe4acd481b..6a837881e8 100644 --- a/api/client/commit.go +++ b/api/client/commit.go @@ -18,7 +18,7 @@ import ( // // Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] func (cli *DockerCli) CmdCommit(args ...string) error { - cmd := Cli.Subcmd("commit", []string{"CONTAINER [REPOSITORY[:TAG]]"}, "Create a new image from a container's changes", true) + cmd := Cli.Subcmd("commit", []string{"CONTAINER [REPOSITORY[:TAG]]"}, Cli.DockerCommands["commit"].Description, true) flPause := cmd.Bool([]string{"p", "-pause"}, true, "Pause container during commit") flComment := cmd.String([]string{"m", "-message"}, "", "Commit message") flAuthor := cmd.String([]string{"a", "#author", "-author"}, "", "Author (e.g., \"John Hannibal Smith \")") diff --git a/api/client/cp.go b/api/client/cp.go index 4876ae2cdc..c055fced51 100644 --- a/api/client/cp.go +++ b/api/client/cp.go @@ -43,8 +43,8 @@ func (cli *DockerCli) CmdCp(args ...string) error { "cp", []string{"CONTAINER:PATH LOCALPATH|-", "LOCALPATH|- CONTAINER:PATH"}, strings.Join([]string{ - "Copy files/folders between a container and your host.\n", - "Use '-' as the source to read a tar archive from stdin\n", + Cli.DockerCommands["cp"].Description, + "\nUse '-' as the source to read a tar archive from stdin\n", "and extract it to a directory destination in a container.\n", "Use '-' as the destination to stream a tar archive of a\n", "container source to stdout.", diff --git a/api/client/create.go b/api/client/create.go index 47e69feb26..9ef0edab6c 100644 --- a/api/client/create.go +++ b/api/client/create.go @@ -159,7 +159,7 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc // // Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...] func (cli *DockerCli) CmdCreate(args ...string) error { - cmd := Cli.Subcmd("create", []string{"IMAGE [COMMAND] [ARG...]"}, "Create a new container", true) + cmd := Cli.Subcmd("create", []string{"IMAGE [COMMAND] [ARG...]"}, Cli.DockerCommands["create"].Description, true) addTrustedFlags(cmd, true) // These are flags not stored in Config/HostConfig diff --git a/api/client/diff.go b/api/client/diff.go index b955774ccd..24350a04a0 100644 --- a/api/client/diff.go +++ b/api/client/diff.go @@ -18,7 +18,7 @@ import ( // // Usage: docker diff CONTAINER func (cli *DockerCli) CmdDiff(args ...string) error { - cmd := Cli.Subcmd("diff", []string{"CONTAINER"}, "Inspect changes on a container's filesystem", true) + cmd := Cli.Subcmd("diff", []string{"CONTAINER"}, Cli.DockerCommands["diff"].Description, true) cmd.Require(flag.Exact, 1) cmd.ParseFlags(args, true) diff --git a/api/client/events.go b/api/client/events.go index c0168bdb15..435b13e6d9 100644 --- a/api/client/events.go +++ b/api/client/events.go @@ -15,7 +15,7 @@ import ( // // Usage: docker events [OPTIONS] func (cli *DockerCli) CmdEvents(args ...string) error { - cmd := Cli.Subcmd("events", nil, "Get real time events from the server", true) + cmd := Cli.Subcmd("events", nil, Cli.DockerCommands["events"].Description, true) since := cmd.String([]string{"#since", "-since"}, "", "Show all events created since timestamp") until := cmd.String([]string{"-until"}, "", "Stream events until this timestamp") flFilter := opts.NewListOpts(nil) diff --git a/api/client/exec.go b/api/client/exec.go index d02c019bca..42cdf2fed3 100644 --- a/api/client/exec.go +++ b/api/client/exec.go @@ -16,7 +16,7 @@ import ( // // Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] func (cli *DockerCli) CmdExec(args ...string) error { - cmd := Cli.Subcmd("exec", []string{"CONTAINER COMMAND [ARG...]"}, "Run a command in a running container", true) + cmd := Cli.Subcmd("exec", []string{"CONTAINER COMMAND [ARG...]"}, Cli.DockerCommands["exec"].Description, true) execConfig, err := runconfig.ParseExec(cmd, args) // just in case the ParseExec does not exit diff --git a/api/client/export.go b/api/client/export.go index 4d35d54b6e..2763b7b045 100644 --- a/api/client/export.go +++ b/api/client/export.go @@ -14,7 +14,7 @@ import ( // // Usage: docker export [OPTIONS] CONTAINER func (cli *DockerCli) CmdExport(args ...string) error { - cmd := Cli.Subcmd("export", []string{"CONTAINER"}, "Export the contents of a container's filesystem as a tar archive", true) + cmd := Cli.Subcmd("export", []string{"CONTAINER"}, Cli.DockerCommands["export"].Description, true) outfile := cmd.String([]string{"o", "-output"}, "", "Write to a file, instead of STDOUT") cmd.Require(flag.Exact, 1) diff --git a/api/client/history.go b/api/client/history.go index 2c443efd3c..cf0e4e08e7 100644 --- a/api/client/history.go +++ b/api/client/history.go @@ -19,7 +19,7 @@ import ( // // Usage: docker history [OPTIONS] IMAGE func (cli *DockerCli) CmdHistory(args ...string) error { - cmd := Cli.Subcmd("history", []string{"IMAGE"}, "Show the history of an image", true) + cmd := Cli.Subcmd("history", []string{"IMAGE"}, Cli.DockerCommands["history"].Description, true) human := cmd.Bool([]string{"H", "-human"}, true, "Print sizes and dates in human readable format") quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only show numeric IDs") noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output") diff --git a/api/client/images.go b/api/client/images.go index c4562fc8cb..ed001de745 100644 --- a/api/client/images.go +++ b/api/client/images.go @@ -22,7 +22,7 @@ import ( // // Usage: docker images [OPTIONS] [REPOSITORY] func (cli *DockerCli) CmdImages(args ...string) error { - cmd := Cli.Subcmd("images", []string{"[REPOSITORY[:TAG]]"}, "List images", true) + cmd := Cli.Subcmd("images", []string{"[REPOSITORY[:TAG]]"}, Cli.DockerCommands["images"].Description, true) quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only show numeric IDs") all := cmd.Bool([]string{"a", "-all"}, false, "Show all images (default hides intermediate images)") noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output") diff --git a/api/client/import.go b/api/client/import.go index 9bb8818cd3..c64e88d3c1 100644 --- a/api/client/import.go +++ b/api/client/import.go @@ -20,7 +20,7 @@ import ( // // Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]] func (cli *DockerCli) CmdImport(args ...string) error { - cmd := Cli.Subcmd("import", []string{"file|URL|- [REPOSITORY[:TAG]]"}, "Create an empty filesystem image and import the contents of the\ntarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it, then\noptionally tag it.", true) + cmd := Cli.Subcmd("import", []string{"file|URL|- [REPOSITORY[:TAG]]"}, Cli.DockerCommands["import"].Description, true) flChanges := opts.NewListOpts(nil) cmd.Var(&flChanges, []string{"c", "-change"}, "Apply Dockerfile instruction to the created image") message := cmd.String([]string{"m", "-message"}, "", "Set commit message for imported image") diff --git a/api/client/info.go b/api/client/info.go index 35ee5ee3d8..22b7ebb806 100644 --- a/api/client/info.go +++ b/api/client/info.go @@ -16,7 +16,7 @@ import ( // // Usage: docker info func (cli *DockerCli) CmdInfo(args ...string) error { - cmd := Cli.Subcmd("info", nil, "Display system-wide information", true) + cmd := Cli.Subcmd("info", nil, Cli.DockerCommands["info"].Description, true) cmd.Require(flag.Exact, 0) cmd.ParseFlags(args, true) diff --git a/api/client/inspect.go b/api/client/inspect.go index 6e728bdf6b..66517c9514 100644 --- a/api/client/inspect.go +++ b/api/client/inspect.go @@ -24,7 +24,7 @@ var funcMap = template.FuncMap{ // // Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...] 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) + cmd := Cli.Subcmd("inspect", []string{"CONTAINER|IMAGE [CONTAINER|IMAGE...]"}, Cli.DockerCommands["inspect"].Description, 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) diff --git a/api/client/kill.go b/api/client/kill.go index 63abed31f6..c4c355c74b 100644 --- a/api/client/kill.go +++ b/api/client/kill.go @@ -11,7 +11,7 @@ import ( // // Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...] func (cli *DockerCli) CmdKill(args ...string) error { - cmd := Cli.Subcmd("kill", []string{"CONTAINER [CONTAINER...]"}, "Kill a running container using SIGKILL or a specified signal", true) + cmd := Cli.Subcmd("kill", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["kill"].Description, true) signal := cmd.String([]string{"s", "-signal"}, "KILL", "Signal to send to the container") cmd.Require(flag.Min, 1) diff --git a/api/client/load.go b/api/client/load.go index 9501db4f82..378170e17e 100644 --- a/api/client/load.go +++ b/api/client/load.go @@ -14,7 +14,7 @@ import ( // // Usage: docker load [OPTIONS] func (cli *DockerCli) CmdLoad(args ...string) error { - cmd := Cli.Subcmd("load", nil, "Load an image from a tar archive or STDIN", true) + cmd := Cli.Subcmd("load", nil, Cli.DockerCommands["load"].Description, true) infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN") cmd.Require(flag.Exact, 0) diff --git a/api/client/login.go b/api/client/login.go index 7e3d73ca05..3fb20da1a5 100644 --- a/api/client/login.go +++ b/api/client/login.go @@ -22,7 +22,7 @@ import ( // // Usage: docker login SERVER func (cli *DockerCli) CmdLogin(args ...string) error { - cmd := Cli.Subcmd("login", []string{"[SERVER]"}, "Register or log in to a Docker registry server, if no server is\nspecified \""+registry.IndexServer+"\" is the default.", true) + cmd := Cli.Subcmd("login", []string{"[SERVER]"}, Cli.DockerCommands["login"].Description+".\nIf no server is specified \""+registry.IndexServer+"\" is the default.", true) cmd.Require(flag.Max, 1) var username, password, email string diff --git a/api/client/logout.go b/api/client/logout.go index f148548dd4..3753cbbe74 100644 --- a/api/client/logout.go +++ b/api/client/logout.go @@ -14,7 +14,7 @@ import ( // // Usage: docker logout [SERVER] func (cli *DockerCli) CmdLogout(args ...string) error { - cmd := Cli.Subcmd("logout", []string{"[SERVER]"}, "Log out from a Docker registry, if no server is\nspecified \""+registry.IndexServer+"\" is the default.", true) + cmd := Cli.Subcmd("logout", []string{"[SERVER]"}, Cli.DockerCommands["logout"].Description+".\nIf no server is specified \""+registry.IndexServer+"\" is the default.", true) cmd.Require(flag.Max, 1) cmd.ParseFlags(args, true) diff --git a/api/client/logs.go b/api/client/logs.go index ef81b7843c..f6704542b9 100644 --- a/api/client/logs.go +++ b/api/client/logs.go @@ -15,7 +15,7 @@ import ( // // docker logs [OPTIONS] CONTAINER func (cli *DockerCli) CmdLogs(args ...string) error { - cmd := Cli.Subcmd("logs", []string{"CONTAINER"}, "Fetch the logs of a container", true) + cmd := Cli.Subcmd("logs", []string{"CONTAINER"}, Cli.DockerCommands["logs"].Description, 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") diff --git a/api/client/pause.go b/api/client/pause.go index 94dd59d7e1..e144a0bd55 100644 --- a/api/client/pause.go +++ b/api/client/pause.go @@ -11,7 +11,7 @@ import ( // // Usage: docker pause CONTAINER [CONTAINER...] func (cli *DockerCli) CmdPause(args ...string) error { - cmd := Cli.Subcmd("pause", []string{"CONTAINER [CONTAINER...]"}, "Pause all processes within a container", true) + cmd := Cli.Subcmd("pause", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["pause"].Description, true) cmd.Require(flag.Min, 1) cmd.ParseFlags(args, true) diff --git a/api/client/port.go b/api/client/port.go index d8bcbf6eff..a981bc5e63 100644 --- a/api/client/port.go +++ b/api/client/port.go @@ -15,7 +15,7 @@ import ( // // Usage: docker port CONTAINER [PRIVATE_PORT[/PROTO]] 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 := Cli.Subcmd("port", []string{"CONTAINER [PRIVATE_PORT[/PROTO]]"}, Cli.DockerCommands["port"].Description, true) cmd.Require(flag.Min, 1) cmd.ParseFlags(args, true) diff --git a/api/client/ps.go b/api/client/ps.go index 88ca1ee671..50d76fbcb4 100644 --- a/api/client/ps.go +++ b/api/client/ps.go @@ -23,7 +23,7 @@ func (cli *DockerCli) CmdPs(args ...string) error { psFilterArgs = filters.Args{} v = url.Values{} - cmd = Cli.Subcmd("ps", nil, "List containers", true) + cmd = Cli.Subcmd("ps", nil, Cli.DockerCommands["ps"].Description, true) quiet = cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs") size = cmd.Bool([]string{"s", "-size"}, false, "Display total file sizes") all = cmd.Bool([]string{"a", "-all"}, false, "Show all containers (default shows just running)") diff --git a/api/client/pull.go b/api/client/pull.go index ecce34161e..dcb2ecb0c7 100644 --- a/api/client/pull.go +++ b/api/client/pull.go @@ -15,7 +15,7 @@ import ( // // Usage: docker pull [OPTIONS] IMAGENAME[:TAG|@DIGEST] func (cli *DockerCli) CmdPull(args ...string) error { - cmd := Cli.Subcmd("pull", []string{"NAME[:TAG|@DIGEST]"}, "Pull an image or a repository from a registry", true) + cmd := Cli.Subcmd("pull", []string{"NAME[:TAG|@DIGEST]"}, Cli.DockerCommands["pull"].Description, true) allTags := cmd.Bool([]string{"a", "-all-tags"}, false, "Download all tagged images in the repository") addTrustedFlags(cmd, true) cmd.Require(flag.Exact, 1) diff --git a/api/client/push.go b/api/client/push.go index 5d01511ca7..0c8823f051 100644 --- a/api/client/push.go +++ b/api/client/push.go @@ -14,7 +14,7 @@ import ( // // Usage: docker push NAME[:TAG] func (cli *DockerCli) CmdPush(args ...string) error { - cmd := Cli.Subcmd("push", []string{"NAME[:TAG]"}, "Push an image or a repository to a registry", true) + cmd := Cli.Subcmd("push", []string{"NAME[:TAG]"}, Cli.DockerCommands["push"].Description, true) addTrustedFlags(cmd, false) cmd.Require(flag.Exact, 1) diff --git a/api/client/rename.go b/api/client/rename.go index e222647018..124ee1fc4c 100644 --- a/api/client/rename.go +++ b/api/client/rename.go @@ -12,7 +12,7 @@ import ( // // Usage: docker rename OLD_NAME NEW_NAME func (cli *DockerCli) CmdRename(args ...string) error { - cmd := Cli.Subcmd("rename", []string{"OLD_NAME NEW_NAME"}, "Rename a container", true) + cmd := Cli.Subcmd("rename", []string{"OLD_NAME NEW_NAME"}, Cli.DockerCommands["rename"].Description, true) cmd.Require(flag.Exact, 2) cmd.ParseFlags(args, true) diff --git a/api/client/restart.go b/api/client/restart.go index 8d050ff71e..92c612926e 100644 --- a/api/client/restart.go +++ b/api/client/restart.go @@ -13,7 +13,7 @@ import ( // // Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...] func (cli *DockerCli) CmdRestart(args ...string) error { - cmd := Cli.Subcmd("restart", []string{"CONTAINER [CONTAINER...]"}, "Restart a container", true) + cmd := Cli.Subcmd("restart", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["restart"].Description, true) nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing the container") cmd.Require(flag.Min, 1) diff --git a/api/client/rm.go b/api/client/rm.go index 5766727a94..9f49a2fd46 100644 --- a/api/client/rm.go +++ b/api/client/rm.go @@ -13,7 +13,7 @@ import ( // // Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] func (cli *DockerCli) CmdRm(args ...string) error { - cmd := Cli.Subcmd("rm", []string{"CONTAINER [CONTAINER...]"}, "Remove one or more containers", true) + cmd := Cli.Subcmd("rm", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["rm"].Description, true) v := cmd.Bool([]string{"v", "-volumes"}, false, "Remove the volumes associated with the container") link := cmd.Bool([]string{"l", "#link", "-link"}, false, "Remove the specified link") force := cmd.Bool([]string{"f", "-force"}, false, "Force the removal of a running container (uses SIGKILL)") diff --git a/api/client/rmi.go b/api/client/rmi.go index 25d5646ebe..b4e3700684 100644 --- a/api/client/rmi.go +++ b/api/client/rmi.go @@ -14,7 +14,7 @@ import ( // // Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] func (cli *DockerCli) CmdRmi(args ...string) error { - cmd := Cli.Subcmd("rmi", []string{"IMAGE [IMAGE...]"}, "Remove one or more images", true) + cmd := Cli.Subcmd("rmi", []string{"IMAGE [IMAGE...]"}, Cli.DockerCommands["rmi"].Description, 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) diff --git a/api/client/run.go b/api/client/run.go index 50fccfa390..260d187cbb 100644 --- a/api/client/run.go +++ b/api/client/run.go @@ -40,7 +40,7 @@ func (cid *cidFile) Write(id string) error { // // Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] func (cli *DockerCli) CmdRun(args ...string) error { - cmd := Cli.Subcmd("run", []string{"IMAGE [COMMAND] [ARG...]"}, "Run a command in a new container", true) + cmd := Cli.Subcmd("run", []string{"IMAGE [COMMAND] [ARG...]"}, Cli.DockerCommands["run"].Description, true) addTrustedFlags(cmd, true) // These are flags not stored in Config/HostConfig diff --git a/api/client/save.go b/api/client/save.go index 05f231b147..f14f9a450c 100644 --- a/api/client/save.go +++ b/api/client/save.go @@ -15,7 +15,7 @@ import ( // // Usage: docker save [OPTIONS] IMAGE [IMAGE...] func (cli *DockerCli) CmdSave(args ...string) error { - cmd := Cli.Subcmd("save", []string{"IMAGE [IMAGE...]"}, "Save an image(s) to a tar archive (streamed to STDOUT by default)", true) + cmd := Cli.Subcmd("save", []string{"IMAGE [IMAGE...]"}, Cli.DockerCommands["save"].Description+" (streamed to STDOUT by default)", true) outfile := cmd.String([]string{"o", "-output"}, "", "Write to a file, instead of STDOUT") cmd.Require(flag.Min, 1) diff --git a/api/client/search.go b/api/client/search.go index da6851b4aa..bf120cddc7 100644 --- a/api/client/search.go +++ b/api/client/search.go @@ -26,7 +26,7 @@ func (r ByStars) Less(i, j int) bool { return r[i].StarCount < r[j].StarCount } // // Usage: docker search [OPTIONS] TERM func (cli *DockerCli) CmdSearch(args ...string) error { - cmd := Cli.Subcmd("search", []string{"TERM"}, "Search the Docker Hub for images", true) + cmd := Cli.Subcmd("search", []string{"TERM"}, Cli.DockerCommands["search"].Description, true) noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output") trusted := cmd.Bool([]string{"#t", "#trusted", "#-trusted"}, false, "Only show trusted builds") automated := cmd.Bool([]string{"-automated"}, false, "Only show automated builds") diff --git a/api/client/start.go b/api/client/start.go index a7e624c4c5..4b1c734749 100644 --- a/api/client/start.go +++ b/api/client/start.go @@ -45,7 +45,7 @@ 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 containers", true) + cmd := Cli.Subcmd("start", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["start"].Description, 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) diff --git a/api/client/stats.go b/api/client/stats.go index 569385326d..360d132d3b 100644 --- a/api/client/stats.go +++ b/api/client/stats.go @@ -141,7 +141,7 @@ func (s *containerStats) Display(w io.Writer) error { // // Usage: docker stats CONTAINER [CONTAINER...] 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) + cmd := Cli.Subcmd("stats", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["stats"].Description, true) noStream := cmd.Bool([]string{"-no-stream"}, false, "Disable streaming stats and only pull the first result") cmd.Require(flag.Min, 1) diff --git a/api/client/stop.go b/api/client/stop.go index e195d4a150..91f5e65b0e 100644 --- a/api/client/stop.go +++ b/api/client/stop.go @@ -15,7 +15,7 @@ import ( // // Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...] func (cli *DockerCli) CmdStop(args ...string) error { - cmd := Cli.Subcmd("stop", []string{"CONTAINER [CONTAINER...]"}, "Stop a container by sending SIGTERM and then SIGKILL after a\ngrace period", true) + cmd := Cli.Subcmd("stop", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["stop"].Description+".\nSending SIGTERM and then SIGKILL after a grace period", true) nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing it") cmd.Require(flag.Min, 1) diff --git a/api/client/tag.go b/api/client/tag.go index 454c7ec5b4..b2fd059269 100644 --- a/api/client/tag.go +++ b/api/client/tag.go @@ -13,7 +13,7 @@ import ( // // Usage: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG] func (cli *DockerCli) CmdTag(args ...string) error { - cmd := Cli.Subcmd("tag", []string{"IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]"}, "Tag an image into a repository", true) + cmd := Cli.Subcmd("tag", []string{"IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]"}, Cli.DockerCommands["tag"].Description, true) force := cmd.Bool([]string{"f", "#force", "-force"}, false, "Force") cmd.Require(flag.Exact, 2) diff --git a/api/client/top.go b/api/client/top.go index c9934fe08d..8327820aae 100644 --- a/api/client/top.go +++ b/api/client/top.go @@ -16,7 +16,7 @@ import ( // // Usage: docker top CONTAINER func (cli *DockerCli) CmdTop(args ...string) error { - cmd := Cli.Subcmd("top", []string{"CONTAINER [ps OPTIONS]"}, "Display the running processes of a container", true) + cmd := Cli.Subcmd("top", []string{"CONTAINER [ps OPTIONS]"}, Cli.DockerCommands["top"].Description, true) cmd.Require(flag.Min, 1) cmd.ParseFlags(args, true) diff --git a/api/client/unpause.go b/api/client/unpause.go index cd1e676673..21e25857cf 100644 --- a/api/client/unpause.go +++ b/api/client/unpause.go @@ -11,7 +11,7 @@ import ( // // Usage: docker unpause CONTAINER [CONTAINER...] func (cli *DockerCli) CmdUnpause(args ...string) error { - cmd := Cli.Subcmd("unpause", []string{"CONTAINER [CONTAINER...]"}, "Unpause all processes within a container", true) + cmd := Cli.Subcmd("unpause", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["unpause"].Description, true) cmd.Require(flag.Min, 1) cmd.ParseFlags(args, true) diff --git a/api/client/version.go b/api/client/version.go index fbfeaec34f..43cde71ec4 100644 --- a/api/client/version.go +++ b/api/client/version.go @@ -43,7 +43,7 @@ type versionData struct { // // Usage: docker version func (cli *DockerCli) CmdVersion(args ...string) (err error) { - cmd := Cli.Subcmd("version", nil, "Show the Docker version information.", true) + cmd := Cli.Subcmd("version", nil, Cli.DockerCommands["version"].Description, true) tmplStr := cmd.String([]string{"f", "#format", "-format"}, "", "Format the output using the given go template") cmd.Require(flag.Exact, 0) diff --git a/api/client/volume.go b/api/client/volume.go index 740f3d7b7a..4e9930bc5f 100644 --- a/api/client/volume.go +++ b/api/client/volume.go @@ -20,7 +20,7 @@ import ( // // Usage: docker volume func (cli *DockerCli) CmdVolume(args ...string) error { - description := "Manage Docker volumes\n\nCommands:\n" + description := Cli.DockerCommands["volume"].Description + "\n\nCommands:\n" commands := [][]string{ {"create", "Create a volume"}, {"inspect", "Return low-level information on a volume"}, diff --git a/api/client/wait.go b/api/client/wait.go index 829a320cfe..3b03f7069e 100644 --- a/api/client/wait.go +++ b/api/client/wait.go @@ -13,7 +13,7 @@ import ( // // Usage: docker wait CONTAINER [CONTAINER...] func (cli *DockerCli) CmdWait(args ...string) error { - cmd := Cli.Subcmd("wait", []string{"CONTAINER [CONTAINER...]"}, "Block until a container stops, then print its exit code.", true) + cmd := Cli.Subcmd("wait", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["wait"].Description, true) cmd.Require(flag.Min, 1) cmd.ParseFlags(args, true) diff --git a/cli/common.go b/cli/common.go index 85a02ac43b..d3aa391be2 100644 --- a/cli/common.go +++ b/cli/common.go @@ -18,3 +18,61 @@ type CommonFlags struct { TLSOptions *tlsconfig.Options TrustKey string } + +// Command is the struct contains command name and description +type Command struct { + Name string + Description string +} + +var dockerCommands = []Command{ + {"attach", "Attach to a running container"}, + {"build", "Build an image from a Dockerfile"}, + {"commit", "Create a new image from a container's changes"}, + {"cp", "Copy files/folders between a container and the local filesystem"}, + {"create", "Create a new container"}, + {"diff", "Inspect changes on a container's filesystem"}, + {"events", "Get real time events from the server"}, + {"exec", "Run a command in a running container"}, + {"export", "Export a container's filesystem as a tar archive"}, + {"history", "Show the history of an image"}, + {"images", "List images"}, + {"import", "Import the contents from a tarball to create a filesystem image"}, + {"info", "Display system-wide information"}, + {"inspect", "Return low-level information on a container or image"}, + {"kill", "Kill a running container"}, + {"load", "Load an image from a tar archive or STDIN"}, + {"login", "Register or log in to a Docker registry"}, + {"logout", "Log out from a Docker registry"}, + {"logs", "Fetch the logs of a container"}, + {"pause", "Pause all processes within a container"}, + {"port", "List port mappings or a specific mapping for the CONTAINER"}, + {"ps", "List containers"}, + {"pull", "Pull an image or a repository from a registry"}, + {"push", "Push an image or a repository to a registry"}, + {"rename", "Rename a container"}, + {"restart", "Restart a container"}, + {"rm", "Remove one or more containers"}, + {"rmi", "Remove one or more images"}, + {"run", "Run a command in a new container"}, + {"save", "Save an image(s) to a tar archive"}, + {"search", "Search the Docker Hub for images"}, + {"start", "Start one or more stopped containers"}, + {"stats", "Display a live stream of container(s) resource usage statistics"}, + {"stop", "Stop a running container"}, + {"tag", "Tag an image into a repository"}, + {"top", "Display the running processes of a container"}, + {"unpause", "Unpause all processes within a container"}, + {"version", "Show the Docker version information"}, + {"volume", "Manage Docker volumes"}, + {"wait", "Block until a container stops, then print its exit code"}, +} + +// DockerCommands stores all the docker command +var DockerCommands = make(map[string]Command) + +func init() { + for _, cmd := range dockerCommands { + DockerCommands[cmd.Name] = cmd + } +} diff --git a/docker/docker.go b/docker/docker.go index f727fb1f69..4795b8046d 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -36,7 +36,7 @@ func main() { help := "\nCommands:\n" for _, cmd := range dockerCommands { - help += fmt.Sprintf(" %-10.10s%s\n", cmd.name, cmd.description) + help += fmt.Sprintf(" %-10.10s%s\n", cmd.Name, cmd.Description) } help += "\nRun 'docker COMMAND --help' for more information on a command." diff --git a/docker/flags.go b/docker/flags.go index de517ddc73..35a8108880 100644 --- a/docker/flags.go +++ b/docker/flags.go @@ -1,64 +1,30 @@ package main -import flag "github.com/docker/docker/pkg/mflag" +import ( + "sort" + + "github.com/docker/docker/cli" + flag "github.com/docker/docker/pkg/mflag" +) var ( flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage") flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit") ) -type command struct { - name string - description string -} - -type byName []command +type byName []cli.Command func (a byName) Len() int { return len(a) } func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a byName) Less(i, j int) bool { return a[i].name < a[j].name } +func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name } + +var dockerCommands []cli.Command // TODO(tiborvass): do not show 'daemon' on client-only binaries -// and deduplicate description in dockerCommands and cli subcommands -var dockerCommands = []command{ - {"attach", "Attach to a running container"}, - {"build", "Build an image from a Dockerfile"}, - {"commit", "Create a new image from a container's changes"}, - {"cp", "Copy files/folders between a container and the local filesystem"}, - {"create", "Create a new container"}, - {"diff", "Inspect changes on a container's filesystem"}, - {"events", "Get real time events from the server"}, - {"exec", "Run a command in a running container"}, - {"export", "Export a container's filesystem as a tar archive"}, - {"history", "Show the history of an image"}, - {"images", "List images"}, - {"import", "Import the contents from a tarball to create a filesystem image"}, - {"info", "Display system-wide information"}, - {"inspect", "Return low-level information on a container or image"}, - {"kill", "Kill a running container"}, - {"load", "Load an image from a tar archive or STDIN"}, - {"login", "Register or log in to a Docker registry"}, - {"logout", "Log out from a Docker registry"}, - {"logs", "Fetch the logs of a container"}, - {"pause", "Pause all processes within a container"}, - {"port", "List port mappings or a specific mapping for the CONTAINER"}, - {"ps", "List containers"}, - {"pull", "Pull an image or a repository from a registry"}, - {"push", "Push an image or a repository to a registry"}, - {"rename", "Rename a container"}, - {"restart", "Restart a container"}, - {"rm", "Remove one or more containers"}, - {"rmi", "Remove one or more images"}, - {"run", "Run a command in a new container"}, - {"save", "Save an image(s) to a tar archive"}, - {"search", "Search the Docker Hub for images"}, - {"start", "Start one or more containers"}, - {"stats", "Display a live stream of container(s) resource usage statistics"}, - {"stop", "Stop a container"}, - {"tag", "Tag an image into a repository"}, - {"top", "Display the running processes of a container"}, - {"unpause", "Unpause all processes within a container"}, - {"version", "Show the Docker version information"}, - {"volume", "Manage Docker volumes"}, - {"wait", "Block until a container stops, then print its exit code"}, + +func init() { + for _, cmd := range cli.DockerCommands { + dockerCommands = append(dockerCommands, cmd) + } + sort.Sort(byName(dockerCommands)) } diff --git a/docker/flags_experimental.go b/docker/flags_experimental.go index f4e9a44f7a..0994a82dd0 100644 --- a/docker/flags_experimental.go +++ b/docker/flags_experimental.go @@ -2,10 +2,14 @@ package main -import "sort" +import ( + "sort" + + "github.com/docker/docker/cli" +) func init() { - dockerCommands = append(dockerCommands, command{"network", "Network management"}) + dockerCommands = append(dockerCommands, cli.Command{Name: "network", Description: "Network management"}) //Sorting logic required here to pass Command Sort Test. sort.Sort(byName(dockerCommands))