-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from goflink/feat/markdown-table
Feature: markdown table
- Loading branch information
Showing
4 changed files
with
36 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
) | ||
|
||
const StdinFileName = "stdin" | ||
|
||
type StdinReader struct { | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,50 @@ | ||
package writer | ||
|
||
import ( | ||
"github.com/olekukonko/tablewriter" | ||
"fmt" | ||
"io" | ||
"terraform-plan-summary/terraform_state" | ||
|
||
"github.com/olekukonko/tablewriter" | ||
) | ||
|
||
type TableWriter struct { | ||
changes map[string]terraform_state.ResourceChanges | ||
mdEnabled bool | ||
changes map[string]terraform_state.ResourceChanges | ||
} | ||
|
||
func (t TableWriter) Write(writer io.Writer) error { | ||
tableString := make([][]string, 0, 4) | ||
for change, changedResources := range t.changes { | ||
for _, changedResource := range changedResources { | ||
tableString = append(tableString, []string{change, changedResource.Address}) | ||
if t.mdEnabled { | ||
tableString = append(tableString, []string{change, fmt.Sprintf("`%s`", changedResource.Address)}) | ||
} else { | ||
tableString = append(tableString, []string{change, changedResource.Address}) | ||
} | ||
} | ||
} | ||
|
||
table := tablewriter.NewWriter(writer) | ||
table.SetHeader([]string{"Change", "Name"}) | ||
table.SetAutoMergeCells(true) | ||
table.SetRowLine(true) | ||
table.AppendBulk(tableString) | ||
|
||
if t.mdEnabled { | ||
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) | ||
table.SetCenterSeparator("|") | ||
} else { | ||
table.SetRowLine(true) | ||
} | ||
|
||
table.Render() | ||
|
||
return nil | ||
} | ||
|
||
func NewTableWriter(changes map[string]terraform_state.ResourceChanges) Writer { | ||
return TableWriter{changes: changes} | ||
func NewTableWriter(changes map[string]terraform_state.ResourceChanges, mdEnabled bool) Writer { | ||
return TableWriter{ | ||
changes: changes, | ||
mdEnabled: mdEnabled, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters