From 89d7f6cf868b7f4c5da443a052b9905f3fb9d71b Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Sat, 30 Jan 2021 20:44:48 -0500 Subject: [PATCH] Move pkg/print to internal/print Originally pkg/print was intended to be public to be used by plugin developers, but this setting has to be defined by plugin-sdk and as such it's moved to internal/format to be only used by terraform-docs core project. Signed-off-by: Khosrow Moossavi --- internal/cli/config.go | 4 +- internal/format/asciidoc_document.go | 15 +++- internal/format/asciidoc_document_test.go | 2 +- internal/format/asciidoc_table.go | 17 ++++- internal/format/asciidoc_table_test.go | 2 +- internal/format/factory.go | 56 +++++++-------- internal/format/factory_test.go | 22 +++--- internal/format/json.go | 12 +++- internal/format/json_test.go | 2 +- internal/format/markdown_document.go | 25 ++++--- internal/format/markdown_document_test.go | 52 +++++++------- internal/format/markdown_table.go | 27 ++++--- internal/format/markdown_table_test.go | 52 +++++++------- internal/format/pretty.go | 12 +++- internal/format/pretty_test.go | 2 +- internal/format/tfvars_hcl.go | 12 +++- internal/format/tfvars_hcl_test.go | 2 +- internal/format/tfvars_json.go | 12 +++- internal/format/tfvars_json_test.go | 2 +- internal/format/toml.go | 12 +++- internal/format/toml_test.go | 2 +- internal/format/xml.go | 12 +++- internal/format/xml_test.go | 2 +- internal/format/yaml.go | 12 +++- internal/format/yaml_test.go | 2 +- {pkg => internal}/print/doc.go | 0 .../print.go => internal/print/engine.go | 4 +- {pkg => internal}/print/settings.go | 70 ++++++++++++++----- internal/testutil/settings.go | 2 +- pkg/tmpl/sanitizer.go | 2 +- pkg/tmpl/sanitizer_test.go | 2 +- pkg/tmpl/template.go | 4 +- pkg/tmpl/template_test.go | 6 +- scripts/docs/generate.go | 4 +- 34 files changed, 286 insertions(+), 180 deletions(-) rename {pkg => internal}/print/doc.go (100%) rename pkg/print/print.go => internal/print/engine.go (80%) rename {pkg => internal}/print/settings.go (63%) diff --git a/internal/cli/config.go b/internal/cli/config.go index cddb2f3..517ea52 100644 --- a/internal/cli/config.go +++ b/internal/cli/config.go @@ -13,8 +13,8 @@ package cli import ( "fmt" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" ) type _sections struct { @@ -326,7 +326,7 @@ func (c *Config) validate() error { // extract and build print.Settings and terraform.Options out of Config func (c *Config) extract() (*print.Settings, *terraform.Options) { - settings := print.NewSettings() + settings := print.DefaultSettings() options := terraform.NewOptions() // header-from diff --git a/internal/format/asciidoc_document.go b/internal/format/asciidoc_document.go index a1d7774..5cec542 100644 --- a/internal/format/asciidoc_document.go +++ b/internal/format/asciidoc_document.go @@ -13,8 +13,8 @@ package format import ( "text/template" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -165,7 +165,7 @@ type AsciidocDocument struct { } // NewAsciidocDocument returns new instance of AsciidocDocument. -func NewAsciidocDocument(settings *print.Settings) *AsciidocDocument { +func NewAsciidocDocument(settings *print.Settings) print.Engine { tt := tmpl.NewTemplate(&tmpl.Item{ Name: "document", Text: asciidocDocumentTpl, @@ -220,7 +220,7 @@ func NewAsciidocDocument(settings *print.Settings) *AsciidocDocument { } } -// Print prints a Terraform module as AsciiDoc document. +// Print a Terraform module as AsciiDoc document. func (d *AsciidocDocument) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := d.template.Render(module) if err != nil { @@ -228,3 +228,12 @@ func (d *AsciidocDocument) Print(module *terraform.Module, settings *print.Setti } return sanitize(rendered), nil } + +func init() { + register(map[string]initializerFn{ + "asciidoc document": NewAsciidocDocument, + "asciidoc doc": NewAsciidocDocument, + "adoc document": NewAsciidocDocument, + "adoc doc": NewAsciidocDocument, + }) +} diff --git a/internal/format/asciidoc_document_test.go b/internal/format/asciidoc_document_test.go index b7f2d53..1a098d2 100644 --- a/internal/format/asciidoc_document_test.go +++ b/internal/format/asciidoc_document_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestAsciidocDocument(t *testing.T) { diff --git a/internal/format/asciidoc_table.go b/internal/format/asciidoc_table.go index 999e954..3a6fc87 100644 --- a/internal/format/asciidoc_table.go +++ b/internal/format/asciidoc_table.go @@ -13,8 +13,8 @@ package format import ( "text/template" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -143,7 +143,7 @@ type AsciidocTable struct { } // NewAsciidocTable returns new instance of AsciidocTable. -func NewAsciidocTable(settings *print.Settings) *AsciidocTable { +func NewAsciidocTable(settings *print.Settings) print.Engine { tt := tmpl.NewTemplate(&tmpl.Item{ Name: "table", Text: asciidocTableTpl, @@ -186,7 +186,7 @@ func NewAsciidocTable(settings *print.Settings) *AsciidocTable { } } -// Print prints a Terraform module as AsciiDoc tables. +// Print a Terraform module as AsciiDoc tables. func (t *AsciidocTable) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := t.template.Render(module) if err != nil { @@ -194,3 +194,14 @@ func (t *AsciidocTable) Print(module *terraform.Module, settings *print.Settings } return sanitize(rendered), nil } + +func init() { + register(map[string]initializerFn{ + "asciidoc": NewAsciidocTable, + "asciidoc table": NewAsciidocTable, + "asciidoc tbl": NewAsciidocTable, + "adoc": NewAsciidocTable, + "adoc table": NewAsciidocTable, + "adoc tbl": NewAsciidocTable, + }) +} diff --git a/internal/format/asciidoc_table_test.go b/internal/format/asciidoc_table_test.go index da81f8c..4368a41 100644 --- a/internal/format/asciidoc_table_test.go +++ b/internal/format/asciidoc_table_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestAsciidocTable(t *testing.T) { diff --git a/internal/format/factory.go b/internal/format/factory.go index 9537781..4d1513b 100644 --- a/internal/format/factory.go +++ b/internal/format/factory.go @@ -13,41 +13,33 @@ package format import ( "fmt" - "github.com/terraform-docs/terraform-docs/pkg/print" + "github.com/terraform-docs/terraform-docs/internal/print" ) -// Factory initializes and returns the conceret implementation of -// print.Format based on the provided 'name', for example for name +// initializerFn returns a concrete implementation of an Engine. +type initializerFn func(*print.Settings) print.Engine + +// initializers list of all registered engine initializer functions. +var initializers = make(map[string]initializerFn) + +// register a formatter engine initializer function. +func register(e map[string]initializerFn) { + if e == nil { + return + } + for k, v := range e { + initializers[k] = v + } +} + +// Factory initializes and returns the concrete implementation of +// format.Engine based on the provided 'name', for example for name // of 'json' it will return '*format.JSON' through 'format.NewJSON' // function. -func Factory(name string, settings *print.Settings) (print.Format, error) { - switch name { - case "asciidoc", "adoc": - return NewAsciidocTable(settings), nil - case "asciidoc document", "asciidoc doc", "adoc document", "adoc doc": - return NewAsciidocDocument(settings), nil - case "asciidoc table", "asciidoc tbl", "adoc table", "adoc tbl": - return NewAsciidocTable(settings), nil - case "json": - return NewJSON(settings), nil - case "markdown", "md": - return NewTable(settings), nil - case "markdown document", "markdown doc", "md document", "md doc": - return NewDocument(settings), nil - case "markdown table", "markdown tbl", "md table", "md tbl": - return NewTable(settings), nil - case "pretty": - return NewPretty(settings), nil - case "tfvars hcl": - return NewTfvarsHCL(settings), nil - case "tfvars json": - return NewTfvarsJSON(settings), nil - case "toml": - return NewTOML(settings), nil - case "xml": - return NewXML(settings), nil - case "yaml": - return NewYAML(settings), nil +func Factory(name string, settings *print.Settings) (print.Engine, error) { + fn, ok := initializers[name] + if !ok { + return nil, fmt.Errorf("formatter '%s' not found", name) } - return nil, fmt.Errorf("formatter '%s' not found", name) + return fn(settings), nil } diff --git a/internal/format/factory_test.go b/internal/format/factory_test.go index 191e436..60049d2 100644 --- a/internal/format/factory_test.go +++ b/internal/format/factory_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/terraform-docs/terraform-docs/pkg/print" + "github.com/terraform-docs/terraform-docs/internal/print" ) func TestFormatFactory(t *testing.T) { @@ -95,61 +95,61 @@ func TestFormatFactory(t *testing.T) { { name: "format factory from name", format: "markdown", - expected: "*format.Table", + expected: "*format.MarkdownTable", wantErr: false, }, { name: "format factory from name", format: "md", - expected: "*format.Table", + expected: "*format.MarkdownTable", wantErr: false, }, { name: "format factory from name", format: "markdown document", - expected: "*format.Document", + expected: "*format.MarkdownDocument", wantErr: false, }, { name: "format factory from name", format: "markdown doc", - expected: "*format.Document", + expected: "*format.MarkdownDocument", wantErr: false, }, { name: "format factory from name", format: "md document", - expected: "*format.Document", + expected: "*format.MarkdownDocument", wantErr: false, }, { name: "format factory from name", format: "md doc", - expected: "*format.Document", + expected: "*format.MarkdownDocument", wantErr: false, }, { name: "format factory from name", format: "markdown table", - expected: "*format.Table", + expected: "*format.MarkdownTable", wantErr: false, }, { name: "format factory from name", format: "markdown tbl", - expected: "*format.Table", + expected: "*format.MarkdownTable", wantErr: false, }, { name: "format factory from name", format: "md table", - expected: "*format.Table", + expected: "*format.MarkdownTable", wantErr: false, }, { name: "format factory from name", format: "md tbl", - expected: "*format.Table", + expected: "*format.MarkdownTable", wantErr: false, }, { diff --git a/internal/format/json.go b/internal/format/json.go index afeedee..41ee022 100644 --- a/internal/format/json.go +++ b/internal/format/json.go @@ -15,19 +15,19 @@ import ( "encoding/json" "strings" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" ) // JSON represents JSON format. type JSON struct{} // NewJSON returns new instance of JSON. -func NewJSON(settings *print.Settings) *JSON { +func NewJSON(settings *print.Settings) print.Engine { return &JSON{} } -// Print prints a Terraform module as json. +// Print a Terraform module as json. func (j *JSON) Print(module *terraform.Module, settings *print.Settings) (string, error) { copy := &terraform.Module{ Header: "", @@ -70,3 +70,9 @@ func (j *JSON) Print(module *terraform.Module, settings *print.Settings) (string return strings.TrimSuffix(buffer.String(), "\n"), nil } + +func init() { + register(map[string]initializerFn{ + "json": NewJSON, + }) +} diff --git a/internal/format/json_test.go b/internal/format/json_test.go index 373fd9f..57c806b 100644 --- a/internal/format/json_test.go +++ b/internal/format/json_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestJson(t *testing.T) { diff --git a/internal/format/markdown_document.go b/internal/format/markdown_document.go index 45c47d1..a2e4dbc 100644 --- a/internal/format/markdown_document.go +++ b/internal/format/markdown_document.go @@ -13,8 +13,8 @@ package format import ( "text/template" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -159,13 +159,13 @@ const ( ` ) -// Document represents Markdown Document format. -type Document struct { +// MarkdownDocument represents Markdown Document format. +type MarkdownDocument struct { template *tmpl.Template } -// NewDocument returns new instance of Document. -func NewDocument(settings *print.Settings) *Document { +// NewMarkdownDocument returns new instance of Document. +func NewMarkdownDocument(settings *print.Settings) print.Engine { tt := tmpl.NewTemplate(&tmpl.Item{ Name: "document", Text: documentTpl, @@ -214,16 +214,25 @@ func NewDocument(settings *print.Settings) *Document { return settings.ShowRequired }, }) - return &Document{ + return &MarkdownDocument{ template: tt, } } -// Print prints a Terraform module as Markdown document. -func (d *Document) Print(module *terraform.Module, settings *print.Settings) (string, error) { +// Print a Terraform module as Markdown document. +func (d *MarkdownDocument) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := d.template.Render(module) if err != nil { return "", err } return sanitize(rendered), nil } + +func init() { + register(map[string]initializerFn{ + "markdown document": NewMarkdownDocument, + "markdown doc": NewMarkdownDocument, + "md document": NewMarkdownDocument, + "md doc": NewMarkdownDocument, + }) +} diff --git a/internal/format/markdown_document_test.go b/internal/format/markdown_document_test.go index 85b7260..990aa2b 100644 --- a/internal/format/markdown_document_test.go +++ b/internal/format/markdown_document_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestDocument(t *testing.T) { @@ -31,7 +31,7 @@ func TestDocument(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -51,7 +51,7 @@ func TestDocumentWithRequired(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -77,7 +77,7 @@ func TestDocumentSortByName(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -105,7 +105,7 @@ func TestDocumentSortByRequired(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -131,7 +131,7 @@ func TestDocumentSortByType(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -156,7 +156,7 @@ func TestDocumentNoHeader(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -181,7 +181,7 @@ func TestDocumentNoInputs(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -206,7 +206,7 @@ func TestDocumentNoOutputs(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -231,7 +231,7 @@ func TestDocumentNoProviders(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -256,7 +256,7 @@ func TestDocumentNoRequirements(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -281,7 +281,7 @@ func TestDocumentNoResources(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -306,7 +306,7 @@ func TestDocumentOnlyHeader(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -331,7 +331,7 @@ func TestDocumentOnlyInputs(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -356,7 +356,7 @@ func TestDocumentOnlyOutputs(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -381,7 +381,7 @@ func TestDocumentOnlyProviders(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -406,7 +406,7 @@ func TestDocumentOnlyRequirements(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -431,7 +431,7 @@ func TestDocumentOnlyResources(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -451,7 +451,7 @@ func TestDocumentEscapeCharacters(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -471,7 +471,7 @@ func TestDocumentIndentationBelowAllowed(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -491,7 +491,7 @@ func TestDocumentIndentationAboveAllowed(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -511,7 +511,7 @@ func TestDocumentIndentationOfFour(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -537,7 +537,7 @@ func TestDocumentOutputValues(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -587,7 +587,7 @@ func TestDocumentHeaderFromFile(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -615,7 +615,7 @@ func TestDocumentOutputValuesNoSensitivity(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -640,7 +640,7 @@ func TestDocumentEmpty(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewDocument(settings) + printer := NewMarkdownDocument(settings) actual, err := printer.Print(module, settings) assert.Nil(err) diff --git a/internal/format/markdown_table.go b/internal/format/markdown_table.go index 7bc9fb4..428bf6d 100644 --- a/internal/format/markdown_table.go +++ b/internal/format/markdown_table.go @@ -13,8 +13,8 @@ package format import ( "text/template" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -126,13 +126,13 @@ const ( ` ) -// Table represents Markdown Table format. -type Table struct { +// MarkdownTable represents Markdown Table format. +type MarkdownTable struct { template *tmpl.Template } -// NewTable returns new instance of Table. -func NewTable(settings *print.Settings) *Table { +// NewMarkdownTable returns new instance of Table. +func NewMarkdownTable(settings *print.Settings) print.Engine { tt := tmpl.NewTemplate(&tmpl.Item{ Name: "table", Text: tableTpl, @@ -169,16 +169,27 @@ func NewTable(settings *print.Settings) *Table { return result }, }) - return &Table{ + return &MarkdownTable{ template: tt, } } -// Print prints a Terraform module as Markdown tables. -func (t *Table) Print(module *terraform.Module, settings *print.Settings) (string, error) { +// Print a Terraform module as Markdown tables. +func (t *MarkdownTable) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := t.template.Render(module) if err != nil { return "", err } return sanitize(rendered), nil } + +func init() { + register(map[string]initializerFn{ + "markdown": NewMarkdownTable, + "markdown table": NewMarkdownTable, + "markdown tbl": NewMarkdownTable, + "md": NewMarkdownTable, + "md table": NewMarkdownTable, + "md tbl": NewMarkdownTable, + }) +} diff --git a/internal/format/markdown_table_test.go b/internal/format/markdown_table_test.go index a266287..49b0b5c 100644 --- a/internal/format/markdown_table_test.go +++ b/internal/format/markdown_table_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestTable(t *testing.T) { @@ -31,7 +31,7 @@ func TestTable(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -51,7 +51,7 @@ func TestTableWithRequired(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -77,7 +77,7 @@ func TestTableSortByName(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -105,7 +105,7 @@ func TestTableSortByRequired(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -131,7 +131,7 @@ func TestTableSortByType(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -156,7 +156,7 @@ func TestTableNoHeader(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -181,7 +181,7 @@ func TestTableNoInputs(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -206,7 +206,7 @@ func TestTableNoOutputs(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -231,7 +231,7 @@ func TestTableNoProviders(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -256,7 +256,7 @@ func TestTableNoRequirements(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -281,7 +281,7 @@ func TestTableNoResources(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -306,7 +306,7 @@ func TestTableOnlyHeader(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -331,7 +331,7 @@ func TestTableOnlyInputs(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -356,7 +356,7 @@ func TestTableOnlyOutputs(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -381,7 +381,7 @@ func TestTableOnlyProviders(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -406,7 +406,7 @@ func TestTableOnlyRequirements(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -431,7 +431,7 @@ func TestTableOnlyResources(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -451,7 +451,7 @@ func TestTableEscapeCharacters(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -471,7 +471,7 @@ func TestTableIndentationBelowAllowed(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -491,7 +491,7 @@ func TestTableIndentationAboveAllowed(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -511,7 +511,7 @@ func TestTableIndentationOfFour(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -537,7 +537,7 @@ func TestTableOutputValues(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -587,7 +587,7 @@ func TestTableHeaderFromFile(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -615,7 +615,7 @@ func TestTableOutputValuesNoSensitivity(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) @@ -640,7 +640,7 @@ func TestTableEmpty(t *testing.T) { module, err := testutil.GetModule(options) assert.Nil(err) - printer := NewTable(settings) + printer := NewMarkdownTable(settings) actual, err := printer.Print(module, settings) assert.Nil(err) diff --git a/internal/format/pretty.go b/internal/format/pretty.go index 5397d15..9120a02 100644 --- a/internal/format/pretty.go +++ b/internal/format/pretty.go @@ -15,8 +15,8 @@ import ( "regexp" "text/template" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -114,7 +114,7 @@ type Pretty struct { } // NewPretty returns new instance of Pretty. -func NewPretty(settings *print.Settings) *Pretty { +func NewPretty(settings *print.Settings) print.Engine { tt := tmpl.NewTemplate(&tmpl.Item{ Name: "pretty", Text: prettyTpl, @@ -153,7 +153,7 @@ func NewPretty(settings *print.Settings) *Pretty { } } -// Print prints a Terraform module document. +// Print a Terraform module document. func (p *Pretty) Print(module *terraform.Module, settings *print.Settings) (string, error) { rendered, err := p.template.Render(module) if err != nil { @@ -161,3 +161,9 @@ func (p *Pretty) Print(module *terraform.Module, settings *print.Settings) (stri } return regexp.MustCompile(`(\r?\n)*$`).ReplaceAllString(rendered, ""), nil } + +func init() { + register(map[string]initializerFn{ + "pretty": NewPretty, + }) +} diff --git a/internal/format/pretty_test.go b/internal/format/pretty_test.go index 3115563..5ced0db 100644 --- a/internal/format/pretty_test.go +++ b/internal/format/pretty_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestPretty(t *testing.T) { diff --git a/internal/format/tfvars_hcl.go b/internal/format/tfvars_hcl.go index 51ddd28..b17693b 100644 --- a/internal/format/tfvars_hcl.go +++ b/internal/format/tfvars_hcl.go @@ -16,8 +16,8 @@ import ( "strings" "text/template" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" "github.com/terraform-docs/terraform-docs/pkg/tmpl" ) @@ -39,7 +39,7 @@ type TfvarsHCL struct { var padding []int // NewTfvarsHCL returns new instance of TfvarsHCL. -func NewTfvarsHCL(settings *print.Settings) *TfvarsHCL { +func NewTfvarsHCL(settings *print.Settings) print.Engine { tt := tmpl.NewTemplate(&tmpl.Item{ Name: "tfvars", Text: tfvarsHCLTpl, @@ -61,7 +61,7 @@ func NewTfvarsHCL(settings *print.Settings) *TfvarsHCL { } } -// Print prints a Terraform module as Terraform tfvars HCL document. +// Print a Terraform module as Terraform tfvars HCL. func (h *TfvarsHCL) Print(module *terraform.Module, settings *print.Settings) (string, error) { alignments(module.Inputs) rendered, err := h.template.Render(module) @@ -96,3 +96,9 @@ func alignments(inputs []*terraform.Input) { padding[i] = maxlen } } + +func init() { + register(map[string]initializerFn{ + "tfvars hcl": NewTfvarsHCL, + }) +} diff --git a/internal/format/tfvars_hcl_test.go b/internal/format/tfvars_hcl_test.go index 5c5e1d2..f2d2628 100644 --- a/internal/format/tfvars_hcl_test.go +++ b/internal/format/tfvars_hcl_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestTfvarsHcl(t *testing.T) { diff --git a/internal/format/tfvars_json.go b/internal/format/tfvars_json.go index 0bbbdda..9ecdb47 100644 --- a/internal/format/tfvars_json.go +++ b/internal/format/tfvars_json.go @@ -17,19 +17,19 @@ import ( "github.com/iancoleman/orderedmap" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" ) // TfvarsJSON represents Terraform tfvars JSON format. type TfvarsJSON struct{} // NewTfvarsJSON returns new instance of TfvarsJSON. -func NewTfvarsJSON(settings *print.Settings) *TfvarsJSON { +func NewTfvarsJSON(settings *print.Settings) print.Engine { return &TfvarsJSON{} } -// Print prints a Terraform module as Terraform tfvars JSON document. +// Print a Terraform module as Terraform tfvars JSON. func (j *TfvarsJSON) Print(module *terraform.Module, settings *print.Settings) (string, error) { copy := orderedmap.New() copy.SetEscapeHTML(false) @@ -50,3 +50,9 @@ func (j *TfvarsJSON) Print(module *terraform.Module, settings *print.Settings) ( return strings.TrimSuffix(buffer.String(), "\n"), nil } + +func init() { + register(map[string]initializerFn{ + "tfvars json": NewTfvarsJSON, + }) +} diff --git a/internal/format/tfvars_json_test.go b/internal/format/tfvars_json_test.go index 61c4550..140afb2 100644 --- a/internal/format/tfvars_json_test.go +++ b/internal/format/tfvars_json_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestTfvarsJson(t *testing.T) { diff --git a/internal/format/toml.go b/internal/format/toml.go index f945de1..fbdab41 100644 --- a/internal/format/toml.go +++ b/internal/format/toml.go @@ -16,19 +16,19 @@ import ( "github.com/BurntSushi/toml" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" ) // TOML represents TOML format. type TOML struct{} // NewTOML returns new instance of TOML. -func NewTOML(settings *print.Settings) *TOML { +func NewTOML(settings *print.Settings) print.Engine { return &TOML{} } -// Print prints a Terraform module as toml. +// Print a Terraform module as toml. func (t *TOML) Print(module *terraform.Module, settings *print.Settings) (string, error) { copy := terraform.Module{ Header: "", @@ -67,3 +67,9 @@ func (t *TOML) Print(module *terraform.Module, settings *print.Settings) (string return strings.TrimSuffix(buffer.String(), "\n"), nil } + +func init() { + register(map[string]initializerFn{ + "toml": NewTOML, + }) +} diff --git a/internal/format/toml_test.go b/internal/format/toml_test.go index d2ccfbf..53ffe1e 100644 --- a/internal/format/toml_test.go +++ b/internal/format/toml_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestToml(t *testing.T) { diff --git a/internal/format/xml.go b/internal/format/xml.go index 9e13165..ba465fb 100644 --- a/internal/format/xml.go +++ b/internal/format/xml.go @@ -14,19 +14,19 @@ import ( "encoding/xml" "strings" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" ) // XML represents XML format. type XML struct{} // NewXML returns new instance of XML. -func NewXML(settings *print.Settings) *XML { +func NewXML(settings *print.Settings) print.Engine { return &XML{} } -// Print prints a Terraform module as xml. +// Print a Terraform module as xml. func (x *XML) Print(module *terraform.Module, settings *print.Settings) (string, error) { copy := &terraform.Module{ Header: "", @@ -63,3 +63,9 @@ func (x *XML) Print(module *terraform.Module, settings *print.Settings) (string, return strings.TrimSuffix(string(out), "\n"), nil } + +func init() { + register(map[string]initializerFn{ + "xml": NewXML, + }) +} diff --git a/internal/format/xml_test.go b/internal/format/xml_test.go index 02f2433..a1c96a3 100644 --- a/internal/format/xml_test.go +++ b/internal/format/xml_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestXml(t *testing.T) { diff --git a/internal/format/yaml.go b/internal/format/yaml.go index 1ef57b0..dc5bc20 100644 --- a/internal/format/yaml.go +++ b/internal/format/yaml.go @@ -16,19 +16,19 @@ import ( "gopkg.in/yaml.v3" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" ) // YAML represents YAML format. type YAML struct{} // NewYAML returns new instance of YAML. -func NewYAML(settings *print.Settings) *YAML { +func NewYAML(settings *print.Settings) print.Engine { return &YAML{} } -// Print prints a Terraform module as yaml. +// Print a Terraform module as yaml. func (y *YAML) Print(module *terraform.Module, settings *print.Settings) (string, error) { copy := &terraform.Module{ Header: "", @@ -70,3 +70,9 @@ func (y *YAML) Print(module *terraform.Module, settings *print.Settings) (string return strings.TrimSuffix(buffer.String(), "\n"), nil } + +func init() { + register(map[string]initializerFn{ + "yaml": NewYAML, + }) +} diff --git a/internal/format/yaml_test.go b/internal/format/yaml_test.go index 615bfaf..48ca4c0 100644 --- a/internal/format/yaml_test.go +++ b/internal/format/yaml_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestYaml(t *testing.T) { diff --git a/pkg/print/doc.go b/internal/print/doc.go similarity index 100% rename from pkg/print/doc.go rename to internal/print/doc.go diff --git a/pkg/print/print.go b/internal/print/engine.go similarity index 80% rename from pkg/print/print.go rename to internal/print/engine.go index f7b741e..a57640d 100644 --- a/pkg/print/print.go +++ b/internal/print/engine.go @@ -14,7 +14,7 @@ import ( "github.com/terraform-docs/terraform-docs/internal/terraform" ) -// Format represents a printer format (e.g. json, table, yaml, ...) -type Format interface { +// Engine represents a printer format engine (e.g. json, table, yaml, ...) +type Engine interface { Print(*terraform.Module, *Settings) (string, error) } diff --git a/pkg/print/settings.go b/internal/print/settings.go similarity index 63% rename from pkg/print/settings.go rename to internal/print/settings.go index 6fc0a3b..f5e7494 100644 --- a/pkg/print/settings.go +++ b/internal/print/settings.go @@ -10,75 +10,107 @@ the root directory of this source tree. package print -// Settings represents all settings +// Settings represents all settings. type Settings struct { - // EscapeCharacters escapes special characters (such as _ * in Markdown and > < in JSON) (default: true) + // EscapeCharacters escapes special characters (such as _ * in Markdown and > < in JSON) + // + // default: true // scope: Markdown EscapeCharacters bool - // EscapePipe escapes pipe character in Markdown (default: true) + // EscapePipe escapes pipe character in Markdown + // + // default: true // scope: Markdown EscapePipe bool - // IndentLevel control the indentation of AsciiDoc and Markdown headers [available: 1, 2, 3, 4, 5] (default: 2) + // IndentLevel control the indentation of AsciiDoc and Markdown headers [available: 1, 2, 3, 4, 5] + // + // default: 2 // scope: Asciidoc, Markdown IndentLevel int - // OutputValues ailrghaekrgj + // OutputValues extract and show Output values from Terraform module output + // + // default: false // scope: Global OutputValues bool - // ShowColor print "colorized" version of result in the terminal (default: true) + // ShowColor print "colorized" version of result in the terminal + // + // default: true // scope: Pretty ShowColor bool - // ShowHeader show "Header" module information (default: true) + // ShowHeader show "Header" module information + // + // default: true // scope: Global ShowHeader bool - // ShowInputs show "Inputs" information (default: true) + // ShowInputs show "Inputs" information + // + // default: true // scope: Global ShowInputs bool - // ShowOutputs show "Outputs" information (default: true) + // ShowOutputs show "Outputs" information + // + // default: true // scope: Global ShowOutputs bool - // ShowProviders show "Providers" information (default: true) + // ShowProviders show "Providers" information + // + // default: true // scope: Global ShowProviders bool - // ShowRequired show "Required" column when generating Markdown (default: true) + // ShowRequired show "Required" column when generating Markdown + // + // default: true // scope: Markdown ShowRequired bool - // ShowSensitivity show "Sensitive" column when generating Markdown (default: true) + // ShowSensitivity show "Sensitive" column when generating Markdown + // + // default: true // scope: Markdown ShowSensitivity bool - // ShowRequirements show "Requirements" section (default: true) + // ShowRequirements show "Requirements" section + // + // default: true // scope: Global ShowRequirements bool - // ShowResources show "Resources" section (default: true) + // ShowResources show "Resources" section + // + // default: true // scope: Global ShowResources bool - // SortByName sorted rendering of inputs and outputs (default: true) + // SortByName sorted rendering of inputs and outputs + // + // default: true // scope: Global SortByName bool - // SortByRequired sort items (inputs, providers) by name and prints required ones first (default: false) + // SortByRequired sort items (inputs, providers) by name and prints required ones first + // + // default: false // scope: Global SortByRequired bool - // SortByType sort items (inputs, outputs) by type alphabetically (default: false) + // SortByType sort items (inputs, outputs) by type alphabetically + // + // default: false // scope: Global SortByType bool } -// NewSettings returns new instance of Settings -func NewSettings() *Settings { +// DefaultSettings returns new instance of Settings +func DefaultSettings() *Settings { return &Settings{ EscapeCharacters: true, EscapePipe: true, diff --git a/internal/testutil/settings.go b/internal/testutil/settings.go index 7642349..edd1037 100644 --- a/internal/testutil/settings.go +++ b/internal/testutil/settings.go @@ -13,7 +13,7 @@ package testutil import ( "github.com/imdario/mergo" - "github.com/terraform-docs/terraform-docs/pkg/print" + "github.com/terraform-docs/terraform-docs/internal/print" ) // TestSettings respresents the Settings instance for tests diff --git a/pkg/tmpl/sanitizer.go b/pkg/tmpl/sanitizer.go index 209f2f1..0d26347 100644 --- a/pkg/tmpl/sanitizer.go +++ b/pkg/tmpl/sanitizer.go @@ -18,7 +18,7 @@ import ( "mvdan.cc/xurls/v2" - "github.com/terraform-docs/terraform-docs/pkg/print" + "github.com/terraform-docs/terraform-docs/internal/print" ) // sanitizeName escapes underscore character which have special meaning in Markdown. diff --git a/pkg/tmpl/sanitizer_test.go b/pkg/tmpl/sanitizer_test.go index 1c2208c..8e7076a 100644 --- a/pkg/tmpl/sanitizer_test.go +++ b/pkg/tmpl/sanitizer_test.go @@ -17,8 +17,8 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/testutil" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestSanitizeName(t *testing.T) { diff --git a/pkg/tmpl/template.go b/pkg/tmpl/template.go index 18861dc..3f7b676 100644 --- a/pkg/tmpl/template.go +++ b/pkg/tmpl/template.go @@ -16,9 +16,9 @@ import ( "strings" "text/template" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/types" - "github.com/terraform-docs/terraform-docs/pkg/print" ) // Item represents a named templated which can reference @@ -40,7 +40,7 @@ type Template struct { // NewTemplate returns new instance of Template func NewTemplate(items ...*Item) *Template { - settings := print.NewSettings() + settings := print.DefaultSettings() return &Template{ Items: items, settings: settings, diff --git a/pkg/tmpl/template_test.go b/pkg/tmpl/template_test.go index 4f48f34..2732013 100644 --- a/pkg/tmpl/template_test.go +++ b/pkg/tmpl/template_test.go @@ -20,9 +20,9 @@ import ( "github.com/stretchr/testify/assert" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" "github.com/terraform-docs/terraform-docs/internal/types" - "github.com/terraform-docs/terraform-docs/pkg/print" ) func TestTemplateRender(t *testing.T) { @@ -70,7 +70,7 @@ func TestTemplateRender(t *testing.T) { t.Run(tt.name, func(t *testing.T) { assert := assert.New(t) tpl := NewTemplate(tt.items...) - tpl.Settings(print.NewSettings()) + tpl.Settings(print.DefaultSettings()) tpl.CustomFunc(customFuncs) rendered, err := tpl.Render(module) if tt.wantErr { @@ -487,7 +487,7 @@ func TestBuiltinFunc(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert := assert.New(t) - settings := print.NewSettings() + settings := print.DefaultSettings() settings.EscapeCharacters = tt.escapeChar settings.EscapePipe = tt.escapePipe funcs := builtinFuncs(settings) diff --git a/scripts/docs/generate.go b/scripts/docs/generate.go index 498937f..aec33fe 100644 --- a/scripts/docs/generate.go +++ b/scripts/docs/generate.go @@ -24,8 +24,8 @@ import ( "github.com/terraform-docs/terraform-docs/cmd" "github.com/terraform-docs/terraform-docs/internal/format" + "github.com/terraform-docs/terraform-docs/internal/print" "github.com/terraform-docs/terraform-docs/internal/terraform" - "github.com/terraform-docs/terraform-docs/pkg/print" ) // These are practiaclly a copy/paste of https://github.com/spf13/cobra/blob/master/doc/md_docs.go @@ -156,7 +156,7 @@ func printExample(buf *bytes.Buffer, name string) error { buf.WriteString("```\n\n") buf.WriteString("generates the following output:\n\n") - settings := print.NewSettings() + settings := print.DefaultSettings() settings.ShowColor = false options := &terraform.Options{ Path: "./examples",