From e9cd7da7468c50754f0da8a347f496fe97a19b3d Mon Sep 17 00:00:00 2001 From: Mike Ball Date: Sun, 7 Jan 2024 14:38:57 -0500 Subject: [PATCH] ensure multiple markdown tables are rendered 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. --- writer/table.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/writer/table.go b/writer/table.go index 8641fa2..05b0adf 100644 --- a/writer/table.go +++ b/writer/table.go @@ -62,8 +62,10 @@ 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() + // Without a line break separating each table, a single malformed markdown table is printed. + // Printing an empty newline ensures distinct, separate tables are rendered. + fmt.Fprint(writer, tablewriter.NEWLINE) + table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) table.SetCenterSeparator("|") } else { @@ -77,7 +79,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,