Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func runInfo(ctx context.Context, cmd *cobra.Command, dockerCli command.Cli, opt
// Don't pass a dockerCLI to newClientVersion(), because we currently
// don't include negotiated API version, and want to avoid making an
// API connection when only printing the Client section.
clientVersion: newClientVersion(dockerCli.CurrentContext(), nil),
clientVersion: newClientVersion(dockerCli.CurrentContext(), nil, true),
Debug: debug.IsEnabled(),
},
Info: &system.Info{},
Expand Down
33 changes: 26 additions & 7 deletions cli/command/system/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,17 @@ type serverVersion struct {
// passed as argument, additional information is included (API version),
// which may invoke an API connection. Pass nil to omit the additional
// information.
func newClientVersion(contextName string, dockerCli command.Cli) clientVersion {
func newClientVersion(contextName string, dockerCli command.Cli, prettyTime bool) clientVersion {
buildTime := version.BuildTime
if prettyTime {
buildTime = reformatDate(buildTime)
}
v := clientVersion{
Version: version.Version,
DefaultAPIVersion: client.MaxAPIVersion,
GoVersion: runtime.Version(),
GitCommit: version.GitCommit,
BuildTime: reformatDate(version.BuildTime),
BuildTime: buildTime,
Os: runtime.GOOS,
Arch: arch(),
Context: contextName,
Expand All @@ -128,7 +132,7 @@ func newClientVersion(contextName string, dockerCli command.Cli) clientVersion {
return v
}

func newServerVersion(sv client.ServerVersionResult) *serverVersion {
func newServerVersion(sv client.ServerVersionResult, prettyTime bool) *serverVersion {
out := &serverVersion{
Platform: sv.Platform,
Version: sv.Version,
Expand All @@ -145,13 +149,16 @@ func newServerVersion(sv client.ServerVersionResult) *serverVersion {
foundEngine = true
buildTime, ok := component.Details["BuildTime"]
if ok {
component.Details["BuildTime"] = reformatDate(buildTime)
if prettyTime {
buildTime = reformatDate(buildTime)
component.Details["BuildTime"] = buildTime
}
out.BuildTime = buildTime
}
out.GitCommit = component.Details["GitCommit"]
out.GoVersion = component.Details["GoVersion"]
out.KernelVersion = component.Details["KernelVersion"]
out.Experimental = func() bool { b, _ := strconv.ParseBool(component.Details["Experimental"]); return b }()
out.BuildTime = buildTime
}
out.Components = append(out.Components, component)
}
Expand Down Expand Up @@ -193,6 +200,16 @@ func newVersionCommand(dockerCLI command.Cli) *cobra.Command {
return cmd
}


func isJSONVersionFormat(format string) bool {
switch format {
case formatter.JSONFormatKey, formatter.JSONFormat:
return true
default:
return false
}
}

func reformatDate(buildTime string) string {
t, errTime := time.Parse(time.RFC3339Nano, buildTime)
if errTime == nil {
Expand All @@ -216,12 +233,14 @@ func runVersion(ctx context.Context, dockerCLI command.Cli, opts *versionOptions
return cli.StatusError{StatusCode: 64, Status: err.Error()}
}

// Keep RFC3339 BuildTime strings for JSON; reformat to ANSIC only for human templates.
prettyTime := !isJSONVersionFormat(opts.format)
vd := versionInfo{
Client: newClientVersion(dockerCLI.CurrentContext(), dockerCLI),
Client: newClientVersion(dockerCLI.CurrentContext(), dockerCLI, prettyTime),
}
sv, err := dockerCLI.Client().ServerVersion(ctx, client.ServerVersionOptions{})
if err == nil {
vd.Server = newServerVersion(sv)
vd.Server = newServerVersion(sv, prettyTime)
}
if err2 := prettyPrintVersion(dockerCLI.Out(), vd, tmpl); err2 != nil && err == nil {
err = err2
Expand Down