-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
115476a
commit e6c8d4f
Showing
3 changed files
with
109 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package pluginprinter | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/doublecloud/tross/internal/core/xerrors" | ||
"github.com/olekukonko/tablewriter" | ||
) | ||
|
||
func boolToString(value bool) string { | ||
if value { | ||
return "+" | ||
} | ||
return "" | ||
} | ||
|
||
func Print(sources, destinations, parsers, transformers []string, title string) error { | ||
if _, err := io.WriteString(os.Stdout, title+"\n"); err != nil { | ||
return xerrors.Errorf("unable to write string title: %w", err) | ||
} | ||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetRowLine(true) | ||
table.SetHeader([]string{"Provider", "Source", "Target"}) | ||
|
||
mapProviders := make(map[string][]bool) | ||
for _, source := range sources { | ||
if _, ok := mapProviders[source]; !ok { | ||
mapProviders[source] = make([]bool, 2) | ||
} | ||
mapProviders[source][0] = true | ||
} | ||
for _, destination := range destinations { | ||
if _, ok := mapProviders[destination]; !ok { | ||
mapProviders[destination] = make([]bool, 2) | ||
} | ||
mapProviders[destination][1] = true | ||
} | ||
|
||
for provider, row := range mapProviders { | ||
oneRow := make([]string, len(row)+1) | ||
for i, file := range row { | ||
oneRow[i+1] = boolToString(file) | ||
} | ||
oneRow[0] = provider | ||
table.Append(oneRow) | ||
} | ||
|
||
table.Render() | ||
|
||
if _, err := io.WriteString(os.Stdout, "\n"); err != nil { | ||
return xerrors.Errorf("unable to write string eol: %w", err) | ||
} | ||
|
||
tableParser := tablewriter.NewWriter(os.Stdout) | ||
tableParser.SetRowLine(true) | ||
tableParser.SetHeader([]string{"Parser", "Imported"}) | ||
|
||
for _, parser := range parsers { | ||
row := make([]string, 2) | ||
row[0] = parser | ||
row[1] = boolToString(true) | ||
tableParser.Append(row) | ||
} | ||
|
||
tableParser.Render() | ||
|
||
if _, err := io.WriteString(os.Stdout, "\n"); err != nil { | ||
return xerrors.Errorf("unable to write string eol: %w", err) | ||
} | ||
|
||
tableTransformer := tablewriter.NewWriter(os.Stdout) | ||
tableTransformer.SetRowLine(true) | ||
tableTransformer.SetHeader([]string{"Transformer", "Imported"}) | ||
|
||
for _, transformer := range transformers { | ||
row := make([]string, 2) | ||
row[0] = transformer | ||
row[1] = boolToString(true) | ||
tableTransformer.Append(row) | ||
} | ||
tableTransformer.Render() | ||
|
||
if _, err := io.WriteString(os.Stdout, "\n"); err != nil { | ||
return xerrors.Errorf("unable to write string eol: %w", err) | ||
} | ||
|
||
return nil | ||
} |