Skip to content

Commit

Permalink
Print projects in table format (yorkie-team#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins authored May 12, 2022
1 parent 6e60e17 commit 5495238
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 5 deletions.
32 changes: 29 additions & 3 deletions cmd/yorkie/project/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ package project

import (
"context"
"time"

"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"

"github.com/yorkie-team/yorkie/admin"
"github.com/yorkie-team/yorkie/pkg/units"
)

func newListCommand() *cobra.Command {
return &cobra.Command{
Use: "list",
Use: "ls",
Short: "List all projects",
RunE: func(cmd *cobra.Command, args []string) error {
// TODO(hackerwins): use adminAddr from env or addr flag.
Expand All @@ -44,10 +47,33 @@ func newListCommand() *cobra.Command {
return err
}

// TODO(hackerwins): Print projects in table format.
tw := table.NewWriter()
tw.Style().Options.DrawBorder = false
tw.Style().Options.SeparateColumns = false
tw.Style().Options.SeparateFooter = false
tw.Style().Options.SeparateHeader = false
tw.Style().Options.SeparateRows = false
tw.AppendHeader(table.Row{
"ID",
"NAME",
"PUBLIC KEY",
"SECRET KEY",
"AUTH WEBHOOK URL",
"AUTH WEBHOOK METHODS",
"CREATED AT",
})
for _, project := range projects {
cmd.Printf("%s\n", project.Name)
tw.AppendRow(table.Row{
project.ID,
project.Name,
project.PublicKey,
project.SecretKey,
project.AuthWebhookURL,
project.AuthWebhookMethods,
units.HumanDuration(time.Now().UTC().Sub(project.CreatedAt)),
})
}
cmd.Printf("%s\n", tw.Render())

return nil
},
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/go-memdb v1.3.2
github.com/jedib0t/go-pretty/v6 v6.3.1
github.com/moby/locker v1.0.1
github.com/prometheus/client_golang v1.11.0
github.com/rs/xid v1.2.1
Expand Down Expand Up @@ -111,7 +112,7 @@ require (
github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mbilski/exhaustivestruct v1.2.0 // indirect
github.com/mgechev/revive v1.1.4 // indirect
Expand All @@ -134,6 +135,7 @@ require (
github.com/quasilyte/go-ruleguard v0.3.15 // indirect
github.com/quasilyte/gogrep v0.0.0-20220103110004-ffaa07af02e3 // indirect
github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/ryancurrah/gomodguard v1.2.3 // indirect
github.com/ryanrolds/sqlclosecheck v0.3.0 // indirect
github.com/sanposhiho/wastedassign/v2 v2.0.6 // indirect
Expand Down
Loading

0 comments on commit 5495238

Please sign in to comment.