mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00

Continues 11858 by: - Making sure the exit code is always zero when we ask for help - Making sure the exit code isn't zero when we print help on error cases - Making sure both short and long usage go to the same stream (stdout vs stderr) - Making sure all docker commands support --help - Test that all cmds send --help to stdout, exit code 0, show full usage, no blank lines at end - Test that all cmds (that support it) show short usage on bad arg to stderr, no blank line at end - Test that all cmds complain about a bad option, no blank line at end - Test that docker (w/o subcmd) does the same stuff mentioned above properly Signed-off-by: Doug Davis <dug@us.ibm.com>
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package client
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"runtime"
|
|
|
|
"github.com/docker/docker/api"
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/autogen/dockerversion"
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
)
|
|
|
|
// CmdVersion shows Docker version information.
|
|
//
|
|
// Available version information is shown for: client Docker version, client API version, client Go version, client Git commit, client OS/Arch, server Docker version, server API version, server Go version, server Git commit, and server OS/Arch.
|
|
//
|
|
// Usage: docker version
|
|
func (cli *DockerCli) CmdVersion(args ...string) error {
|
|
cmd := cli.Subcmd("version", "", "Show the Docker version information.", true)
|
|
cmd.Require(flag.Exact, 0)
|
|
|
|
cmd.ParseFlags(args, true)
|
|
|
|
if dockerversion.VERSION != "" {
|
|
fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION)
|
|
}
|
|
fmt.Fprintf(cli.out, "Client API version: %s\n", api.APIVERSION)
|
|
fmt.Fprintf(cli.out, "Go version (client): %s\n", runtime.Version())
|
|
if dockerversion.GITCOMMIT != "" {
|
|
fmt.Fprintf(cli.out, "Git commit (client): %s\n", dockerversion.GITCOMMIT)
|
|
}
|
|
fmt.Fprintf(cli.out, "OS/Arch (client): %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
|
|
|
stream, _, err := cli.call("GET", "/version", nil, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var v types.Version
|
|
if err := json.NewDecoder(stream).Decode(&v); err != nil {
|
|
fmt.Fprintf(cli.err, "Error reading remote version: %s\n", err)
|
|
return err
|
|
}
|
|
|
|
fmt.Fprintf(cli.out, "Server version: %s\n", v.Version)
|
|
if v.ApiVersion != "" {
|
|
fmt.Fprintf(cli.out, "Server API version: %s\n", v.ApiVersion)
|
|
}
|
|
fmt.Fprintf(cli.out, "Go version (server): %s\n", v.GoVersion)
|
|
fmt.Fprintf(cli.out, "Git commit (server): %s\n", v.GitCommit)
|
|
fmt.Fprintf(cli.out, "OS/Arch (server): %s/%s\n", v.Os, v.Arch)
|
|
|
|
return nil
|
|
}
|