From 06d420d2ead65cb5af760d7946d8844f568f4d65 Mon Sep 17 00:00:00 2001 From: Charles Hooper Date: Mon, 11 Mar 2013 22:08:22 +0000 Subject: [PATCH 1/3] Fix CmdInspect and CmdImages help/parsing. Fixes #38 --- server/server.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/server.go b/server/server.go index bc642cdbb0..9efdaa97da 100644 --- a/server/server.go +++ b/server/server.go @@ -60,6 +60,7 @@ func (srv *Server) Help() string { {"tar", "Stream the contents of a container as a tar archive"}, {"web", "Generate a web UI"}, {"images", "List images"}, + {"inspect", "Return low-level information on a container"}, } { help += fmt.Sprintf(" %-10.10s%s\n", cmd...) } @@ -282,7 +283,6 @@ func (srv *Server) CmdLs(stdin io.ReadCloser, stdout io.Writer, args ...string) func (srv *Server) CmdInspect(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "inspect", "[OPTIONS] CONTAINER", "Return low-level information on a container") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 1 { @@ -463,7 +463,9 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri cmd := rcli.Subcmd(stdout, "images", "[OPTIONS] [NAME]", "List images") limit := cmd.Int("l", 0, "Only show the N most recent versions of each image") quiet := cmd.Bool("q", false, "only show numeric IDs") - cmd.Parse(args) + if err := cmd.Parse(args); err != nil { + return nil + } if cmd.NArg() > 1 { cmd.Usage() return nil @@ -893,7 +895,7 @@ func New() (*Server, error) { return nil, err } srv := &Server{ - images: images, + images: images, containers: containers, } return srv, nil From a7cb3cb86a39f950a517b61e3a674e0cd080804f Mon Sep 17 00:00:00 2001 From: Charles Hooper Date: Mon, 11 Mar 2013 22:29:13 +0000 Subject: [PATCH 2/3] Complete fix for #38 -- fix double-usage on help --- server/server.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/server/server.go b/server/server.go index 9efdaa97da..3a66d7e032 100644 --- a/server/server.go +++ b/server/server.go @@ -71,7 +71,6 @@ func (srv *Server) Help() string { func (srv *Server) CmdWait(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "wait", "[OPTIONS] NAME", "Block until a container stops, then print its exit code.") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 1 { @@ -100,7 +99,6 @@ func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout io.Writer, args ...string func (srv *Server) CmdStop(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "stop", "[OPTIONS] NAME", "Stop a running container") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 1 { @@ -123,7 +121,6 @@ func (srv *Server) CmdStop(stdin io.ReadCloser, stdout io.Writer, args ...string func (srv *Server) CmdRestart(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "restart", "[OPTIONS] NAME", "Restart a running container") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 1 { @@ -146,7 +143,6 @@ func (srv *Server) CmdRestart(stdin io.ReadCloser, stdout io.Writer, args ...str func (srv *Server) CmdStart(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "start", "[OPTIONS] NAME", "Start a stopped container") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 1 { @@ -169,7 +165,6 @@ func (srv *Server) CmdStart(stdin io.ReadCloser, stdout io.Writer, args ...strin func (srv *Server) CmdUmount(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "umount", "[OPTIONS] NAME", "umount a container's filesystem (debug only)") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 1 { @@ -192,7 +187,6 @@ func (srv *Server) CmdUmount(stdin io.ReadCloser, stdout io.Writer, args ...stri func (srv *Server) CmdMount(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "umount", "[OPTIONS] NAME", "mount a container's filesystem (debug only)") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 1 { @@ -215,7 +209,6 @@ func (srv *Server) CmdMount(stdin io.ReadCloser, stdout io.Writer, args ...strin func (srv *Server) CmdCat(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "cat", "[OPTIONS] CONTAINER PATH", "write the contents of a container's file to standard output") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 2 { @@ -237,7 +230,6 @@ func (srv *Server) CmdCat(stdin io.ReadCloser, stdout io.Writer, args ...string) func (srv *Server) CmdWrite(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "write", "[OPTIONS] CONTAINER PATH", "write the contents of standard input to a container's file") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 2 { @@ -259,7 +251,6 @@ func (srv *Server) CmdWrite(stdin io.ReadCloser, stdout io.Writer, args ...strin func (srv *Server) CmdLs(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "ls", "[OPTIONS] CONTAINER PATH", "List the contents of a container's directory") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 2 { @@ -315,7 +306,6 @@ func (srv *Server) CmdInspect(stdin io.ReadCloser, stdout io.Writer, args ...str func (srv *Server) CmdPort(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "port", "[OPTIONS] CONTAINER PRIVATE_PORT", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() != 2 { @@ -341,7 +331,6 @@ func (srv *Server) CmdRmi(stdin io.ReadCloser, stdout io.Writer, args ...string) cmd := rcli.Subcmd(stdout, "rmimage", "[OPTIONS] IMAGE", "Remove an image") fl_regexp := cmd.Bool("r", false, "Use IMAGE as a regular expression instead of an exact name") if err := cmd.Parse(args); err != nil { - cmd.Usage() return nil } if cmd.NArg() < 1 { From 52b811f50a0906904d688e5fae8f32e1ada90f1a Mon Sep 17 00:00:00 2001 From: Charles Hooper Date: Mon, 11 Mar 2013 23:11:46 +0000 Subject: [PATCH 3/3] Add all commands to the output of 'dotcloud help'. Fixes #39 --- server/server.go | 54 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/server/server.go b/server/server.go index 3a66d7e032..37404f2c21 100644 --- a/server/server.go +++ b/server/server.go @@ -37,30 +37,40 @@ func (srv *Server) Name() string { return "docker" } +// FIXME: Stop violating DRY by repeating usage here and in Subcmd declarations func (srv *Server) Help() string { help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n" for _, cmd := range [][]interface{}{ - {"run", "Run a command in a container"}, - {"ps", "Display a list of containers"}, - {"pull", "Download a tarball and create a container from it"}, - {"put", "Upload a tarball and create a container from it"}, - {"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"}, - {"rm", "Remove containers"}, - {"kill", "Kill a running container"}, - {"wait", "Wait for the state of a container to change"}, - {"stop", "Stop a running container"}, - {"start", "Start a stopped container"}, - {"restart", "Restart a running container"}, - {"logs", "Fetch the logs of a container"}, + {"attach", "Attach to a running container"}, + {"cat", "Write the contents of a container's file to standard output"}, + {"commit", "Create a new image from a container's changes"}, + {"cp", "Create a copy of IMAGE and call it NAME"}, + {"debug", "(debug only) (No documentation available)"}, {"diff", "Inspect changes on a container's filesystem"}, - {"commit", "Save the state of a container"}, - {"attach", "Attach to the standard inputs and outputs of a running container"}, - {"wait", "Block until a container exits, then print its exit code"}, - {"info", "Display system-wide information"}, - {"tar", "Stream the contents of a container as a tar archive"}, - {"web", "Generate a web UI"}, {"images", "List images"}, + {"info", "Display system-wide information"}, {"inspect", "Return low-level information on a container"}, + {"kill", "Kill a running container"}, + {"layers", "(debug only) List filesystem layers"}, + {"logs", "Fetch the logs of a container"}, + {"ls", "List the contents of a container's directory"}, + {"mirror", "(debug only) (No documentation available)"}, + {"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"}, + {"ps", "List containers"}, + {"pull", "Download a new image from a remote location"}, + {"put", "Import a new image from a local archive"}, + {"reset", "Reset changes to a container's filesystem"}, + {"restart", "Restart a running container"}, + {"rm", "Remove a container"}, + {"rmimage", "Remove an image"}, + {"run", "Run a command in a new container"}, + {"start", "Start a stopped container"}, + {"stop", "Stop a running container"}, + {"tar", "Stream the contents of a container as a tar archive"}, + {"umount", "(debug only) Mount a container's filesystem"}, + {"wait", "Block until a container stops, then print its exit code"}, + {"web", "A web UI for docker"}, + {"write", "Write the contents of standard input to a container's file"}, } { help += fmt.Sprintf(" %-10.10s%s\n", cmd...) } @@ -89,6 +99,14 @@ func (srv *Server) CmdWait(stdin io.ReadCloser, stdout io.Writer, args ...string // 'docker info': display system-wide information. func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout io.Writer, args ...string) error { + cmd := rcli.Subcmd(stdout, "info", "", "Display system-wide information.") + if err := cmd.Parse(args); err != nil { + return nil + } + if cmd.NArg() > 1 { + cmd.Usage() + return nil + } fmt.Fprintf(stdout, "containers: %d\nversion: %s\nimages: %d\n", len(srv.containers.List()), VERSION,