summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPaul Scott <paul@tailscale.com>2024-05-28 21:53:18 +0100
committerPaul Scott <paul@tailscale.com>2024-05-28 21:53:18 +0100
commitec85e58e049a272b6e5b9b0f8aecaf784160c265 (patch)
tree574260ea1e197efc8f0c544bf9d9cba804a51580
parentf1d10c12acf69fcb7509c6aaff65e1a9c8897715 (diff)
downloadtailscale-icio/public-key-short.tar.xz
tailscale-icio/public-key-short.zip
cmd/tailscale/cli: use tabwriter for output and add --ids, --headers flags to statusicio/public-key-short
Signed-off-by: Paul Scott <paul@tailscale.com>
-rw-r--r--cmd/tailscale/cli/status.go56
1 files changed, 47 insertions, 9 deletions
diff --git a/cmd/tailscale/cli/status.go b/cmd/tailscale/cli/status.go
index e4dccc247..9b54d5858 100644
--- a/cmd/tailscale/cli/status.go
+++ b/cmd/tailscale/cli/status.go
@@ -17,6 +17,7 @@ import (
"os"
"strconv"
"strings"
+ "text/tabwriter"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/toqueteos/webbrowser"
@@ -55,7 +56,9 @@ https://github.com/tailscale/tailscale/blob/main/ipn/ipnstate/ipnstate.go
fs.BoolVar(&statusArgs.self, "self", true, "show status of local machine")
fs.BoolVar(&statusArgs.peers, "peers", true, "show status of peers")
fs.StringVar(&statusArgs.listen, "listen", "127.0.0.1:8384", "listen address for web mode; use port 0 for automatic")
- fs.BoolVar(&statusArgs.browser, "browser", true, "Open a browser in web mode")
+ fs.BoolVar(&statusArgs.browser, "browser", true, "open a browser in web mode")
+ fs.BoolVar(&statusArgs.ids, "ids", false, "show all identifiers")
+ fs.BoolVar(&statusArgs.headers, "headers", true, "show column headers")
return fs
})(),
}
@@ -68,6 +71,8 @@ var statusArgs struct {
active bool // in CLI mode, filter output to only peers with active sessions
self bool // in CLI mode, show status of local machine
peers bool // in CLI mode, show status of peer machines
+ headers bool // in CLI mode, print an initial header row
+ ids bool // in CLI mode, show all node identifiers and addresses
}
func runStatus(ctx context.Context, args []string) error {
@@ -150,14 +155,44 @@ func runStatus(ctx context.Context, args []string) error {
}
var buf bytes.Buffer
- f := func(format string, a ...any) { fmt.Fprintf(&buf, format, a...) }
+ tab := tabwriter.NewWriter(&buf, 4, 4, 1, ' ', 0)
+ f := func(format string, a ...any) { fmt.Fprintf(tab, format, a...) }
+ col := func(c string) { f("%s\t", c) }
+
+ if statusArgs.headers {
+ if statusArgs.ids {
+ col("IPv4")
+ col("IPv6")
+ col("PK")
+ col("ID")
+ } else {
+ col("IP")
+ }
+ col("NAME")
+ col("OWNER")
+ col("OS")
+ col("STATUS")
+ f("\n")
+ }
+
printPS := func(ps *ipnstate.PeerStatus) {
- f("%-15s %-20s %-12s %-7s ",
- firstIPString(ps.TailscaleIPs),
- dnsOrQuoteHostname(st, ps),
- ownerLogin(st, ps),
- ps.OS,
- )
+ if statusArgs.ids {
+ col(firstIPString(ps.TailscaleIPs))
+ if len(ps.TailscaleIPs) > 1 {
+ col(strings.Trim(fmt.Sprintf("%v", ps.TailscaleIPs[1:]), "[]"))
+ } else {
+ col("")
+ }
+ col(ps.PublicKey.ShortString())
+ col(string(ps.ID))
+ } else {
+ col(firstIPString(ps.TailscaleIPs))
+ }
+ col(dnsOrQuoteHostname(st, ps))
+ col(ownerLogin(st, ps))
+ col(ps.OS)
+
+ // Final, unaligned status column.
relay := ps.Relay
anyTraffic := ps.TxBytes != 0 || ps.RxBytes != 0
var offline string
@@ -193,7 +228,7 @@ func runStatus(ctx context.Context, args []string) error {
}
}
if anyTraffic {
- f(", tx %d rx %d", ps.TxBytes, ps.RxBytes)
+ f("; tx %d rx %d", ps.TxBytes, ps.RxBytes)
}
f("\n")
}
@@ -226,6 +261,9 @@ func runStatus(ctx context.Context, args []string) error {
printPS(ps)
}
}
+ if err := tab.Flush(); err != nil {
+ return err
+ }
Stdout.Write(buf.Bytes())
if locBasedExitNode {
outln()