From b3b03d7172c634086fa8d64818ea28cc11aba9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Parada?= Date: Tue, 23 Nov 2021 13:02:42 -0300 Subject: [PATCH] remove id from tables and format datetime as ago --- cmd/calyptia/create_aggregator.go | 4 ++-- cmd/calyptia/create_pipeline.go | 4 ++-- cmd/calyptia/get_agent.go | 4 ++-- cmd/calyptia/get_aggregator.go | 4 ++-- cmd/calyptia/get_pipeline.go | 4 ++-- cmd/calyptia/get_pipeline_config.go | 4 ++-- cmd/calyptia/get_pipeline_port.go | 4 ++-- cmd/calyptia/get_pipeline_status.go | 4 ++-- cmd/calyptia/get_project.go | 4 ++-- cmd/calyptia/utl.go | 11 +++++++++++ 10 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 cmd/calyptia/utl.go diff --git a/cmd/calyptia/create_aggregator.go b/cmd/calyptia/create_aggregator.go index da401c9b..13340a7d 100644 --- a/cmd/calyptia/create_aggregator.go +++ b/cmd/calyptia/create_aggregator.go @@ -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) diff --git a/cmd/calyptia/create_pipeline.go b/cmd/calyptia/create_pipeline.go index 16f449ac..1735b33e 100644 --- a/cmd/calyptia/create_pipeline.go +++ b/cmd/calyptia/create_pipeline.go @@ -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) diff --git a/cmd/calyptia/get_agent.go b/cmd/calyptia/get_agent.go index e5b31584..880dfd61 100644 --- a/cmd/calyptia/get_agent.go +++ b/cmd/calyptia/get_agent.go @@ -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": diff --git a/cmd/calyptia/get_aggregator.go b/cmd/calyptia/get_aggregator.go index 998b9b3e..a008c941 100644 --- a/cmd/calyptia/get_aggregator.go +++ b/cmd/calyptia/get_aggregator.go @@ -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": diff --git a/cmd/calyptia/get_pipeline.go b/cmd/calyptia/get_pipeline.go index 4b0f92e6..b6c44d3b 100644 --- a/cmd/calyptia/get_pipeline.go +++ b/cmd/calyptia/get_pipeline.go @@ -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": diff --git a/cmd/calyptia/get_pipeline_config.go b/cmd/calyptia/get_pipeline_config.go index 177f3999..293a4a2b 100644 --- a/cmd/calyptia/get_pipeline_config.go +++ b/cmd/calyptia/get_pipeline_config.go @@ -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": diff --git a/cmd/calyptia/get_pipeline_port.go b/cmd/calyptia/get_pipeline_port.go index 33748e9d..265eab14 100644 --- a/cmd/calyptia/get_pipeline_port.go +++ b/cmd/calyptia/get_pipeline_port.go @@ -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) @@ -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": diff --git a/cmd/calyptia/get_pipeline_status.go b/cmd/calyptia/get_pipeline_status.go index a16db356..34fa78bd 100644 --- a/cmd/calyptia/get_pipeline_status.go +++ b/cmd/calyptia/get_pipeline_status.go @@ -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": diff --git a/cmd/calyptia/get_project.go b/cmd/calyptia/get_project.go index 7ba2c297..6539d091 100644 --- a/cmd/calyptia/get_project.go +++ b/cmd/calyptia/get_project.go @@ -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": diff --git a/cmd/calyptia/utl.go b/cmd/calyptia/utl.go new file mode 100644 index 00000000..b0517fde --- /dev/null +++ b/cmd/calyptia/utl.go @@ -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() +}