Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve warning of no logs when using filter for logs list #733

Merged
merged 5 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/cli/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
Expand Down
11 changes: 11 additions & 0 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 5 additions & 2 deletions internal/display/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down Expand Up @@ -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())
Expand Down
9 changes: 7 additions & 2 deletions internal/display/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down