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

Add headers to output when using logs tail #732

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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),
Comment on lines +153 to +157
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are coming from:

func (v *logView) AsTableRow() []string {
typ, desc := v.typeDesc()
clientName := v.GetClientName()
if clientName == "" {
clientName = ansi.Faint(notApplicable)
}
conn := v.getConnection()
if conn == notApplicable {
conn = ansi.Faint(truncate(conn, 20))
} else {
conn = truncate(conn, 20)
}
return []string{
typ,
truncate(desc, 54),
truncate(v.GetDate().Format("Jan 02 15:04:05.000"), 20),
conn,
clientName,
}
}
.

Was not able to reuse the ViewAsTableHeader func due to the extra empty spaces needed to align everything.

}
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