From d530d581f7362aab16e9dfeee1143dd5c824e6c7 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 4 Apr 2013 20:19:06 -0700 Subject: [PATCH] Make commands.go more idiomatic. Use DockerConn only when needed, keep io.Writer when not --- commands.go | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/commands.go b/commands.go index 8bc451b6bf..64de8b3d0b 100644 --- a/commands.go +++ b/commands.go @@ -71,7 +71,7 @@ func (srv *Server) CmdLogin(stdin io.ReadCloser, stdout rcli.DockerConn, args .. // - we have to read a password (without echoing it); // - the rcli "protocol" only supports cannonical and raw modes and you // can't tune it once the command as been started. - var readStringOnRawTerminal = func(stdin io.Reader, stdout rcli.DockerConn, echo bool) string { + var readStringOnRawTerminal = func(stdin io.Reader, stdout io.Writer, echo bool) string { char := make([]byte, 1) buffer := make([]byte, 64) var i = 0 @@ -106,10 +106,10 @@ func (srv *Server) CmdLogin(stdin io.ReadCloser, stdout rcli.DockerConn, args .. } return string(buffer[:i]) } - var readAndEchoString = func(stdin io.Reader, stdout rcli.DockerConn) string { + var readAndEchoString = func(stdin io.Reader, stdout io.Writer) string { return readStringOnRawTerminal(stdin, stdout, true) } - var readString = func(stdin io.Reader, stdout rcli.DockerConn) string { + var readString = func(stdin io.Reader, stdout io.Writer) string { return readStringOnRawTerminal(stdin, stdout, false) } @@ -160,7 +160,7 @@ func (srv *Server) CmdLogin(stdin io.ReadCloser, stdout rcli.DockerConn, args .. } // 'docker wait': block until a container stops -func (srv *Server) CmdWait(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +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 { return nil @@ -180,14 +180,14 @@ func (srv *Server) CmdWait(stdin io.ReadCloser, stdout rcli.DockerConn, args ... } // 'docker version': show version information -func (srv *Server) CmdVersion(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdVersion(stdin io.ReadCloser, stdout io.Writer, args ...string) error { fmt.Fprintf(stdout, "Version:%s\n", VERSION) fmt.Fprintf(stdout, "Git Commit:%s\n", GIT_COMMIT) return nil } // 'docker info': display system-wide information. -func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout io.Writer, args ...string) error { images, _ := srv.runtime.graph.All() var imgcount int if images == nil { @@ -216,7 +216,7 @@ func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout rcli.DockerConn, args ... return nil } -func (srv *Server) CmdStop(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +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 { return nil @@ -238,7 +238,7 @@ func (srv *Server) CmdStop(stdin io.ReadCloser, stdout rcli.DockerConn, args ... return nil } -func (srv *Server) CmdRestart(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +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 { return nil @@ -260,7 +260,7 @@ func (srv *Server) CmdRestart(stdin io.ReadCloser, stdout rcli.DockerConn, args return nil } -func (srv *Server) CmdStart(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +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 { return nil @@ -282,7 +282,7 @@ func (srv *Server) CmdStart(stdin io.ReadCloser, stdout rcli.DockerConn, args .. return nil } -func (srv *Server) CmdInspect(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +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 { return nil @@ -317,7 +317,7 @@ func (srv *Server) CmdInspect(stdin io.ReadCloser, stdout rcli.DockerConn, args return nil } -func (srv *Server) CmdPort(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +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 { return nil @@ -341,7 +341,7 @@ func (srv *Server) CmdPort(stdin io.ReadCloser, stdout rcli.DockerConn, args ... } // 'docker rmi NAME' removes all images with the name NAME -func (srv *Server) CmdRmi(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) (err error) { +func (srv *Server) CmdRmi(stdin io.ReadCloser, stdout io.Writer, args ...string) (err error) { cmd := rcli.Subcmd(stdout, "rmimage", "[OPTIONS] IMAGE", "Remove an image") if err := cmd.Parse(args); err != nil { return nil @@ -358,7 +358,7 @@ func (srv *Server) CmdRmi(stdin io.ReadCloser, stdout rcli.DockerConn, args ...s return nil } -func (srv *Server) CmdHistory(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdHistory(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "history", "[OPTIONS] IMAGE", "Show the history of an image") if err := cmd.Parse(args); err != nil { return nil @@ -384,7 +384,7 @@ func (srv *Server) CmdHistory(stdin io.ReadCloser, stdout rcli.DockerConn, args }) } -func (srv *Server) CmdRm(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdRm(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "rm", "[OPTIONS] CONTAINER", "Remove a container") if err := cmd.Parse(args); err != nil { return nil @@ -402,7 +402,7 @@ func (srv *Server) CmdRm(stdin io.ReadCloser, stdout rcli.DockerConn, args ...st } // 'docker kill NAME' kills a running container -func (srv *Server) CmdKill(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdKill(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "kill", "[OPTIONS] CONTAINER [CONTAINER...]", "Kill a running container") if err := cmd.Parse(args); err != nil { return nil @@ -419,7 +419,7 @@ func (srv *Server) CmdKill(stdin io.ReadCloser, stdout rcli.DockerConn, args ... return nil } -func (srv *Server) CmdImport(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdImport(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "import", "[OPTIONS] URL|- [REPOSITORY [TAG]]", "Create a new filesystem image from the contents of a tarball") var archive io.Reader var resp *http.Response @@ -525,7 +525,7 @@ func (srv *Server) CmdPush(stdin io.ReadCloser, stdout rcli.DockerConn, args ... return nil } -func (srv *Server) CmdPull(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "pull", "NAME", "Pull an image or a repository from the registry") if err := cmd.Parse(args); err != nil { return nil @@ -550,7 +550,7 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout rcli.DockerConn, args ... return nil } -func (srv *Server) CmdImages(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...string) error { 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") @@ -640,7 +640,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout rcli.DockerConn, args . return nil } -func (srv *Server) CmdPs(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "ps", "[OPTIONS]", "List containers") quiet := cmd.Bool("q", false, "Only display numeric IDs") @@ -687,7 +687,7 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout rcli.DockerConn, args ...st return nil } -func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "commit", "[OPTIONS] CONTAINER [REPOSITORY [TAG]]", "Create a new image from a container's changes") @@ -708,7 +708,7 @@ func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout rcli.DockerConn, args . return nil } -func (srv *Server) CmdExport(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdExport(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "export", "CONTAINER", "Export the contents of a filesystem as a tar archive") @@ -730,7 +730,7 @@ func (srv *Server) CmdExport(stdin io.ReadCloser, stdout rcli.DockerConn, args . return fmt.Errorf("No such container: %s", name) } -func (srv *Server) CmdDiff(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdDiff(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "diff", "CONTAINER [OPTIONS]", "Inspect changes on a container's filesystem") @@ -754,7 +754,7 @@ func (srv *Server) CmdDiff(stdin io.ReadCloser, stdout rcli.DockerConn, args ... return nil } -func (srv *Server) CmdLogs(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdLogs(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "logs", "[OPTIONS] CONTAINER", "Fetch the logs of a container") if err := cmd.Parse(args); err != nil { return nil @@ -860,7 +860,7 @@ func (opts AttachOpts) Get(val string) bool { return false } -func (srv *Server) CmdTag(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error { +func (srv *Server) CmdTag(stdin io.ReadCloser, stdout io.Writer, args ...string) error { cmd := rcli.Subcmd(stdout, "tag", "[OPTIONS] IMAGE REPOSITORY [TAG]", "Tag an image into a repository") force := cmd.Bool("f", false, "Force") if err := cmd.Parse(args); err != nil {