Skip to content

Commit 5afa325

Browse files
committed
TUN-4150: Only show the connector table in 'tunnel info' if there are connectors. Don't show rows with zero connections.
1 parent 8ca0d86 commit 5afa325

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

cmd/cloudflared/tunnel/subcommands.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,22 +454,38 @@ func formatAndPrintConnectionsList(tunnelInfo Info, showRecentlyDisconnected boo
454454
writer := tabWriter()
455455
defer writer.Flush()
456456

457+
// Print the general tunnel info table
457458
_, _ = fmt.Fprintf(writer, "NAME: %s\nID: %s\nCREATED: %s\n\n", tunnelInfo.Name, tunnelInfo.ID, tunnelInfo.CreatedAt)
458459

460+
// Determine whether to print the connector table
461+
shouldDisplayTable := false
462+
for _, c := range tunnelInfo.Connectors {
463+
conns := fmtConnections(c.Connections, showRecentlyDisconnected)
464+
if len(conns) > 0 {
465+
shouldDisplayTable = true
466+
}
467+
}
468+
if !shouldDisplayTable {
469+
fmt.Println("This tunnel has no active connectors.")
470+
return
471+
}
472+
473+
// Print the connector table
459474
_, _ = fmt.Fprintln(writer, "CONNECTOR ID\tCREATED\tARCHITECTURE\tVERSION\tORIGIN IP\tEDGE\t")
460475
for _, c := range tunnelInfo.Connectors {
461-
var originIp = ""
462-
if len(c.Connections) > 0 {
463-
originIp = c.Connections[0].OriginIP.String()
476+
conns := fmtConnections(c.Connections, showRecentlyDisconnected)
477+
if len(conns) == 0 {
478+
continue
464479
}
480+
originIp := c.Connections[0].OriginIP.String()
465481
formattedStr := fmt.Sprintf(
466482
"%s\t%s\t%s\t%s\t%s\t%s\t",
467483
c.ID,
468484
c.RunAt.Format(time.RFC3339),
469485
c.Arch,
470486
c.Version,
471487
originIp,
472-
fmtConnections(c.Connections, showRecentlyDisconnected),
488+
conns,
473489
)
474490
_, _ = fmt.Fprintln(writer, formattedStr)
475491
}

0 commit comments

Comments
 (0)