From b04338080c9a32c47b94f45fb07878c990ea8b6c Mon Sep 17 00:00:00 2001 From: "Arvid E. Picciani" Date: Mon, 1 Aug 2022 19:45:12 +0200 Subject: [PATCH] display port name field in 'service ls' Signed-off-by: Arvid E. Picciani --- cli/command/service/formatter.go | 14 +++++++++++--- cli/command/task/formatter.go | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cli/command/service/formatter.go b/cli/command/service/formatter.go index 5e99acc845..a488b4fcc5 100644 --- a/cli/command/service/formatter.go +++ b/cli/command/service/formatter.go @@ -725,6 +725,7 @@ func (c *serviceContext) Image() string { } type portRange struct { + pName string pStart uint32 pEnd uint32 tStart uint32 @@ -734,10 +735,16 @@ type portRange struct { func (pr portRange) String() string { var ( - pub string - tgt string + pub string + tgt string + name string ) + if pr.pName == "" { + name = "*" + } else { + name = pr.pName + } if pr.pEnd > pr.pStart { pub = fmt.Sprintf("%d-%d", pr.pStart, pr.pEnd) } else { @@ -748,7 +755,7 @@ func (pr portRange) String() string { } else { tgt = fmt.Sprintf("%d", pr.tStart) } - return fmt.Sprintf("*:%s->%s/%s", pub, tgt, pr.protocol) + return fmt.Sprintf("%s:%s->%s/%s", name, pub, tgt, pr.protocol) } // Ports formats published ports on the ingress network for output. @@ -794,6 +801,7 @@ func (c *serviceContext) Ports() string { ports = append(ports, pr.String()) } pr = portRange{ + pName: p.Name, pStart: p.PublishedPort, pEnd: p.PublishedPort, tStart: p.TargetPort, diff --git a/cli/command/task/formatter.go b/cli/command/task/formatter.go index 0958a1e89e..06a5bd6585 100644 --- a/cli/command/task/formatter.go +++ b/cli/command/task/formatter.go @@ -139,7 +139,10 @@ func (c *taskContext) Ports() string { } ports := []string{} for _, pConfig := range c.task.Status.PortStatus.Ports { - ports = append(ports, fmt.Sprintf("*:%d->%d/%s", + var name = pConfig.Name + if name == "" { name = "*" } + ports = append(ports, fmt.Sprintf("%s:%d->%d/%s", + name, pConfig.PublishedPort, pConfig.TargetPort, pConfig.Protocol,