From 9fdddfcec51c9f61c51153e71e63a8b90bc429c1 Mon Sep 17 00:00:00 2001 From: Pranav Karawale Date: Mon, 24 May 2021 22:27:12 +0530 Subject: [PATCH] feat: add `footer` parameter to `out.Table` --- cli/get.go | 4 ++-- cli/list.go | 4 ++-- cli/status.go | 2 +- out/out.go | 7 ++++++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cli/get.go b/cli/get.go index 41d7b94..f6dd6cb 100644 --- a/cli/get.go +++ b/cli/get.go @@ -38,7 +38,7 @@ func getProjectCommand(t *core.Timetrace) *cobra.Command { return } - out.Table([]string{"Key"}, [][]string{{project.Key}}) + out.Table([]string{"Key"}, [][]string{{project.Key}}, nil) }, } @@ -102,5 +102,5 @@ func showRecord(record *core.Record, formatter *core.Formatter) { }, } - out.Table([]string{"Start", "End", "Project", "Billable"}, rows) + out.Table([]string{"Start", "End", "Project", "Billable"}, rows, nil) } diff --git a/cli/list.go b/cli/list.go index ca2f26b..3bcdc90 100644 --- a/cli/list.go +++ b/cli/list.go @@ -44,7 +44,7 @@ func listProjectsCommand(t *core.Timetrace) *cobra.Command { rows[i][1] = project.Key } - out.Table([]string{"#", "Key"}, rows) + out.Table([]string{"#", "Key"}, rows, nil) }, } @@ -107,7 +107,7 @@ func listRecordsCommand(t *core.Timetrace) *cobra.Command { rows[i][5] = billable } - out.Table([]string{"#", "Key", "Project", "Start", "End", "Billable"}, rows) + out.Table([]string{"#", "Key", "Project", "Start", "End", "Billable"}, rows, nil) }, } diff --git a/cli/status.go b/cli/status.go index 9586731..2721e52 100644 --- a/cli/status.go +++ b/cli/status.go @@ -42,7 +42,7 @@ func statusCommand(t *core.Timetrace) *cobra.Command { report.FormatTodayTime(), }, } - out.Table([]string{"Current project", "Worked since start", "Worked today"}, rows) + out.Table([]string{"Current project", "Worked since start", "Worked today"}, rows, nil) }, } diff --git a/out/out.go b/out/out.go index 84a5790..834edee 100644 --- a/out/out.go +++ b/out/out.go @@ -42,11 +42,16 @@ func Err(format string, a ...interface{}) { } // Table renders a table with the given rows to the standard output. -func Table(header []string, rows [][]string) { +func Table(header []string, rows [][]string, footer []string) { paddedHeaders := headersWithPadding(header) table := tablewriter.NewWriter(os.Stdout) table.SetHeader(paddedHeaders) setHeaderColor(table, paddedHeaders) + // If footer array is not empty, then render footer in table. + if len(footer) > 0 { + paddedFooters := headersWithPadding(footer) + table.SetFooter(paddedFooters) + } table.AppendBulk(rows) table.Render() }