Skip to content

Commit

Permalink
remove id from tables and format datetime as ago
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasparada committed Nov 23, 2021
1 parent 714d091 commit b3b03d7
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cmd/calyptia/create_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func newCmdCreateAggregator(config *config) *cobra.Command {
switch format {
case "table":
tw := table.NewWriter()
tw.AppendHeader(table.Row{"ID", "Name", "Created at"})
tw.AppendHeader(table.Row{"Name", "Ago"})
tw.Style().Options = table.OptionsNoBordersAndSeparators
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
tw.SetAllowedRowLength(w)
}
tw.AppendRow(table.Row{a.ID, a.Name, a.CreatedAt.Local()})
tw.AppendRow(table.Row{a.Name, fmtAgo(a.CreatedAt)})
fmt.Println(tw.Render())
case "json":
err := json.NewEncoder(os.Stdout).Encode(a)
Expand Down
4 changes: 2 additions & 2 deletions cmd/calyptia/create_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ func newCmdCreatePipeline(config *config) *cobra.Command {
switch outputFormat {
case "table":
tw := table.NewWriter()
tw.AppendHeader(table.Row{"ID", "Name", "Created at"})
tw.AppendHeader(table.Row{"Name", "Ago"})
tw.Style().Options = table.OptionsNoBordersAndSeparators
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
tw.SetAllowedRowLength(w)
}
tw.AppendRow(table.Row{a.ID, a.Name, a.CreatedAt.Local()})
tw.AppendRow(table.Row{a.Name, fmtAgo(a.CreatedAt)})
fmt.Println(tw.Render())
case "json":
err := json.NewEncoder(os.Stdout).Encode(a)
Expand Down
4 changes: 2 additions & 2 deletions cmd/calyptia/get_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ func newCmdGetAgents(config *config) *cobra.Command {
switch format {
case "table":
tw := table.NewWriter()
tw.AppendHeader(table.Row{"ID", "Name", "Type", "Version", "Status", "Created at"})
tw.AppendHeader(table.Row{"Name", "Type", "Version", "Status", "Ago"})
tw.Style().Options = table.OptionsNoBordersAndSeparators
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
tw.SetAllowedRowLength(w)
}

for _, a := range aa {
tw.AppendRow(table.Row{a.ID, a.Name, a.Type, a.Version, agentStatus(a.LastMetricsAddedAt, time.Minute*-5), a.CreatedAt.Local()})
tw.AppendRow(table.Row{a.Name, a.Type, a.Version, agentStatus(a.LastMetricsAddedAt, time.Minute*-5), fmtAgo(a.CreatedAt)})
}
fmt.Println(tw.Render())
case "json":
Expand Down
4 changes: 2 additions & 2 deletions cmd/calyptia/get_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func newCmdGetAggregators(config *config) *cobra.Command {
switch format {
case "table":
tw := table.NewWriter()
tw.AppendHeader(table.Row{"ID", "Name", "Created at"})
tw.AppendHeader(table.Row{"Name", "Ago"})
tw.Style().Options = table.OptionsNoBordersAndSeparators
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
tw.SetAllowedRowLength(w)
}

for _, a := range aa {
tw.AppendRow(table.Row{a.ID, a.Name, a.CreatedAt.Local()})
tw.AppendRow(table.Row{a.Name, fmtAgo(a.CreatedAt)})
}
fmt.Println(tw.Render())
case "json":
Expand Down
4 changes: 2 additions & 2 deletions cmd/calyptia/get_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func newCmdGetPipelines(config *config) *cobra.Command {
switch format {
case "table":
tw := table.NewWriter()
tw.AppendHeader(table.Row{"ID", "Name", "Replicas", "Status", "Created at"})
tw.AppendHeader(table.Row{"Name", "Replicas", "Status", "Ago"})
tw.Style().Options = table.OptionsNoBordersAndSeparators
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
tw.SetAllowedRowLength(w)
}

for _, p := range pp {
tw.AppendRow(table.Row{p.ID, p.Name, p.ReplicasCount, p.Status.Status, p.CreatedAt.Local()})
tw.AppendRow(table.Row{p.Name, p.ReplicasCount, p.Status.Status, fmtAgo(p.CreatedAt)})
}
fmt.Println(tw.Render())
case "json":
Expand Down
4 changes: 2 additions & 2 deletions cmd/calyptia/get_pipeline_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func newCmdGetPipelineConfigHistory(config *config) *cobra.Command {
switch format {
case "table":
tw := table.NewWriter()
tw.AppendHeader(table.Row{"ID", "Created at"})
tw.AppendHeader(table.Row{"ID", "Ago"})
tw.Style().Options = table.OptionsNoBordersAndSeparators
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
tw.SetAllowedRowLength(w)
}

for _, c := range cc {
tw.AppendRow(table.Row{c.ID, c.CreatedAt.Local()})
tw.AppendRow(table.Row{c.ID, fmtAgo(c.CreatedAt)})
}
fmt.Println(tw.Render())
case "json":
Expand Down
4 changes: 2 additions & 2 deletions cmd/calyptia/get_pipeline_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newCmdGetPipelinePorts(config *config) *cobra.Command {
switch format {
case "table":
tw := table.NewWriter()
tw.AppendHeader(table.Row{"ID", "Protocol", "Frontend port", "Backend port", "Endpoint", "Created at"})
tw.AppendHeader(table.Row{"Protocol", "Frontend port", "Backend port", "Endpoint", "Ago"})
tw.Style().Options = table.OptionsNoBordersAndSeparators
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
tw.SetAllowedRowLength(w)
Expand All @@ -52,7 +52,7 @@ func newCmdGetPipelinePorts(config *config) *cobra.Command {
if endpoint == "" {
endpoint = "Pending"
}
tw.AppendRow(table.Row{p.ID, p.Protocol, p.FrontendPort, p.BackendPort, endpoint, p.CreatedAt.Local()})
tw.AppendRow(table.Row{p.Protocol, p.FrontendPort, p.BackendPort, endpoint, fmtAgo(p.CreatedAt)})
}
fmt.Println(tw.Render())
case "json":
Expand Down
4 changes: 2 additions & 2 deletions cmd/calyptia/get_pipeline_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func newCmdGetPipelineStatusHistory(config *config) *cobra.Command {
switch format {
case "table":
tw := table.NewWriter()
tw.AppendHeader(table.Row{"ID", "Status", "Config ID", "Created at"})
tw.AppendHeader(table.Row{"Status", "Config ID", "Ago"})
tw.Style().Options = table.OptionsNoBordersAndSeparators
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
tw.SetAllowedRowLength(w)
}

for _, s := range ss {
tw.AppendRow(table.Row{s.ID, s.Status, s.Config.ID, s.CreatedAt.Local()})
tw.AppendRow(table.Row{s.Status, s.Config.ID, fmtAgo(s.CreatedAt)})
}
fmt.Println(tw.Render())
case "json":
Expand Down
4 changes: 2 additions & 2 deletions cmd/calyptia/get_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func newCmdGetProjects(config *config) *cobra.Command {
switch format {
case "table":
tw := table.NewWriter()
tw.AppendHeader(table.Row{"ID", "Name", "Created at"})
tw.AppendHeader(table.Row{"Name", "Ago"})
tw.Style().Options = table.OptionsNoBordersAndSeparators
if w, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
tw.SetAllowedRowLength(w)
}

for _, p := range pp {
tw.AppendRow(table.Row{p.ID, p.Name, p.CreatedAt.Local()})
tw.AppendRow(table.Row{p.Name, fmtAgo(p.CreatedAt)})
}
fmt.Println(tw.Render())
case "json":
Expand Down
11 changes: 11 additions & 0 deletions cmd/calyptia/utl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"time"

"github.com/hako/durafmt"
)

func fmtAgo(t time.Time) string {
return durafmt.ParseShort(time.Since(t)).LimitFirstN(1).String()
}

0 comments on commit b3b03d7

Please sign in to comment.