From ca321d3c13327ff9a90e0af0235f4c924e193ec3 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 18 Feb 2026 15:25:14 +0000 Subject: [PATCH] cmd/headscale/cli: use HeadscaleDateTimeFormat and util.Base10 consistently Replace five hardcoded "2006-01-02 15:04:05" strings with the HeadscaleDateTimeFormat constant already defined in utils.go. Replace two literal 10 base arguments to strconv.FormatUint with util.Base10 to match the convention in api_key.go and nodes.go. --- cmd/headscale/cli/nodes.go | 4 ++-- cmd/headscale/cli/preauthkeys.go | 5 +++-- cmd/headscale/cli/pterm_style.go | 2 +- cmd/headscale/cli/users.go | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index 41cf31b4..b28d66cd 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -315,7 +315,7 @@ func nodesToPtables( if node.GetLastSeen() != nil { lastSeen = node.GetLastSeen().AsTime() - lastSeenTime = lastSeen.Format("2006-01-02 15:04:05") + lastSeenTime = lastSeen.Format(HeadscaleDateTimeFormat) } var ( @@ -325,7 +325,7 @@ func nodesToPtables( if node.GetExpiry() != nil { expiry = node.GetExpiry().AsTime() - expiryTime = expiry.Format("2006-01-02 15:04:05") + expiryTime = expiry.Format(HeadscaleDateTimeFormat) } else { expiryTime = "N/A" } diff --git a/cmd/headscale/cli/preauthkeys.go b/cmd/headscale/cli/preauthkeys.go index eda42d4c..0a0f8285 100644 --- a/cmd/headscale/cli/preauthkeys.go +++ b/cmd/headscale/cli/preauthkeys.go @@ -7,6 +7,7 @@ import ( "strings" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol/util" "github.com/pterm/pterm" "github.com/spf13/cobra" ) @@ -80,13 +81,13 @@ var listPreAuthKeys = &cobra.Command{ } tableData = append(tableData, []string{ - strconv.FormatUint(key.GetId(), 10), + strconv.FormatUint(key.GetId(), util.Base10), key.GetKey(), strconv.FormatBool(key.GetReusable()), strconv.FormatBool(key.GetEphemeral()), strconv.FormatBool(key.GetUsed()), expiration, - key.GetCreatedAt().AsTime().Format("2006-01-02 15:04:05"), + key.GetCreatedAt().AsTime().Format(HeadscaleDateTimeFormat), owner, }) } diff --git a/cmd/headscale/cli/pterm_style.go b/cmd/headscale/cli/pterm_style.go index 85fd050b..bad84c75 100644 --- a/cmd/headscale/cli/pterm_style.go +++ b/cmd/headscale/cli/pterm_style.go @@ -7,7 +7,7 @@ import ( ) func ColourTime(date time.Time) string { - dateStr := date.Format("2006-01-02 15:04:05") + dateStr := date.Format(HeadscaleDateTimeFormat) if date.After(time.Now()) { dateStr = pterm.LightGreen(dateStr) diff --git a/cmd/headscale/cli/users.go b/cmd/headscale/cli/users.go index 33f40229..6f04dd28 100644 --- a/cmd/headscale/cli/users.go +++ b/cmd/headscale/cli/users.go @@ -8,6 +8,7 @@ import ( "strconv" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol/util" "github.com/juanfont/headscale/hscontrol/util/zlog/zf" "github.com/pterm/pterm" "github.com/rs/zerolog/log" @@ -189,11 +190,11 @@ var listUsersCmd = &cobra.Command{ tableData = append( tableData, []string{ - strconv.FormatUint(user.GetId(), 10), + strconv.FormatUint(user.GetId(), util.Base10), user.GetDisplayName(), user.GetName(), user.GetEmail(), - user.GetCreatedAt().AsTime().Format("2006-01-02 15:04:05"), + user.GetCreatedAt().AsTime().Format(HeadscaleDateTimeFormat), }, ) }