github.com/squaremo/docker@v1.3.2-0.20150516120342-42cfc9554972/api/client/version.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"runtime"
     7  
     8  	"github.com/docker/docker/api"
     9  	"github.com/docker/docker/api/types"
    10  	"github.com/docker/docker/autogen/dockerversion"
    11  	flag "github.com/docker/docker/pkg/mflag"
    12  )
    13  
    14  // CmdVersion shows Docker version information.
    15  //
    16  // 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.
    17  //
    18  // Usage: docker version
    19  func (cli *DockerCli) CmdVersion(args ...string) error {
    20  	cmd := cli.Subcmd("version", "", "Show the Docker version information.", true)
    21  	cmd.Require(flag.Exact, 0)
    22  
    23  	cmd.ParseFlags(args, false)
    24  
    25  	if dockerversion.VERSION != "" {
    26  		fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION)
    27  	}
    28  	fmt.Fprintf(cli.out, "Client API version: %s\n", api.APIVERSION)
    29  	fmt.Fprintf(cli.out, "Go version (client): %s\n", runtime.Version())
    30  	if dockerversion.GITCOMMIT != "" {
    31  		fmt.Fprintf(cli.out, "Git commit (client): %s\n", dockerversion.GITCOMMIT)
    32  	}
    33  	fmt.Fprintf(cli.out, "OS/Arch (client): %s/%s\n", runtime.GOOS, runtime.GOARCH)
    34  
    35  	stream, _, err := cli.call("GET", "/version", nil, nil)
    36  	if err != nil {
    37  		return err
    38  	}
    39  
    40  	var v types.Version
    41  	if err := json.NewDecoder(stream).Decode(&v); err != nil {
    42  		fmt.Fprintf(cli.err, "Error reading remote version: %s\n", err)
    43  		return err
    44  	}
    45  
    46  	fmt.Fprintf(cli.out, "Server version: %s\n", v.Version)
    47  	if v.ApiVersion != "" {
    48  		fmt.Fprintf(cli.out, "Server API version: %s\n", v.ApiVersion)
    49  	}
    50  	fmt.Fprintf(cli.out, "Go version (server): %s\n", v.GoVersion)
    51  	fmt.Fprintf(cli.out, "Git commit (server): %s\n", v.GitCommit)
    52  	fmt.Fprintf(cli.out, "OS/Arch (server): %s/%s\n", v.Os, v.Arch)
    53  
    54  	return nil
    55  }