From 3ccbfe2829661720e6ecc1f349cdc45a4bfe4ac1 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 10 Jan 2024 15:00:31 -0500 Subject: [PATCH] table output for zrok ls (#438) --- cmd/zrok/dir.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/zrok/dir.go b/cmd/zrok/dir.go index ae146738..5879e2e7 100644 --- a/cmd/zrok/dir.go +++ b/cmd/zrok/dir.go @@ -2,12 +2,14 @@ package main import ( "fmt" + "github.com/jedib0t/go-pretty/v6/table" "github.com/openziti/zrok/environment" "github.com/openziti/zrok/tui" "github.com/openziti/zrok/util" "github.com/openziti/zrok/util/sync" "github.com/spf13/cobra" "net/url" + "os" ) func init() { @@ -54,12 +56,16 @@ func (cmd *dirCommand) run(_ *cobra.Command, args []string) { tui.Error("error listing directory", err) } + tw := table.NewWriter() + tw.SetOutputMirror(os.Stdout) + tw.SetStyle(table.StyleLight) + tw.AppendHeader(table.Row{"type", "Name", "Size", "Modified"}) for _, object := range objects { if object.IsDir { - fmt.Printf(" %-32s\n", object.Path) + tw.AppendRow(table.Row{"DIR", object.Path, "", ""}) } else { - fmt.Printf(" %-32s %-16s %s\n", object.Path, util.BytesToSize(object.Size), object.Modified.String()) + tw.AppendRow(table.Row{"", object.Path, util.BytesToSize(object.Size), object.Modified.Local()}) } } - fmt.Println() + tw.Render() }