Skip to content

Commit

Permalink
Sort tables before transposing and adding blank space
Browse files Browse the repository at this point in the history
[#142877853](https://www.pivotaltracker.com/story/show/142877853)

Signed-off-by: Michael Maximilien <[email protected]>
  • Loading branch information
Rob Day-Reynolds authored and maximilien committed May 11, 2017
1 parent 64a1d74 commit ef55792
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/run_errand.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (c RunErrandCmd) summarize(errandName string, results []boshdir.ErrandResul

Notes: []string{},

FillFirstColumn: true,

Transpose: true,
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/run_errand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ var _ = Describe("RunErrandCmd", func() {

Notes: []string{},

FillFirstColumn: true,

Transpose: true,
}))
})
Expand Down Expand Up @@ -247,6 +249,8 @@ var _ = Describe("RunErrandCmd", func() {

Notes: []string{},

FillFirstColumn: true,

Transpose: true,
}))

Expand Down
8 changes: 4 additions & 4 deletions ui/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ func (t Table) Print(w io.Writer) error {
rowCount += len(section.Rows)
}

rows := t.AsRows()

if t.Transpose {
var newRows [][]Value

headerVals := buildHeaderVals(t)

for i, row := range t.Rows {
for i, row := range rows {
for j, val := range row {
if t.Header[j].Hidden {
continue
Expand All @@ -112,7 +114,7 @@ func (t Table) Print(w io.Writer) error {
}
}

t.Rows = newRows
rows = newRows
t.Header = []Header{
{Hidden: t.DataOnly},
{Hidden: false},
Expand All @@ -123,8 +125,6 @@ func (t Table) Print(w io.Writer) error {
}
}

rows := t.AsRows()

for _, row := range rows {
writer.Write(t.Header, row)
}
Expand Down
34 changes: 34 additions & 0 deletions ui/table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,40 @@ Header2|v2|
`))
})

Context("when table also has a SortBy value set", func() {
It("prints as transposed table with sections sorted by the SortBy", func() {
table := Table{
Content: "errands",
Header: []Header{
NewHeader("Header1"),
NewHeader("OtherHeader2"),
NewHeader("Header3"),
},
Rows: [][]Value{
{ValueString{"r1c1"}, ValueString{"longr1c2"}, ValueString{"r1c3"}},
{ValueString{"r2c1"}, ValueString{"r2c2"}, ValueString{"r2c3"}},
},
SortBy: []ColumnSort{
{Column: 0, Asc: true},
},
BackgroundStr: ".",
BorderStr: "|",
Transpose: true,
}
table.Print(buf)
Expect("\n" + buf.String()).To(Equal(`
Header1.....|r1c1....|
OtherHeader2|longr1c2|
Header3.....|r1c3....|
Header1.....|r2c1....|
OtherHeader2|r2c2....|
Header3.....|r2c3....|
2 errands
`))
})
})
})

Context("when column filtering is used", func() {
Expand Down

0 comments on commit ef55792

Please sign in to comment.