From 336e87c199af5e1bf9d62dbb55e2c1b088f5504f Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Wed, 12 Apr 2023 18:14:32 +0200 Subject: [PATCH 1/2] Add headers to output when using logs tail --- internal/display/display.go | 11 +++++++++++ internal/display/display_test.go | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/display/display.go b/internal/display/display.go index 3e059fa4a..b748219f1 100644 --- a/internal/display/display.go +++ b/internal/display/display.go @@ -148,6 +148,17 @@ func (r *Renderer) Stream(data []View, ch <-chan View) { } } + if len(data) > 0 { + header := []string{ + truncate("TYPE", 23), + truncate("DESCRIPTION", 54), + truncate("DATE", 20), + truncate("CONNECTION", 20), + truncate("CLIENT", 20), + } + displayRow(header) + } + for _, v := range data { displayView(v) } diff --git a/internal/display/display_test.go b/internal/display/display_test.go index 55d3eba68..2a0f8e64d 100644 --- a/internal/display/display_test.go +++ b/internal/display/display_test.go @@ -63,7 +63,9 @@ func TestStream(t *testing.T) { t.Run("Stream correctly handles nil channel", func(t *testing.T) { mockRender.Stream(results, nil) - expectedResult := "API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A \n" + expectedResult := `TYPE DESCRIPTION DATE CONNECTION CLIENT +API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A +` assert.Equal(t, expectedResult, stdout.String()) stdout.Reset() }) @@ -93,7 +95,8 @@ func TestStream(t *testing.T) { wg.Wait() - expectedResult := `API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A + expectedResult := `TYPE DESCRIPTION DATE CONNECTION CLIENT +API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A API Operation Update tenant settings Jan 01 00:00:00.000 N/A N/A ` assert.Equal(t, expectedResult, stdout.String()) From c1405fdef04f2c236a588ec67a812b016b055b8c Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Wed, 12 Apr 2023 18:31:00 +0200 Subject: [PATCH 2/2] Improve warning of no logs when using filter for logs list --- internal/cli/logs.go | 3 ++- internal/display/logs.go | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/cli/logs.go b/internal/cli/logs.go index f7d3d82bd..c8b164534 100644 --- a/internal/cli/logs.go +++ b/internal/cli/logs.go @@ -66,7 +66,8 @@ func listLogsCmd(cli *cli) *cobra.Command { return fmt.Errorf("An unexpected error occurred while getting logs: %v", err) } - cli.renderer.LogList(list, !cli.debug) + hasFilter := inputs.Filter != "" + cli.renderer.LogList(list, !cli.debug, hasFilter) return nil }, } diff --git a/internal/display/logs.go b/internal/display/logs.go index 906c51c45..b65b398a7 100644 --- a/internal/display/logs.go +++ b/internal/display/logs.go @@ -142,13 +142,18 @@ func (v *logView) typeDesc() (typ, desc string) { return typ, desc } -func (r *Renderer) LogList(logs []*management.Log, silent bool) { +func (r *Renderer) LogList(logs []*management.Log, silent, hasFilter bool) { resource := "logs" r.Heading(resource) if len(logs) == 0 { - r.EmptyState(resource) + if hasFilter { + r.Output("No logs available matching filter criteria.\n\n") + } else { + r.EmptyState(resource) + } + r.Infof("To generate logs, run a test command like 'auth0 test login' or 'auth0 test token'") return }