Skip to content

Commit

Permalink
fix: using lipgloss tables instead of tablewriter
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Dec 16, 2024
1 parent 14729ba commit 6980ba6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 64 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ require (
github.com/aymanbagabas/git-module v1.8.4-0.20231101154130-8d27204ac6d2
github.com/caarlos0/duration v0.0.0-20240108180406-5d492514f3c7
github.com/caarlos0/env/v11 v11.2.2
github.com/caarlos0/tablewriter v0.1.0
github.com/charmbracelet/git-lfs-transfer v0.1.1-0.20240708204110-bacbfdb68d92
github.com/charmbracelet/keygen v0.5.1
github.com/charmbracelet/log v0.4.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ github.com/caarlos0/duration v0.0.0-20240108180406-5d492514f3c7 h1:kJP/C2eL9DCKr
github.com/caarlos0/duration v0.0.0-20240108180406-5d492514f3c7/go.mod h1:mSkwb/eZEwOJJJ4tqAKiuhLIPe0e9+FKhlU0oMCpbf8=
github.com/caarlos0/env/v11 v11.2.2 h1:95fApNrUyueipoZN/EhA8mMxiNxrBwDa+oAZrMWl3Kg=
github.com/caarlos0/env/v11 v11.2.2/go.mod h1:JBfcdeQiBoI3Zh1QRAWfe+tpiNTmDtcCj/hHHHMx0vc=
github.com/caarlos0/tablewriter v0.1.0 h1:HWwl/Zh3GKgVejSeG8lKHc28YBbI7bLRW2tgvxFF2DA=
github.com/caarlos0/tablewriter v0.1.0/go.mod h1:oZ3/mQeP+SC5c1Dr6zv/6jCf0dfsUWq+PuwNw8l3ir0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
Expand Down
39 changes: 18 additions & 21 deletions pkg/ssh/cmd/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/caarlos0/duration"
"github.com/caarlos0/tablewriter"
"github.com/charmbracelet/lipgloss/table"
"github.com/charmbracelet/soft-serve/pkg/backend"
"github.com/charmbracelet/soft-serve/pkg/proto"
"github.com/dustin/go-humanize"
Expand Down Expand Up @@ -92,28 +92,25 @@ func TokenCommand() *cobra.Command {
}

now := time.Now()
return tablewriter.Render(
cmd.OutOrStdout(),
tokens,
[]string{"ID", "Name", "Created At", "Expires In"},
func(t proto.AccessToken) ([]string, error) {
expiresAt := "-"
if !t.ExpiresAt.IsZero() {
if now.After(t.ExpiresAt) {
expiresAt = "expired"
} else {
expiresAt = humanize.Time(t.ExpiresAt)
}
table := table.New().Headers("ID", "Name", "Created At", "Expires In")
for _, token := range tokens {
expiresAt := "-"
if !token.ExpiresAt.IsZero() {
if now.After(token.ExpiresAt) {
expiresAt = "expired"
} else {
expiresAt = humanize.Time(token.ExpiresAt)
}
}

return []string{
strconv.FormatInt(t.ID, 10),
t.Name,
humanize.Time(t.CreatedAt),
expiresAt,
}, nil
},
)
table = table.Row(strconv.FormatInt(token.ID, 10),
token.Name,
humanize.Time(token.CreatedAt),
expiresAt,
)
}
cmd.Println(table)
return nil
},
}

Expand Down
73 changes: 33 additions & 40 deletions pkg/ssh/cmd/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"strings"

"github.com/caarlos0/tablewriter"
"github.com/charmbracelet/lipgloss/table"
"github.com/charmbracelet/soft-serve/pkg/backend"
"github.com/charmbracelet/soft-serve/pkg/webhook"
"github.com/dustin/go-humanize"
Expand Down Expand Up @@ -60,28 +60,24 @@ func webhookListCommand() *cobra.Command {
return err
}

return tablewriter.Render(
cmd.OutOrStdout(),
webhooks,
[]string{"ID", "URL", "Events", "Active", "Created At", "Updated At"},
func(h webhook.Hook) ([]string, error) {
events := make([]string, len(h.Events))
for i, e := range h.Events {
events[i] = e.String()
}

row := []string{
strconv.FormatInt(h.ID, 10),
h.URL,
strings.Join(events, ","),
strconv.FormatBool(h.Active),
humanize.Time(h.CreatedAt),
humanize.Time(h.UpdatedAt),
}
table := table.New().Headers("ID", "URL", "Events", "Active", "Created At", "Updated At")
for _, h := range webhooks {
events := make([]string, len(h.Events))
for i, e := range h.Events {
events[i] = e.String()
}

return row, nil
},
)
table = table.Row(
strconv.FormatInt(h.ID, 10),
h.URL,
strings.Join(events, ","),
strconv.FormatBool(h.Active),
humanize.Time(h.CreatedAt),
humanize.Time(h.UpdatedAt),
)
}
cmd.Println(table)
return nil
},
}

Expand Down Expand Up @@ -290,24 +286,21 @@ func webhookDeliveriesListCommand() *cobra.Command {
return err
}

return tablewriter.Render(
cmd.OutOrStdout(),
dels,
[]string{"Status", "ID", "Event", "Created At"},
func(d webhook.Delivery) ([]string, error) {
status := "❌"
if d.ResponseStatus >= 200 && d.ResponseStatus < 300 {
status = "✅"
}

return []string{
status,
d.ID.String(),
d.Event.String(),
humanize.Time(d.CreatedAt),
}, nil
},
)
table := table.New().Headers("Status", "ID", "Event", "Created At")
for _, d := range dels {
status := "❌"
if d.ResponseStatus >= 200 && d.ResponseStatus < 300 {
status = "✅"
}
table = table.Row(
status,
d.ID.String(),
d.Event.String(),
humanize.Time(d.CreatedAt),
)
}
cmd.Println(table)
return nil
},
}

Expand Down

0 comments on commit 6980ba6

Please sign in to comment.