Render users in a beautiful table
Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
parent
ed2ff62fd2
commit
99b0d311dd
|
@ -21,8 +21,11 @@ import (
|
||||||
"code.vikunja.io/api/pkg/initialize"
|
"code.vikunja.io/api/pkg/initialize"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
"fmt"
|
"github.com/olekukonko/tablewriter"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -46,7 +49,28 @@ var userListCmd = &cobra.Command{
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Criticalf("Error getting users: %s", err)
|
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()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue