2015-03-24 23:57:23 -04:00
package client
import (
2015-06-25 21:25:41 -04:00
"text/template"
2015-11-30 09:44:06 -05:00
"time"
2015-03-24 23:57:23 -04:00
2015-05-05 00:18:28 -04:00
Cli "github.com/docker/docker/cli"
2015-03-24 23:57:23 -04:00
flag "github.com/docker/docker/pkg/mflag"
)
2015-07-20 20:55:30 -04:00
var versionTemplate = ` Client :
2015-06-25 21:25:41 -04:00
Version : { { . Client . Version } }
2015-07-23 05:40:54 -04:00
API version : { { . Client . APIVersion } }
2015-06-25 21:25:41 -04:00
Go version : { { . Client . GoVersion } }
Git commit : { { . Client . GitCommit } }
Built : { { . Client . BuildTime } }
OS / Arch : { { . Client . Os } } / { { . Client . Arch } } { { if . Client . Experimental } }
Experimental : { { . Client . Experimental } } { { end } } { { if . ServerOK } }
Server :
Version : { { . Server . Version } }
2015-07-23 05:40:54 -04:00
API version : { { . Server . APIVersion } }
2015-06-25 21:25:41 -04:00
Go version : { { . Server . GoVersion } }
Git commit : { { . Server . GitCommit } }
Built : { { . Server . BuildTime } }
OS / Arch : { { . Server . Os } } / { { . Server . Arch } } { { if . Server . Experimental } }
Experimental : { { . Server . Experimental } } { { end } } { { end } } `
2015-03-25 13:34:41 -04:00
// 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
2015-06-25 21:25:41 -04:00
func ( cli * DockerCli ) CmdVersion ( args ... string ) ( err error ) {
2015-10-08 08:46:21 -04:00
cmd := Cli . Subcmd ( "version" , nil , Cli . DockerCommands [ "version" ] . Description , true )
2015-06-25 21:25:41 -04:00
tmplStr := cmd . String ( [ ] string { "f" , "#format" , "-format" } , "" , "Format the output using the given go template" )
2015-03-24 23:57:23 -04:00
cmd . Require ( flag . Exact , 0 )
2015-05-23 11:57:50 -04:00
cmd . ParseFlags ( args , true )
2015-12-04 14:31:24 -05:00
templateFormat := versionTemplate
if * tmplStr != "" {
templateFormat = * tmplStr
2015-03-24 23:57:23 -04:00
}
2015-06-25 21:25:41 -04:00
var tmpl * template . Template
2015-12-04 14:31:24 -05:00
if tmpl , err = template . New ( "" ) . Funcs ( funcMap ) . Parse ( templateFormat ) ; err != nil {
2015-05-05 00:18:28 -04:00
return Cli . StatusError { StatusCode : 64 ,
2015-06-25 21:25:41 -04:00
Status : "Template parsing error: " + err . Error ( ) }
2015-06-19 13:03:13 -04:00
}
2015-06-25 21:25:41 -04:00
2015-12-04 14:31:24 -05:00
vd , err := cli . client . SystemVersion ( )
// first we need to make BuildTime more human friendly
t , errTime := time . Parse ( time . RFC3339Nano , vd . Client . BuildTime )
if errTime == nil {
vd . Client . BuildTime = t . Format ( time . ANSIC )
2015-05-28 20:59:07 -04:00
}
2015-03-24 23:57:23 -04:00
2015-12-04 14:31:24 -05:00
if vd . ServerOK ( ) {
2015-11-30 09:44:06 -05:00
t , errTime = time . Parse ( time . RFC3339Nano , vd . Server . BuildTime )
if errTime == nil {
vd . Server . BuildTime = t . Format ( time . ANSIC )
}
2015-03-24 23:57:23 -04:00
}
2015-12-04 14:31:24 -05:00
if err2 := tmpl . Execute ( cli . out , vd ) ; err2 != nil && err == nil {
err = err2
2015-03-24 23:57:23 -04:00
}
2015-12-04 14:31:24 -05:00
cli . out . Write ( [ ] byte { '\n' } )
return err
2015-03-24 23:57:23 -04:00
}