From 5afa3251dd719906bd295cda36f5da6fcbc68c8d Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Tue, 30 Mar 2021 14:14:22 -0500 Subject: [PATCH] TUN-4150: Only show the connector table in 'tunnel info' if there are connectors. Don't show rows with zero connections. --- cmd/cloudflared/tunnel/subcommands.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/cloudflared/tunnel/subcommands.go b/cmd/cloudflared/tunnel/subcommands.go index 2e92f116..69e92d0f 100644 --- a/cmd/cloudflared/tunnel/subcommands.go +++ b/cmd/cloudflared/tunnel/subcommands.go @@ -454,14 +454,30 @@ func formatAndPrintConnectionsList(tunnelInfo Info, showRecentlyDisconnected boo writer := tabWriter() defer writer.Flush() + // Print the general tunnel info table _, _ = fmt.Fprintf(writer, "NAME: %s\nID: %s\nCREATED: %s\n\n", tunnelInfo.Name, tunnelInfo.ID, tunnelInfo.CreatedAt) + // Determine whether to print the connector table + shouldDisplayTable := false + for _, c := range tunnelInfo.Connectors { + conns := fmtConnections(c.Connections, showRecentlyDisconnected) + if len(conns) > 0 { + shouldDisplayTable = true + } + } + if !shouldDisplayTable { + fmt.Println("This tunnel has no active connectors.") + return + } + + // Print the connector table _, _ = fmt.Fprintln(writer, "CONNECTOR ID\tCREATED\tARCHITECTURE\tVERSION\tORIGIN IP\tEDGE\t") for _, c := range tunnelInfo.Connectors { - var originIp = "" - if len(c.Connections) > 0 { - originIp = c.Connections[0].OriginIP.String() + conns := fmtConnections(c.Connections, showRecentlyDisconnected) + if len(conns) == 0 { + continue } + originIp := c.Connections[0].OriginIP.String() formattedStr := fmt.Sprintf( "%s\t%s\t%s\t%s\t%s\t%s\t", c.ID, @@ -469,7 +485,7 @@ func formatAndPrintConnectionsList(tunnelInfo Info, showRecentlyDisconnected boo c.Arch, c.Version, originIp, - fmtConnections(c.Connections, showRecentlyDisconnected), + conns, ) _, _ = fmt.Fprintln(writer, formattedStr) }