Render users in a beautiful table

Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
kolaente 2020-08-13 12:18:25 +02:00
parent ed2ff62fd2
commit 99b0d311dd
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 27 additions and 3 deletions

View File

@ -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()
},
}