From 99b0d311dd34f898255a6542cc069f546e2a0768 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 13 Aug 2020 12:18:25 +0200 Subject: [PATCH] Render users in a beautiful table Signed-off-by: kolaente --- pkg/cmd/user.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/user.go b/pkg/cmd/user.go index 1910b6750..0992d299a 100644 --- a/pkg/cmd/user.go +++ b/pkg/cmd/user.go @@ -21,8 +21,11 @@ import ( "code.vikunja.io/api/pkg/initialize" "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/user" - "fmt" + "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" + "os" + "strconv" + "time" ) func init() { @@ -46,7 +49,28 @@ var userListCmd = &cobra.Command{ if err != nil { log.Criticalf("Error getting users: %s", err) } - // TODO: Pretty print as ascii tables (only relevant stuff, exlude things like passwords - fmt.Println(users) + + table := tablewriter.NewWriter(os.Stdout) + table.SetHeader([]string{ + "ID", + "Username", + "Email", + "Active", + "Created", + "Updated", + }) + + for _, u := range users { + table.Append([]string{ + strconv.FormatInt(u.ID, 10), + u.Username, + u.Email, + strconv.FormatBool(u.IsActive), + u.Created.Format(time.RFC3339), + u.Updated.Format(time.RFC3339), + }) + } + + table.Render() }, }