Skip to content

Commit

Permalink
ensure multiple markdown tables are rendered
Browse files Browse the repository at this point in the history
This seeks to fix issue #61 by printing all output to the `io.Writer` passed to
`writer.TableWriter#Write`. This ensures multiple, distinct markdown tables are
printed, even when `tf-summarize` is invoked with both `-md` and `-out` flags.

Previously, `fmt.Println()` was used to separate the markdown tables,
but this is insufficient when `-out` is used with a non-STDOUT writer, as is the
case when writing output to a `-out`-specified file.
  • Loading branch information
mdb committed Jan 7, 2024
1 parent 5c19269 commit 6858d2b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions writer/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ func (t TableWriter) Write(writer io.Writer) error {
table.AppendBulk(tableString)

if t.mdEnabled {
// Adding a println to break up the tables in md mode
fmt.Println()
// Printing an empty newline ensures distinct tables are rendered.
fmt.Fprint(writer, tablewriter.NEWLINE)

table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
} else {
Expand All @@ -77,7 +78,6 @@ func (t TableWriter) Write(writer io.Writer) error {
}

func NewTableWriter(changes map[string]terraformstate.ResourceChanges, outputChanges map[string][]string, mdEnabled bool) Writer {

return TableWriter{
changes: changes,
mdEnabled: mdEnabled,
Expand Down

0 comments on commit 6858d2b

Please sign in to comment.