From f194b4143557115db4ac961a633dd12db7356963 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sun, 15 Aug 2021 23:29:55 +0200 Subject: [PATCH] Better table in preauthkeys --- cmd/headscale/cli/preauthkeys.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/headscale/cli/preauthkeys.go b/cmd/headscale/cli/preauthkeys.go index 63acc21a..4d07928d 100644 --- a/cmd/headscale/cli/preauthkeys.go +++ b/cmd/headscale/cli/preauthkeys.go @@ -3,10 +3,12 @@ package cli import ( "fmt" "log" + "strconv" "strings" "time" "github.com/hako/durafmt" + "github.com/pterm/pterm" "github.com/spf13/cobra" ) @@ -54,6 +56,8 @@ var listPreAuthKeys = &cobra.Command{ fmt.Printf("Error getting the list of keys: %s\n", err) return } + + d := pterm.TableData{{"ID", "Key", "Reusable", "Ephemeral", "Expiration", "Created"}} for _, k := range *keys { expiration := "-" if k.Expiration != nil { @@ -67,16 +71,17 @@ var listPreAuthKeys = &cobra.Command{ reusable = fmt.Sprintf("%v", k.Reusable) } - fmt.Printf( - "key: %s, namespace: %s, reusable: %s, ephemeral: %v, expiration: %s, created_at: %s\n", + d = append(d, []string{ + strconv.FormatUint(k.ID, 10), k.Key, - k.Namespace.Name, reusable, - k.Ephemeral, + strconv.FormatBool(k.Ephemeral), expiration, k.CreatedAt.Format("2006-01-02 15:04:05"), - ) + }) + } + pterm.DefaultTable.WithHasHeader().WithData(d).Render() }, }