From cc375fafd04f4149a75185a85e1b6f1fad50ae6e Mon Sep 17 00:00:00 2001 From: allencloud Date: Sun, 25 Sep 2016 16:47:45 +0800 Subject: [PATCH] add endpoint mode in service pretty Signed-off-by: allencloud --- command/formatter/service.go | 15 ++++++++++++--- command/inspect/inspector.go | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/command/formatter/service.go b/command/formatter/service.go index a1872e91b9..a92326e75d 100644 --- a/command/formatter/service.go +++ b/command/formatter/service.go @@ -19,9 +19,9 @@ Labels: {{- range $k, $v := .Labels }} {{ $k }}{{if $v }}={{ $v }}{{ end }} {{- end }}{{ end }} -Mode: -{{- if .IsModeGlobal }} Global -{{- else if .IsModeReplicated }} Replicated +Service Mode: +{{- if .IsModeGlobal }} Global +{{- else if .IsModeReplicated }} Replicated {{- if .ModeReplicatedReplicas }} Replicas: {{ .ModeReplicatedReplicas }} {{- end }}{{ end }} @@ -90,6 +90,7 @@ Resources: {{- if .Networks }} Networks: {{- range $network := .Networks }} {{ $network }}{{ end }} {{ end }} +Endpoint Mode: {{ .EndpointMode }} {{- if .Ports }} Ports: {{- range $port := .Ports }} @@ -282,6 +283,14 @@ func (ctx *serviceInspectContext) Networks() []string { return out } +func (ctx *serviceInspectContext) EndpointMode() string { + if ctx.Service.Spec.EndpointSpec == nil { + return "" + } + + return string(ctx.Service.Spec.EndpointSpec.Mode) +} + func (ctx *serviceInspectContext) Ports() []swarm.PortConfig { return ctx.Service.Endpoint.Ports } diff --git a/command/inspect/inspector.go b/command/inspect/inspector.go index b0537e8464..1d81643fb1 100644 --- a/command/inspect/inspector.go +++ b/command/inspect/inspector.go @@ -122,7 +122,7 @@ func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error { return nil } -// Flush write the result of inspecting all elements into the output stream. +// Flush writes the result of inspecting all elements into the output stream. func (i *TemplateInspector) Flush() error { if i.buffer.Len() == 0 { _, err := io.WriteString(i.outputStream, "\n") @@ -156,7 +156,7 @@ func (i *IndentedInspector) Inspect(typedElement interface{}, rawElement []byte) return nil } -// Flush write the result of inspecting all elements into the output stream. +// Flush writes the result of inspecting all elements into the output stream. func (i *IndentedInspector) Flush() error { if len(i.elements) == 0 && len(i.rawElements) == 0 { _, err := io.WriteString(i.outputStream, "[]\n")