Signed-off-by: Daniel Zhang <jmzwcn@gmail.com>
Daniel Zhang authored on 2017/02/15 09:21:40... | ... |
@@ -256,18 +256,6 @@ type ResizeOptions struct { |
256 | 256 |
Width uint |
257 | 257 |
} |
258 | 258 |
|
259 |
-// VersionResponse holds version information for the client and the server |
|
260 |
-type VersionResponse struct { |
|
261 |
- Client *Version |
|
262 |
- Server *Version |
|
263 |
-} |
|
264 |
- |
|
265 |
-// ServerOK returns true when the client could connect to the docker server |
|
266 |
-// and parse the information received. It returns false otherwise. |
|
267 |
-func (v VersionResponse) ServerOK() bool { |
|
268 |
- return v.Server != nil |
|
269 |
-} |
|
270 |
- |
|
271 | 259 |
// NodeListOptions holds parameters to list nodes with. |
272 | 260 |
type NodeListOptions struct { |
273 | 261 |
Filters filters.Args |
... | ... |
@@ -1,7 +1,6 @@ |
1 | 1 |
package system |
2 | 2 |
|
3 | 3 |
import ( |
4 |
- "fmt" |
|
5 | 4 |
"runtime" |
6 | 5 |
"time" |
7 | 6 |
|
... | ... |
@@ -17,7 +16,7 @@ import ( |
17 | 17 |
|
18 | 18 |
var versionTemplate = `Client: |
19 | 19 |
Version: {{.Client.Version}} |
20 |
- API version: {{.Client.APIVersion}} |
|
20 |
+ API version: {{.Client.APIVersion}}{{if ne .Client.APIVersion .Client.DefaultAPIVersion}} (downgraded from {{.Client.DefaultAPIVersion}}){{end}} |
|
21 | 21 |
Go version: {{.Client.GoVersion}} |
22 | 22 |
Git commit: {{.Client.GitCommit}} |
23 | 23 |
Built: {{.Client.BuildTime}} |
... | ... |
@@ -36,6 +35,29 @@ type versionOptions struct { |
36 | 36 |
format string |
37 | 37 |
} |
38 | 38 |
|
39 |
+// versionInfo contains version information of both the Client, and Server |
|
40 |
+type versionInfo struct { |
|
41 |
+ Client clientVersion |
|
42 |
+ Server *types.Version |
|
43 |
+} |
|
44 |
+ |
|
45 |
+type clientVersion struct { |
|
46 |
+ Version string |
|
47 |
+ APIVersion string `json:"ApiVersion"` |
|
48 |
+ DefaultAPIVersion string `json:"DefaultAPIVersion,omitempty"` |
|
49 |
+ GitCommit string |
|
50 |
+ GoVersion string |
|
51 |
+ Os string |
|
52 |
+ Arch string |
|
53 |
+ BuildTime string `json:",omitempty"` |
|
54 |
+} |
|
55 |
+ |
|
56 |
+// ServerOK returns true when the client could connect to the docker server |
|
57 |
+// and parse the information received. It returns false otherwise. |
|
58 |
+func (v versionInfo) ServerOK() bool { |
|
59 |
+ return v.Server != nil |
|
60 |
+} |
|
61 |
+ |
|
39 | 62 |
// NewVersionCommand creates a new cobra.Command for `docker version` |
40 | 63 |
func NewVersionCommand(dockerCli *command.DockerCli) *cobra.Command { |
41 | 64 |
var opts versionOptions |
... | ... |
@@ -70,20 +92,16 @@ func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error { |
70 | 70 |
Status: "Template parsing error: " + err.Error()} |
71 | 71 |
} |
72 | 72 |
|
73 |
- APIVersion := dockerCli.Client().ClientVersion() |
|
74 |
- if defaultAPIVersion := dockerCli.DefaultVersion(); APIVersion != defaultAPIVersion { |
|
75 |
- APIVersion = fmt.Sprintf("%s (downgraded from %s)", APIVersion, defaultAPIVersion) |
|
76 |
- } |
|
77 |
- |
|
78 |
- vd := types.VersionResponse{ |
|
79 |
- Client: &types.Version{ |
|
80 |
- Version: dockerversion.Version, |
|
81 |
- APIVersion: APIVersion, |
|
82 |
- GoVersion: runtime.Version(), |
|
83 |
- GitCommit: dockerversion.GitCommit, |
|
84 |
- BuildTime: dockerversion.BuildTime, |
|
85 |
- Os: runtime.GOOS, |
|
86 |
- Arch: runtime.GOARCH, |
|
73 |
+ vd := versionInfo{ |
|
74 |
+ Client: clientVersion{ |
|
75 |
+ Version: dockerversion.Version, |
|
76 |
+ APIVersion: dockerCli.Client().ClientVersion(), |
|
77 |
+ DefaultAPIVersion: dockerCli.DefaultVersion(), |
|
78 |
+ GoVersion: runtime.Version(), |
|
79 |
+ GitCommit: dockerversion.GitCommit, |
|
80 |
+ BuildTime: dockerversion.BuildTime, |
|
81 |
+ Os: runtime.GOOS, |
|
82 |
+ Arch: runtime.GOARCH, |
|
87 | 83 |
}, |
88 | 84 |
} |
89 | 85 |
|