diff --git a/README.md b/README.md index daafe13..5587725 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ A utility to generate documentation from Terraform modules in various output formats. ``` bash +terraform-docs asciidoc ./my-terraform-module # generate asciidoc table +terraform-docs asciidoc table ./my-terraform-module # generate asciidoc table +terraform-docs asciidoc document ./my-terraform-module # generate asciidoc document terraform-docs json ./my-terraform-module # generate json terraform-docs markdown ./my-terraform-module # generate markdown table terraform-docs markdown table ./my-terraform-module # generate markdown table diff --git a/cmd/asciidoc.go b/cmd/asciidoc.go new file mode 100644 index 0000000..1b0f218 --- /dev/null +++ b/cmd/asciidoc.go @@ -0,0 +1,43 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var asciidocCmd = &cobra.Command{ + Args: cobra.ExactArgs(1), + Use: "asciidoc [PATH]", + Aliases: []string{"adoc"}, + Short: "Generate AsciiDoc of inputs and outputs", + Annotations: formatAnnotations("asciidoc"), + RunE: formatRunE, +} + +var asciidocTableCmd = &cobra.Command{ + Args: cobra.ExactArgs(1), + Use: "table [PATH]", + Aliases: []string{"tbl"}, + Short: "Generate AsciiDoc tables of inputs and outputs", + Annotations: formatAnnotations("asciidoc table"), + RunE: formatRunE, +} + +var asciidocDocumentCmd = &cobra.Command{ + Args: cobra.ExactArgs(1), + Use: "document [PATH]", + Aliases: []string{"doc"}, + Short: "Generate AsciiDoc document of inputs and outputs", + Annotations: formatAnnotations("asciidoc document"), + RunE: formatRunE, +} + +func init() { + asciidocCmd.PersistentFlags().BoolVar(new(bool), "no-required", false, "do not show \"Required\" column or section") + asciidocCmd.PersistentFlags().BoolVar(new(bool), "no-sensitive", false, "do not show \"Sensitive\" column or section") + asciidocCmd.PersistentFlags().IntVar(&settings.IndentLevel, "indent", 2, "indention level of AsciiDoc sections [1, 2, 3, 4, 5]") + + asciidocCmd.AddCommand(asciidocTableCmd) + asciidocCmd.AddCommand(asciidocDocumentCmd) + + rootCmd.AddCommand(asciidocCmd) +} diff --git a/cmd/markdown.go b/cmd/markdown.go index 3e4baec..56f3d5b 100644 --- a/cmd/markdown.go +++ b/cmd/markdown.go @@ -35,7 +35,7 @@ func init() { markdownCmd.PersistentFlags().BoolVar(new(bool), "no-required", false, "do not show \"Required\" column or section") markdownCmd.PersistentFlags().BoolVar(new(bool), "no-sensitive", false, "do not show \"Sensitive\" column or section") markdownCmd.PersistentFlags().BoolVar(new(bool), "no-escape", false, "do not escape special characters") - markdownCmd.PersistentFlags().IntVar(&settings.MarkdownIndent, "indent", 2, "indention level of Markdown sections [1, 2, 3, 4, 5]") + markdownCmd.PersistentFlags().IntVar(&settings.IndentLevel, "indent", 2, "indention level of Markdown sections [1, 2, 3, 4, 5]") markdownCmd.AddCommand(markdownTableCmd) markdownCmd.AddCommand(markdownDocumentCmd) diff --git a/docs/FORMATS_GUIDE.md b/docs/FORMATS_GUIDE.md index eddcac9..41dc2d5 100644 --- a/docs/FORMATS_GUIDE.md +++ b/docs/FORMATS_GUIDE.md @@ -26,6 +26,9 @@ A utility to generate documentation from Terraform modules in various output for ### SEE ALSO +* [terraform-docs asciidoc](/docs/formats/asciidoc.md) - Generate AsciiDoc of inputs and outputs + * [terraform-docs asciidoc document](/docs/formats/asciidoc-document.md) - Generate AsciiDoc document of inputs and outputs + * [terraform-docs asciidoc table](/docs/formats/asciidoc-table.md) - Generate AsciiDoc tables of inputs and outputs * [terraform-docs json](/docs/formats/json.md) - Generate JSON of inputs and outputs * [terraform-docs markdown](/docs/formats/markdown.md) - Generate Markdown of inputs and outputs * [terraform-docs markdown document](/docs/formats/markdown-document.md) - Generate Markdown document of inputs and outputs @@ -37,4 +40,4 @@ A utility to generate documentation from Terraform modules in various output for * [terraform-docs xml](/docs/formats/xml.md) - Generate XML of inputs and outputs * [terraform-docs yaml](/docs/formats/yaml.md) - Generate YAML of inputs and outputs -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/asciidoc-document.md b/docs/formats/asciidoc-document.md new file mode 100644 index 0000000..5a887a4 --- /dev/null +++ b/docs/formats/asciidoc-document.md @@ -0,0 +1,424 @@ +## terraform-docs asciidoc document + +Generate AsciiDoc document of inputs and outputs + +### Synopsis + +Generate AsciiDoc document of inputs and outputs + +``` +terraform-docs asciidoc document [PATH] [flags] +``` + +### Options + +``` + -h, --help help for document +``` + +### Options inherited from parent commands + +``` + --header-from string relative path of a file to read header from (default "main.tf") + --indent int indention level of AsciiDoc sections [1, 2, 3, 4, 5] (default 2) + --no-header do not show module header + --no-inputs do not show inputs + --no-outputs do not show outputs + --no-providers do not show providers + --no-required do not show "Required" column or section + --no-requirements do not show module requirements + --no-sensitive do not show "Sensitive" column or section + --no-sort do no sort items + --output-values inject output values into outputs + --output-values-from string inject output values from file into outputs + --sort-by-required sort items by name and print required ones first + --sort-inputs-by-required [deprecated] use '--sort-by-required' instead + --with-aggregate-type-defaults [deprecated] print default values of aggregate types +``` + +### Example + +Given the [`examples`](/examples/) module: + +```shell +terraform-docs asciidoc document ./examples/ +``` + +generates the following output: + + Usage: + + Example of 'foo_bar' module in `foo_bar.tf`. + + - list item 1 + - list item 2 + + Even inline **formatting** in _here_ is possible. + and some [link](https://domain.com/) + + * list item 3 + * list item 4 + + ```hcl + module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } + } + ``` + + Here is some trailing text after code block, + followed by another line of text. + + | Name | Description | + |------|-----------------| + | Foo | Foo description | + | Bar | Bar description | + + == Requirements + + The following requirements are needed by this module: + + - terraform (>= 0.12) + + - aws (>= 2.15.0) + + - random (>= 2.2.0) + + == Providers + + The following providers are used by this module: + + - aws (>= 2.15.0) + + - aws.ident (>= 2.15.0) + + - null + + - tls + + == Required Inputs + + The following input variables are required: + + === input_with_underscores + + Description: A variable with underscores. + + Type: `any` + + === list-2 + + Description: It's list number two. + + Type: `list` + + === map-2 + + Description: It's map number two. + + Type: `map` + + === number-2 + + Description: It's number number two. + + Type: `number` + + === string-2 + + Description: It's string number two. + + Type: `string` + + === string_no_default + + Description: n/a + + Type: `string` + + === unquoted + + Description: n/a + + Type: `any` + + == Optional Inputs + + The following input variables are optional (have default values): + + === bool-1 + + Description: It's bool number one. + + Type: `bool` + + Default: `true` + + === bool-2 + + Description: It's bool number two. + + Type: `bool` + + Default: `false` + + === bool-3 + + Description: n/a + + Type: `bool` + + Default: `true` + + === bool_default_false + + Description: n/a + + Type: `bool` + + Default: `false` + + === input-with-code-block + + Description: This is a complicated one. We need a newline. + And an example in a code block + ``` + default = [ + "machine rack01:neptune" + ] + ``` + + Type: `list` + + Default: + [source,json] + ---- + [ + "name rack:location" + ] + ---- + + === input-with-pipe + + Description: It includes v1 \| v2 \| v3 + + Type: `string` + + Default: `"v1"` + + === list-1 + + Description: It's list number one. + + Type: `list` + + Default: + [source,json] + ---- + [ + "a", + "b", + "c" + ] + ---- + + === list-3 + + Description: n/a + + Type: `list` + + Default: `[]` + + === list_default_empty + + Description: n/a + + Type: `list(string)` + + Default: `[]` + + === long_type + + Description: This description is itself markdown. + + It spans over multiple lines. + + Type: + [source,hcl] + ---- + object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) + ---- + + Default: + [source,json] + ---- + { + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" + } + ---- + + === map-1 + + Description: It's map number one. + + Type: `map` + + Default: + [source,json] + ---- + { + "a": 1, + "b": 2, + "c": 3 + } + ---- + + === map-3 + + Description: n/a + + Type: `map` + + Default: `{}` + + === no-escape-default-value + + Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + + Type: `string` + + Default: `"VALUE_WITH_UNDERSCORE"` + + === number-1 + + Description: It's number number one. + + Type: `number` + + Default: `42` + + === number-3 + + Description: n/a + + Type: `number` + + Default: `"19"` + + === number-4 + + Description: n/a + + Type: `number` + + Default: `15.75` + + === number_default_zero + + Description: n/a + + Type: `number` + + Default: `0` + + === object_default_empty + + Description: n/a + + Type: `object({})` + + Default: `{}` + + === string-1 + + Description: It's string number one. + + Type: `string` + + Default: `"bar"` + + === string-3 + + Description: n/a + + Type: `string` + + Default: `""` + + === string_default_empty + + Description: n/a + + Type: `string` + + Default: `""` + + === string_default_null + + Description: n/a + + Type: `string` + + Default: `null` + + === with-url + + Description: The description contains url. https://www.domain.com/foo/bar_baz.html + + Type: `string` + + Default: `""` + + == Outputs + + The following outputs are exported: + + === output-0.12 + + Description: terraform 0.12 only + + === output-1 + + Description: It's output number one. + + === output-2 + + Description: It's output number two. + + === unquoted + + Description: It's unquoted output. + + + +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/asciidoc-table.md b/docs/formats/asciidoc-table.md new file mode 100644 index 0000000..4a23fb3 --- /dev/null +++ b/docs/formats/asciidoc-table.md @@ -0,0 +1,380 @@ +## terraform-docs asciidoc table + +Generate AsciiDoc tables of inputs and outputs + +### Synopsis + +Generate AsciiDoc tables of inputs and outputs + +``` +terraform-docs asciidoc table [PATH] [flags] +``` + +### Options + +``` + -h, --help help for table +``` + +### Options inherited from parent commands + +``` + --header-from string relative path of a file to read header from (default "main.tf") + --indent int indention level of AsciiDoc sections [1, 2, 3, 4, 5] (default 2) + --no-header do not show module header + --no-inputs do not show inputs + --no-outputs do not show outputs + --no-providers do not show providers + --no-required do not show "Required" column or section + --no-requirements do not show module requirements + --no-sensitive do not show "Sensitive" column or section + --no-sort do no sort items + --output-values inject output values into outputs + --output-values-from string inject output values from file into outputs + --sort-by-required sort items by name and print required ones first + --sort-inputs-by-required [deprecated] use '--sort-by-required' instead + --with-aggregate-type-defaults [deprecated] print default values of aggregate types +``` + +### Example + +Given the [`examples`](/examples/) module: + +```shell +terraform-docs asciidoc table ./examples/ +``` + +generates the following output: + + Usage: + + Example of 'foo_bar' module in `foo_bar.tf`. + + - list item 1 + - list item 2 + + Even inline **formatting** in _here_ is possible. + and some [link](https://domain.com/) + + * list item 3 + * list item 4 + + ```hcl + module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } + } + ``` + + Here is some trailing text after code block, + followed by another line of text. + + | Name | Description | + |------|-----------------| + | Foo | Foo description | + | Bar | Bar description | + + == Requirements + + [cols="a,a",options="header,autowidth"] + |=== + |Name |Version + |terraform |>= 0.12 + |aws |>= 2.15.0 + |random |>= 2.2.0 + |=== + + == Providers + + [cols="a,a",options="header,autowidth"] + |=== + |Name |Version + |aws |>= 2.15.0 + |aws.ident |>= 2.15.0 + |null |n/a + |tls |n/a + |=== + + == Inputs + + [cols="a,a,a,a,a",options="header,autowidth"] + |=== + |Name |Description |Type |Default |Required + |bool-1 + |It's bool number one. + |`bool` + |`true` + |no + + |bool-2 + |It's bool number two. + |`bool` + |`false` + |no + + |bool-3 + |n/a + |`bool` + |`true` + |no + + |bool_default_false + |n/a + |`bool` + |`false` + |no + + |input-with-code-block + |This is a complicated one. We need a newline. + And an example in a code block + [source] + ---- + default = [ + "machine rack01:neptune" + ] + ---- + + |`list` + | + + [source] + ---- + [ + "name rack:location" + ] + ---- + + |no + + |input-with-pipe + |It includes v1 \| v2 \| v3 + |`string` + |`"v1"` + |no + + |input_with_underscores + |A variable with underscores. + |`any` + |n/a + |yes + + |list-1 + |It's list number one. + |`list` + | + + [source] + ---- + [ + "a", + "b", + "c" + ] + ---- + + |no + + |list-2 + |It's list number two. + |`list` + |n/a + |yes + + |list-3 + |n/a + |`list` + |`[]` + |no + + |list_default_empty + |n/a + |`list(string)` + |`[]` + |no + + |long_type + |This description is itself markdown. + + It spans over multiple lines. + + | + + [source] + ---- + object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) + ---- + + | + + [source] + ---- + { + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" + } + ---- + + |no + + |map-1 + |It's map number one. + |`map` + | + + [source] + ---- + { + "a": 1, + "b": 2, + "c": 3 + } + ---- + + |no + + |map-2 + |It's map number two. + |`map` + |n/a + |yes + + |map-3 + |n/a + |`map` + |`{}` + |no + + |no-escape-default-value + |The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + |`string` + |`"VALUE_WITH_UNDERSCORE"` + |no + + |number-1 + |It's number number one. + |`number` + |`42` + |no + + |number-2 + |It's number number two. + |`number` + |n/a + |yes + + |number-3 + |n/a + |`number` + |`"19"` + |no + + |number-4 + |n/a + |`number` + |`15.75` + |no + + |number_default_zero + |n/a + |`number` + |`0` + |no + + |object_default_empty + |n/a + |`object({})` + |`{}` + |no + + |string-1 + |It's string number one. + |`string` + |`"bar"` + |no + + |string-2 + |It's string number two. + |`string` + |n/a + |yes + + |string-3 + |n/a + |`string` + |`""` + |no + + |string_default_empty + |n/a + |`string` + |`""` + |no + + |string_default_null + |n/a + |`string` + |`null` + |no + + |string_no_default + |n/a + |`string` + |n/a + |yes + + |unquoted + |n/a + |`any` + |n/a + |yes + + |with-url + |The description contains url. https://www.domain.com/foo/bar_baz.html + |`string` + |`""` + |no + + |=== + + == Outputs + + [cols="a,a",options="header,autowidth"] + |=== + |Name |Description + |output-0.12 |terraform 0.12 only + |output-1 |It's output number one. + |output-2 |It's output number two. + |unquoted |It's unquoted output. + |=== + + + +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/asciidoc.md b/docs/formats/asciidoc.md new file mode 100644 index 0000000..e56aac5 --- /dev/null +++ b/docs/formats/asciidoc.md @@ -0,0 +1,44 @@ +## terraform-docs asciidoc + +Generate AsciiDoc of inputs and outputs + +### Synopsis + +Generate AsciiDoc of inputs and outputs + +``` +terraform-docs asciidoc [PATH] [flags] +``` + +### Options + +``` + -h, --help help for asciidoc + --indent int indention level of AsciiDoc sections [1, 2, 3, 4, 5] (default 2) + --no-required do not show "Required" column or section + --no-sensitive do not show "Sensitive" column or section +``` + +### Options inherited from parent commands + +``` + --header-from string relative path of a file to read header from (default "main.tf") + --no-header do not show module header + --no-inputs do not show inputs + --no-outputs do not show outputs + --no-providers do not show providers + --no-requirements do not show module requirements + --no-sort do no sort items + --output-values inject output values into outputs + --output-values-from string inject output values from file into outputs + --sort-by-required sort items by name and print required ones first + --sort-inputs-by-required [deprecated] use '--sort-by-required' instead + --with-aggregate-type-defaults [deprecated] print default values of aggregate types +``` + +### SEE ALSO + +* [terraform-docs asciidoc document](/docs/formats/asciidoc-document.md) - Generate AsciiDoc document of inputs and outputs +* [terraform-docs asciidoc table](/docs/formats/asciidoc-table.md) - Generate AsciiDoc tables of inputs and outputs + +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/json.md b/docs/formats/json.md index a1c5167..bb7ef85 100644 --- a/docs/formats/json.md +++ b/docs/formats/json.md @@ -340,4 +340,4 @@ generates the following output: } -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/markdown-document.md b/docs/formats/markdown-document.md index dc284d6..f869704 100644 --- a/docs/formats/markdown-document.md +++ b/docs/formats/markdown-document.md @@ -422,4 +422,4 @@ generates the following output: -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/markdown-table.md b/docs/formats/markdown-table.md index bcc815c..0aca591 100644 --- a/docs/formats/markdown-table.md +++ b/docs/formats/markdown-table.md @@ -148,4 +148,4 @@ generates the following output: -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/markdown.md b/docs/formats/markdown.md index 20f600a..4f9ee95 100644 --- a/docs/formats/markdown.md +++ b/docs/formats/markdown.md @@ -42,4 +42,4 @@ terraform-docs markdown [PATH] [flags] * [terraform-docs markdown document](/docs/formats/markdown-document.md) - Generate Markdown document of inputs and outputs * [terraform-docs markdown table](/docs/formats/markdown-table.md) - Generate Markdown tables of inputs and outputs -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/pretty.md b/docs/formats/pretty.md index 0a8b261..d12c6ec 100644 --- a/docs/formats/pretty.md +++ b/docs/formats/pretty.md @@ -244,4 +244,4 @@ generates the following output: -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/tfvars-hcl.md b/docs/formats/tfvars-hcl.md index ad5529c..0587b0a 100644 --- a/docs/formats/tfvars-hcl.md +++ b/docs/formats/tfvars-hcl.md @@ -100,4 +100,4 @@ generates the following output: with-url = "" -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/tfvars-json.md b/docs/formats/tfvars-json.md index 40babf3..9397e90 100644 --- a/docs/formats/tfvars-json.md +++ b/docs/formats/tfvars-json.md @@ -102,4 +102,4 @@ generates the following output: } -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/tfvars.md b/docs/formats/tfvars.md index b6e6e27..1e1e713 100644 --- a/docs/formats/tfvars.md +++ b/docs/formats/tfvars.md @@ -34,4 +34,4 @@ Generate terraform.tfvars of inputs * [terraform-docs tfvars hcl](/docs/formats/tfvars-hcl.md) - Generate HCL format of terraform.tfvars of inputs * [terraform-docs tfvars json](/docs/formats/tfvars-json.md) - Generate JSON format of terraform.tfvars of inputs -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/xml.md b/docs/formats/xml.md index ffbb72f..2a10b9a 100644 --- a/docs/formats/xml.md +++ b/docs/formats/xml.md @@ -339,4 +339,4 @@ generates the following output: -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/docs/formats/yaml.md b/docs/formats/yaml.md index 60a1f02..6c81c87 100644 --- a/docs/formats/yaml.md +++ b/docs/formats/yaml.md @@ -292,4 +292,4 @@ generates the following output: version: '>= 2.2.0' -###### Auto generated by spf13/cobra on 10-Apr-2020 +###### Auto generated by spf13/cobra on 12-Apr-2020 diff --git a/internal/format/asciidoc_document.go b/internal/format/asciidoc_document.go new file mode 100644 index 0000000..74aa5ad --- /dev/null +++ b/internal/format/asciidoc_document.go @@ -0,0 +1,199 @@ +package format + +import ( + "text/template" + + "github.com/segmentio/terraform-docs/pkg/print" + "github.com/segmentio/terraform-docs/pkg/tfconf" + "github.com/segmentio/terraform-docs/pkg/tmpl" +) + +const ( + asciidocDocumentHeaderTpl = ` + {{- if .Settings.ShowHeader -}} + {{- with .Module.Header -}} + {{ sanitizeHeader . }} + {{ printf "\n" }} + {{- end -}} + {{ end -}} + ` + + asciidocDocumentRequirementsTpl = ` + {{- if .Settings.ShowRequirements -}} + {{ indent 0 "=" }} Requirements + {{ if not .Module.Requirements }} + No requirements. + {{ else }} + The following requirements are needed by this module: + {{- range .Module.Requirements }} + {{ $version := ternary (tostring .Version) (printf " (%s)" .Version) "" }} + - {{ name .Name }}{{ $version }} + {{- end }} + {{ end }} + {{ end -}} + ` + + asciidocDocumentProvidersTpl = ` + {{- if .Settings.ShowProviders -}} + {{ indent 0 "=" }} Providers + {{ if not .Module.Providers }} + No provider. + {{ else }} + The following providers are used by this module: + {{- range .Module.Providers }} + {{ $version := ternary (tostring .Version) (printf " (%s)" .Version) "" }} + - {{ name .FullName }}{{ $version }} + {{- end }} + {{ end }} + {{ end -}} + ` + + asciidocDocumentInputsTpl = ` + {{- if .Settings.ShowInputs -}} + {{- if .Settings.ShowRequired -}} + {{ indent 0 "=" }} Required Inputs + {{ if not .Module.RequiredInputs }} + No required input. + {{ else }} + The following input variables are required: + {{- range .Module.RequiredInputs }} + {{ template "input" . }} + {{- end }} + {{- end }} + {{ indent 0 "=" }} Optional Inputs + {{ if not .Module.OptionalInputs }} + No optional input. + {{ else }} + The following input variables are optional (have default values): + {{- range .Module.OptionalInputs }} + {{ template "input" . }} + {{- end }} + {{ end }} + {{ else -}} + {{ indent 0 "=" }} Inputs + {{ if not .Module.Inputs }} + No input. + {{ else }} + The following input variables are supported: + {{- range .Module.Inputs }} + {{ template "input" . }} + {{- end }} + {{ end }} + {{- end }} + {{ end -}} + ` + + asciidocDocumentInputTpl = ` + {{ printf "\n" }} + {{ indent 1 "=" }} {{ name .Name }} + + Description: {{ tostring .Description | sanitizeDoc }} + + Type: {{ tostring .Type | type }} + + {{ if or .HasDefault (not isRequired) }} + Default: {{ default "n/a" .GetValue | value }} + {{- end }} + ` + + asciidocDocumentOutputsTpl = ` + {{- if .Settings.ShowOutputs -}} + {{ indent 0 "=" }} Outputs + {{ if not .Module.Outputs }} + No output. + {{ else }} + The following outputs are exported: + {{- range .Module.Outputs }} + + {{ indent 1 "=" }} {{ name .Name }} + + Description: {{ tostring .Description | sanitizeDoc }} + + {{ if $.Settings.OutputValues }} + {{- $sensitive := ternary .Sensitive "" .GetValue -}} + Value: {{ value $sensitive | sanitizeDoc }} + + {{ if $.Settings.ShowSensitivity -}} + Sensitive: {{ ternary (.Sensitive) "yes" "no" }} + {{- end }} + {{ end }} + {{ end }} + {{ end }} + {{ end -}} + ` + + asciidocDocumentTpl = ` + {{- template "header" . -}} + {{- template "requirements" . -}} + {{- template "providers" . -}} + {{- template "inputs" . -}} + {{- template "outputs" . -}} + ` +) + +// AsciidocDocument represents AsciiDoc Document format. +type AsciidocDocument struct { + template *tmpl.Template +} + +// NewAsciidocDocument returns new instance of AsciidocDocument. +func NewAsciidocDocument(settings *print.Settings) *AsciidocDocument { + tt := tmpl.NewTemplate(&tmpl.Item{ + Name: "document", + Text: asciidocDocumentTpl, + }, &tmpl.Item{ + Name: "header", + Text: asciidocDocumentHeaderTpl, + }, &tmpl.Item{ + Name: "requirements", + Text: asciidocDocumentRequirementsTpl, + }, &tmpl.Item{ + Name: "providers", + Text: asciidocDocumentProvidersTpl, + }, &tmpl.Item{ + Name: "inputs", + Text: asciidocDocumentInputsTpl, + }, &tmpl.Item{ + Name: "input", + Text: asciidocDocumentInputTpl, + }, &tmpl.Item{ + Name: "outputs", + Text: asciidocDocumentOutputsTpl, + }) + settings.EscapeCharacters = false + tt.Settings(settings) + tt.CustomFunc(template.FuncMap{ + "type": func(t string) string { + result, extraline := printFencedAsciidocCodeBlock(t, "hcl") + if !extraline { + result += "\n" + } + return result + }, + "value": func(v string) string { + if v == "n/a" { + return v + } + result, extraline := printFencedAsciidocCodeBlock(v, "json") + if !extraline { + result += "\n" + } + return result + }, + "isRequired": func() bool { + return settings.ShowRequired + }, + }) + return &AsciidocDocument{ + template: tt, + } +} + +// Print prints a Terraform module as AsciiDoc document. +func (d *AsciidocDocument) Print(module *tfconf.Module, settings *print.Settings) (string, error) { + rendered, err := d.template.Render(module) + if err != nil { + return "", err + } + return sanitize(rendered), nil +} diff --git a/internal/format/asciidoc_document_test.go b/internal/format/asciidoc_document_test.go new file mode 100644 index 0000000..b671cd5 --- /dev/null +++ b/internal/format/asciidoc_document_test.go @@ -0,0 +1,501 @@ +package format + +import ( + "testing" + + "github.com/segmentio/terraform-docs/internal/module" + "github.com/segmentio/terraform-docs/internal/testutil" + "github.com/segmentio/terraform-docs/pkg/print" + "github.com/stretchr/testify/assert" +) + +func TestAsciidocDocument(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().Build() + + expected, err := testutil.GetExpected("asciidoc", "document") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentWithRequired(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + ShowRequired: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-WithRequired") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentSortByName(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + SortByName: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-SortByName") + assert.Nil(err) + + options, err := module.NewOptions().With(&module.Options{ + SortBy: &module.SortBy{ + Name: true, + }, + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentSortByRequired(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + SortByName: true, + SortByRequired: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-SortByRequired") + assert.Nil(err) + + options, err := module.NewOptions().With(&module.Options{ + SortBy: &module.SortBy{ + Name: true, + Required: true, + }, + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentNoHeader(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: true, + ShowOutputs: true, + ShowProviders: true, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-NoHeader") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentNoInputs(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: false, + ShowOutputs: true, + ShowProviders: true, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-NoInputs") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentNoOutputs(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: true, + ShowOutputs: false, + ShowProviders: true, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-NoOutputs") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentNoProviders(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: true, + ShowOutputs: true, + ShowProviders: false, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-NoProviders") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentNoRequirements(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: true, + ShowOutputs: true, + ShowProviders: true, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-NoRequirements") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentOnlyHeader(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: false, + ShowOutputs: false, + ShowProviders: false, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-OnlyHeader") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentOnlyInputs(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: true, + ShowOutputs: false, + ShowProviders: false, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-OnlyInputs") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentOnlyOutputs(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: false, + ShowOutputs: true, + ShowProviders: false, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-OnlyOutputs") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentOnlyProviders(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: false, + ShowOutputs: false, + ShowProviders: true, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-OnlyProviders") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentOnlyRequirements(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: false, + ShowOutputs: false, + ShowProviders: false, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-OnlyRequirements") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentIndentationBelowAllowed(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + IndentLevel: 0, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-IndentationBelowAllowed") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentIndentationAboveAllowed(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + IndentLevel: 10, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-IndentationAboveAllowed") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentIndentationOfFour(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + IndentLevel: 4, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-IndentationOfFour") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentOutputValues(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + OutputValues: true, + ShowSensitivity: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-OutputValues") + assert.Nil(err) + + options, err := module.NewOptions().With(&module.Options{ + OutputValues: true, + OutputValuesPath: "output_values.json", + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentHeaderFromFile(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().Build() + + expected, err := testutil.GetExpected("asciidoc", "document-HeaderFromFile") + assert.Nil(err) + + options, err := module.NewOptions().WithOverwrite(&module.Options{ + HeaderFromFile: "doc.tf", + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentOutputValuesNoSensitivity(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + OutputValues: true, + ShowSensitivity: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "document-OutputValuesNoSensitivity") + assert.Nil(err) + + options, err := module.NewOptions().With(&module.Options{ + OutputValues: true, + OutputValuesPath: "output_values.json", + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocDocumentEmpty(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowProviders: false, + ShowInputs: false, + ShowOutputs: false, + }).Build() + + options, err := module.NewOptions().WithOverwrite(&module.Options{ + HeaderFromFile: "bad.tf", + }) + options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocDocument(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal("", actual) +} diff --git a/internal/format/asciidoc_table.go b/internal/format/asciidoc_table.go new file mode 100644 index 0000000..8488448 --- /dev/null +++ b/internal/format/asciidoc_table.go @@ -0,0 +1,162 @@ +package format + +import ( + "text/template" + + "github.com/segmentio/terraform-docs/pkg/print" + "github.com/segmentio/terraform-docs/pkg/tfconf" + "github.com/segmentio/terraform-docs/pkg/tmpl" +) + +const ( + asciidocTableHeaderTpl = ` + {{- if .Settings.ShowHeader -}} + {{- with .Module.Header -}} + {{ sanitizeHeader . }} + {{ printf "\n" }} + {{- end -}} + {{ end -}} + ` + + asciidocTableRequirementsTpl = ` + {{- if .Settings.ShowRequirements -}} + {{ indent 0 "=" }} Requirements + {{ if not .Module.Requirements }} + No requirements. + {{ else }} + [cols="a,a",options="header,autowidth"] + |=== + |Name |Version + {{- range .Module.Requirements }} + |{{ .Name }} |{{ tostring .Version | default "n/a" }} + {{- end }} + |=== + {{ end }} + {{ end -}} + ` + + asciidocTableProvidersTpl = ` + {{- if .Settings.ShowProviders -}} + {{ indent 0 "=" }} Providers + {{ if not .Module.Providers }} + No provider. + {{ else }} + [cols="a,a",options="header,autowidth"] + |=== + |Name |Version + {{- range .Module.Providers }} + |{{ .FullName }} |{{ tostring .Version | default "n/a" }} + {{- end }} + |=== + {{ end }} + {{ end -}} + ` + + asciidocTableInputsTpl = ` + {{- if .Settings.ShowInputs -}} + {{ indent 0 "=" }} Inputs + {{ if not .Module.Inputs }} + No input. + {{ else }} + [cols="a,a,a,a{{ if .Settings.ShowRequired }},a{{ end }}",options="header,autowidth"] + |=== + |Name |Description |Type |Default{{ if .Settings.ShowRequired }} |Required{{ end }} + {{- range .Module.Inputs }} + |{{ .Name }} + |{{ tostring .Description | sanitizeAsciidocTbl }} + |{{ tostring .Type | type | sanitizeAsciidocTbl }} + |{{ value .GetValue | sanitizeAsciidocTbl }} + {{ if $.Settings.ShowRequired }}|{{ ternary .Required "yes" "no" }}{{ end }} + {{ end }} + |=== + {{ end }} + {{ end -}} + ` + + asciidocTableOutputsTpl = ` + {{- if .Settings.ShowOutputs -}} + {{ indent 0 "=" }} Outputs + {{ if not .Module.Outputs }} + No output. + {{ else }} + [cols="a,a{{ if .Settings.OutputValues }},a{{ if $.Settings.ShowSensitivity }},a{{ end }}{{ end }}",options="header,autowidth"] + |=== + |Name |Description{{ if .Settings.OutputValues }} |Value{{ if $.Settings.ShowSensitivity }} |Sensitive{{ end }}{{ end }} + {{- range .Module.Outputs }} + |{{ .Name }} |{{ tostring .Description | sanitizeAsciidocTbl }} + {{- if $.Settings.OutputValues -}} + {{- $sensitive := ternary .Sensitive "" .GetValue -}} + {{ printf " " }}|{{ value $sensitive }} + {{- if $.Settings.ShowSensitivity -}} + {{ printf " " }}|{{ ternary .Sensitive "yes" "no" }} + {{- end -}} + {{- end -}} + {{- end }} + |=== + {{ end }} + {{ end -}} + ` + + asciidocTableTpl = ` + {{- template "header" . -}} + {{- template "requirements" . -}} + {{- template "providers" . -}} + {{- template "inputs" . -}} + {{- template "outputs" . -}} + ` +) + +// AsciidocTable represents AsciiDoc Table format. +type AsciidocTable struct { + template *tmpl.Template +} + +// NewAsciidocTable returns new instance of AsciidocTable. +func NewAsciidocTable(settings *print.Settings) *AsciidocTable { + tt := tmpl.NewTemplate(&tmpl.Item{ + Name: "table", + Text: asciidocTableTpl, + }, &tmpl.Item{ + Name: "header", + Text: asciidocTableHeaderTpl, + }, &tmpl.Item{ + Name: "requirements", + Text: asciidocTableRequirementsTpl, + }, &tmpl.Item{ + Name: "providers", + Text: asciidocTableProvidersTpl, + }, &tmpl.Item{ + Name: "inputs", + Text: asciidocTableInputsTpl, + }, &tmpl.Item{ + Name: "outputs", + Text: asciidocTableOutputsTpl, + }) + settings.EscapeCharacters = false + tt.Settings(settings) + tt.CustomFunc(template.FuncMap{ + "type": func(t string) string { + inputType, _ := printFencedCodeBlock(t, "") + return inputType + }, + "value": func(v string) string { + var result = "n/a" + if v != "" { + result, _ = printFencedCodeBlock(v, "") + } + return result + }, + }) + return &AsciidocTable{ + template: tt, + } +} + +// Print prints a Terraform module as AsciiDoc tables. +func (t *AsciidocTable) Print(module *tfconf.Module, settings *print.Settings) (string, error) { + rendered, err := t.template.Render(module) + if err != nil { + return "", err + } + return sanitize(rendered), nil +} diff --git a/internal/format/asciidoc_table_test.go b/internal/format/asciidoc_table_test.go new file mode 100644 index 0000000..2cb8043 --- /dev/null +++ b/internal/format/asciidoc_table_test.go @@ -0,0 +1,501 @@ +package format + +import ( + "testing" + + "github.com/segmentio/terraform-docs/internal/module" + "github.com/segmentio/terraform-docs/internal/testutil" + "github.com/segmentio/terraform-docs/pkg/print" + "github.com/stretchr/testify/assert" +) + +func TestAsciidocTable(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().Build() + + expected, err := testutil.GetExpected("asciidoc", "table") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableWithRequired(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + ShowRequired: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-WithRequired") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableSortByName(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + SortByName: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-SortByName") + assert.Nil(err) + + options, err := module.NewOptions().With(&module.Options{ + SortBy: &module.SortBy{ + Name: true, + }, + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableSortByRequired(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + SortByName: true, + SortByRequired: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-SortByRequired") + assert.Nil(err) + + options, err := module.NewOptions().With(&module.Options{ + SortBy: &module.SortBy{ + Name: true, + Required: true, + }, + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableNoHeader(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: true, + ShowOutputs: true, + ShowProviders: true, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-NoHeader") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableNoInputs(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: false, + ShowOutputs: true, + ShowProviders: true, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-NoInputs") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableNoOutputs(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: true, + ShowOutputs: false, + ShowProviders: true, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-NoOutputs") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableNoProviders(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: true, + ShowOutputs: true, + ShowProviders: false, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-NoProviders") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableNoRequirements(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: true, + ShowOutputs: true, + ShowProviders: true, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-NoRequirements") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableOnlyHeader(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: true, + ShowInputs: false, + ShowOutputs: false, + ShowProviders: false, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-OnlyHeader") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableOnlyInputs(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: true, + ShowOutputs: false, + ShowProviders: false, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-OnlyInputs") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableOnlyOutputs(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: false, + ShowOutputs: true, + ShowProviders: false, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-OnlyOutputs") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableOnlyProviders(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: false, + ShowOutputs: false, + ShowProviders: true, + ShowRequirements: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-OnlyProviders") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableOnlyRequirements(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowInputs: false, + ShowOutputs: false, + ShowProviders: false, + ShowRequirements: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-OnlyRequirements") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableIndentationBelowAllowed(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + IndentLevel: 0, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-IndentationBelowAllowed") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableIndentationAboveAllowed(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + IndentLevel: 10, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-IndentationAboveAllowed") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableIndentationOfFour(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + IndentLevel: 4, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-IndentationOfFour") + assert.Nil(err) + + options := module.NewOptions() + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableOutputValues(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + OutputValues: true, + ShowSensitivity: true, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-OutputValues") + assert.Nil(err) + + options, err := module.NewOptions().With(&module.Options{ + OutputValues: true, + OutputValuesPath: "output_values.json", + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableHeaderFromFile(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().Build() + + expected, err := testutil.GetExpected("asciidoc", "table-HeaderFromFile") + assert.Nil(err) + + options, err := module.NewOptions().WithOverwrite(&module.Options{ + HeaderFromFile: "doc.tf", + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableOutputValuesNoSensitivity(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().WithSections().With(&print.Settings{ + OutputValues: true, + ShowSensitivity: false, + }).Build() + + expected, err := testutil.GetExpected("asciidoc", "table-OutputValuesNoSensitivity") + assert.Nil(err) + + options, err := module.NewOptions().With(&module.Options{ + OutputValues: true, + OutputValuesPath: "output_values.json", + }) + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal(expected, actual) +} + +func TestAsciidocTableEmpty(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + ShowHeader: false, + ShowProviders: false, + ShowInputs: false, + ShowOutputs: false, + }).Build() + + options, err := module.NewOptions().WithOverwrite(&module.Options{ + HeaderFromFile: "bad.tf", + }) + options.ShowHeader = false // Since we don't show the header, the file won't be loaded at all + assert.Nil(err) + + module, err := testutil.GetModule(options) + assert.Nil(err) + + printer := NewAsciidocTable(settings) + actual, err := printer.Print(module, settings) + + assert.Nil(err) + assert.Equal("", actual) +} diff --git a/internal/format/factory.go b/internal/format/factory.go index 736d4b4..4dbe53c 100644 --- a/internal/format/factory.go +++ b/internal/format/factory.go @@ -12,6 +12,12 @@ import ( // function. func Factory(name string, settings *print.Settings) (print.Format, error) { switch name { + case "asciidoc": + return NewAsciidocTable(settings), nil + case "asciidoc document": + return NewAsciidocDocument(settings), nil + case "asciidoc table": + return NewAsciidocTable(settings), nil case "json": return NewJSON(settings), nil case "markdown": diff --git a/internal/format/factory_test.go b/internal/format/factory_test.go index ceeabed..3416a72 100644 --- a/internal/format/factory_test.go +++ b/internal/format/factory_test.go @@ -15,6 +15,24 @@ func TestFormatFactory(t *testing.T) { expected string wantErr bool }{ + { + name: "format factory from name", + format: "asciidoc", + expected: "*format.AsciidocTable", + wantErr: false, + }, + { + name: "format factory from name", + format: "asciidoc document", + expected: "*format.AsciidocDocument", + wantErr: false, + }, + { + name: "format factory from name", + format: "asciidoc table", + expected: "*format.AsciidocTable", + wantErr: false, + }, { name: "format factory from name", format: "json", diff --git a/internal/format/markdown_document.go b/internal/format/markdown_document.go index 1a25b38..3b250d1 100644 --- a/internal/format/markdown_document.go +++ b/internal/format/markdown_document.go @@ -20,7 +20,7 @@ const ( documentRequirementsTpl = ` {{- if .Settings.ShowRequirements -}} - {{ indent 0 }} Requirements + {{ indent 0 "#" }} Requirements {{ if not .Module.Requirements }} No requirements. {{ else }} @@ -35,7 +35,7 @@ const ( documentProvidersTpl = ` {{- if .Settings.ShowProviders -}} - {{ indent 0 }} Providers + {{ indent 0 "#" }} Providers {{ if not .Module.Providers }} No provider. {{ else }} @@ -51,7 +51,7 @@ const ( documentInputsTpl = ` {{- if .Settings.ShowInputs -}} {{- if .Settings.ShowRequired -}} - {{ indent 0 }} Required Inputs + {{ indent 0 "#" }} Required Inputs {{ if not .Module.RequiredInputs }} No required input. {{ else }} @@ -60,7 +60,7 @@ const ( {{ template "input" . }} {{- end }} {{- end }} - {{ indent 0 }} Optional Inputs + {{ indent 0 "#" }} Optional Inputs {{ if not .Module.OptionalInputs }} No optional input. {{ else }} @@ -70,7 +70,7 @@ const ( {{- end }} {{ end }} {{ else -}} - {{ indent 0 }} Inputs + {{ indent 0 "#" }} Inputs {{ if not .Module.Inputs }} No input. {{ else }} @@ -85,7 +85,7 @@ const ( documentInputTpl = ` {{ printf "\n" }} - {{ indent 1 }} {{ name .Name }} + {{ indent 1 "#" }} {{ name .Name }} Description: {{ tostring .Description | sanitizeDoc }} @@ -98,14 +98,14 @@ const ( documentOutputsTpl = ` {{- if .Settings.ShowOutputs -}} - {{ indent 0 }} Outputs + {{ indent 0 "#" }} Outputs {{ if not .Module.Outputs }} No output. {{ else }} The following outputs are exported: {{- range .Module.Outputs }} - {{ indent 1 }} {{ name .Name }} + {{ indent 1 "#" }} {{ name .Name }} Description: {{ tostring .Description | sanitizeDoc }} diff --git a/internal/format/markdown_document_test.go b/internal/format/markdown_document_test.go index b098ecd..6d519d0 100644 --- a/internal/format/markdown_document_test.go +++ b/internal/format/markdown_document_test.go @@ -364,7 +364,7 @@ func TestDocumentEscapeCharacters(t *testing.T) { func TestDocumentIndentationBelowAllowed(t *testing.T) { assert := assert.New(t) settings := testutil.Settings().WithSections().With(&print.Settings{ - MarkdownIndent: 0, + IndentLevel: 0, }).Build() expected, err := testutil.GetExpected("markdown", "document-IndentationBelowAllowed") @@ -384,7 +384,7 @@ func TestDocumentIndentationBelowAllowed(t *testing.T) { func TestDocumentIndentationAboveAllowed(t *testing.T) { assert := assert.New(t) settings := testutil.Settings().WithSections().With(&print.Settings{ - MarkdownIndent: 10, + IndentLevel: 10, }).Build() expected, err := testutil.GetExpected("markdown", "document-IndentationAboveAllowed") @@ -404,7 +404,7 @@ func TestDocumentIndentationAboveAllowed(t *testing.T) { func TestDocumentIndentationOfFour(t *testing.T) { assert := assert.New(t) settings := testutil.Settings().WithSections().With(&print.Settings{ - MarkdownIndent: 4, + IndentLevel: 4, }).Build() expected, err := testutil.GetExpected("markdown", "document-IndentationOfFour") diff --git a/internal/format/markdown_table.go b/internal/format/markdown_table.go index f304ae2..33eb027 100644 --- a/internal/format/markdown_table.go +++ b/internal/format/markdown_table.go @@ -20,7 +20,7 @@ const ( tableRequirementsTpl = ` {{- if .Settings.ShowRequirements -}} - {{ indent 0 }} Requirements + {{ indent 0 "#" }} Requirements {{ if not .Module.Requirements }} No requirements. {{ else }} @@ -35,7 +35,7 @@ const ( tableProvidersTpl = ` {{- if .Settings.ShowProviders -}} - {{ indent 0 }} Providers + {{ indent 0 "#" }} Providers {{ if not .Module.Providers }} No provider. {{ else }} @@ -50,7 +50,7 @@ const ( tableInputsTpl = ` {{- if .Settings.ShowInputs -}} - {{ indent 0 }} Inputs + {{ indent 0 "#" }} Inputs {{ if not .Module.Inputs }} No input. {{ else }} @@ -68,7 +68,7 @@ const ( tableOutputsTpl = ` {{- if .Settings.ShowOutputs -}} - {{ indent 0 }} Outputs + {{ indent 0 "#" }} Outputs {{ if not .Module.Outputs }} No output. {{ else }} @@ -79,7 +79,7 @@ const ( {{- if $.Settings.OutputValues -}} {{- $sensitive := ternary .Sensitive "" .GetValue -}} {{ printf " " }}{{ value $sensitive | sanitizeTbl }} | - {{- if $.Settings.ShowSensitivity -}} + {{- if $.Settings.ShowSensitivity -}} {{ printf " " }}{{ ternary .Sensitive "yes" "no" }} | {{- end -}} {{- end -}} diff --git a/internal/format/markdown_table_test.go b/internal/format/markdown_table_test.go index 2a8c770..20e6f88 100644 --- a/internal/format/markdown_table_test.go +++ b/internal/format/markdown_table_test.go @@ -364,7 +364,7 @@ func TestTableEscapeCharacters(t *testing.T) { func TestTableIndentationBelowAllowed(t *testing.T) { assert := assert.New(t) settings := testutil.Settings().WithSections().With(&print.Settings{ - MarkdownIndent: 0, + IndentLevel: 0, }).Build() expected, err := testutil.GetExpected("markdown", "table-IndentationBelowAllowed") @@ -384,7 +384,7 @@ func TestTableIndentationBelowAllowed(t *testing.T) { func TestTableIndentationAboveAllowed(t *testing.T) { assert := assert.New(t) settings := testutil.Settings().WithSections().With(&print.Settings{ - MarkdownIndent: 10, + IndentLevel: 10, }).Build() expected, err := testutil.GetExpected("markdown", "table-IndentationAboveAllowed") @@ -404,7 +404,7 @@ func TestTableIndentationAboveAllowed(t *testing.T) { func TestTableIndentationOfFour(t *testing.T) { assert := assert.New(t) settings := testutil.Settings().WithSections().With(&print.Settings{ - MarkdownIndent: 4, + IndentLevel: 4, }).Build() expected, err := testutil.GetExpected("markdown", "table-IndentationOfFour") diff --git a/internal/format/testdata/asciidoc/document-HeaderFromFile.golden b/internal/format/testdata/asciidoc/document-HeaderFromFile.golden new file mode 100644 index 0000000..0fc7f8b --- /dev/null +++ b/internal/format/testdata/asciidoc/document-HeaderFromFile.golden @@ -0,0 +1,353 @@ +This header comes from a custom file + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna +aliqua. Ut enim ad minim veniam, quis nostrud exercitation +ullamco laboris nisi ut aliquip ex ea commodo consequat. +Duis aute irure dolor in reprehenderit in voluptate velit +esse cillum dolore eu fugiat nulla pariatur. + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document-IndentationAboveAllowed.golden b/internal/format/testdata/asciidoc/document-IndentationAboveAllowed.golden new file mode 100644 index 0000000..ed5fae5 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-IndentationAboveAllowed.golden @@ -0,0 +1,382 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document-IndentationBelowAllowed.golden b/internal/format/testdata/asciidoc/document-IndentationBelowAllowed.golden new file mode 100644 index 0000000..ed5fae5 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-IndentationBelowAllowed.golden @@ -0,0 +1,382 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document-IndentationOfFour.golden b/internal/format/testdata/asciidoc/document-IndentationOfFour.golden new file mode 100644 index 0000000..30df264 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-IndentationOfFour.golden @@ -0,0 +1,382 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +==== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +==== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +==== Inputs + +The following input variables are supported: + +===== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +===== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +===== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +===== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +===== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +===== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +===== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +===== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +===== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +===== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +===== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +===== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +===== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +===== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +===== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +===== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +===== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +===== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +===== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +===== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +===== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +===== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +===== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +===== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +===== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +===== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +===== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +===== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +===== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +===== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +==== Outputs + +The following outputs are exported: + +===== unquoted + +Description: It's unquoted output. + +===== output-2 + +Description: It's output number two. + +===== output-1 + +Description: It's output number one. + +===== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document-NoHeader.golden b/internal/format/testdata/asciidoc/document-NoHeader.golden new file mode 100644 index 0000000..a915b94 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-NoHeader.golden @@ -0,0 +1,344 @@ +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document-NoInputs.golden b/internal/format/testdata/asciidoc/document-NoInputs.golden new file mode 100644 index 0000000..296c49d --- /dev/null +++ b/internal/format/testdata/asciidoc/document-NoInputs.golden @@ -0,0 +1,79 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document-NoOutputs.golden b/internal/format/testdata/asciidoc/document-NoOutputs.golden new file mode 100644 index 0000000..40cc3a8 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-NoOutputs.golden @@ -0,0 +1,362 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` diff --git a/internal/format/testdata/asciidoc/document-NoProviders.golden b/internal/format/testdata/asciidoc/document-NoProviders.golden new file mode 100644 index 0000000..d451a0e --- /dev/null +++ b/internal/format/testdata/asciidoc/document-NoProviders.golden @@ -0,0 +1,370 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document-NoRequirements.golden b/internal/format/testdata/asciidoc/document-NoRequirements.golden new file mode 100644 index 0000000..9150c74 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-NoRequirements.golden @@ -0,0 +1,372 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document-OnlyHeader.golden b/internal/format/testdata/asciidoc/document-OnlyHeader.golden new file mode 100644 index 0000000..f4425a9 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-OnlyHeader.golden @@ -0,0 +1,37 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | diff --git a/internal/format/testdata/asciidoc/document-OnlyInputs.golden b/internal/format/testdata/asciidoc/document-OnlyInputs.golden new file mode 100644 index 0000000..bd10b70 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-OnlyInputs.golden @@ -0,0 +1,302 @@ +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` diff --git a/internal/format/testdata/asciidoc/document-OnlyOutputs.golden b/internal/format/testdata/asciidoc/document-OnlyOutputs.golden new file mode 100644 index 0000000..509b98e --- /dev/null +++ b/internal/format/testdata/asciidoc/document-OnlyOutputs.golden @@ -0,0 +1,19 @@ +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document-OnlyProviders.golden b/internal/format/testdata/asciidoc/document-OnlyProviders.golden new file mode 100644 index 0000000..c7c930b --- /dev/null +++ b/internal/format/testdata/asciidoc/document-OnlyProviders.golden @@ -0,0 +1,11 @@ +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null diff --git a/internal/format/testdata/asciidoc/document-OnlyRequirements.golden b/internal/format/testdata/asciidoc/document-OnlyRequirements.golden new file mode 100644 index 0000000..b5096f2 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-OnlyRequirements.golden @@ -0,0 +1,9 @@ +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) diff --git a/internal/format/testdata/asciidoc/document-OutputValues.golden b/internal/format/testdata/asciidoc/document-OutputValues.golden new file mode 100644 index 0000000..9cda97d --- /dev/null +++ b/internal/format/testdata/asciidoc/document-OutputValues.golden @@ -0,0 +1,411 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +Value: +[source,json] +---- +{ + "leon": "cat" +} +---- + +Sensitive: no + +=== output-2 + +Description: It's output number two. + +Value: +[source,json] +---- +[ + "jack", + "lola" +] +---- + +Sensitive: no + +=== output-1 + +Description: It's output number one. + +Value: `1` + +Sensitive: no + +=== output-0.12 + +Description: terraform 0.12 only + +Value: `` + +Sensitive: yes diff --git a/internal/format/testdata/asciidoc/document-OutputValuesNoSensitivity.golden b/internal/format/testdata/asciidoc/document-OutputValuesNoSensitivity.golden new file mode 100644 index 0000000..449090c --- /dev/null +++ b/internal/format/testdata/asciidoc/document-OutputValuesNoSensitivity.golden @@ -0,0 +1,403 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +Value: +[source,json] +---- +{ + "leon": "cat" +} +---- + +=== output-2 + +Description: It's output number two. + +Value: +[source,json] +---- +[ + "jack", + "lola" +] +---- + +=== output-1 + +Description: It's output number one. + +Value: `1` + +=== output-0.12 + +Description: terraform 0.12 only + +Value: `` diff --git a/internal/format/testdata/asciidoc/document-SortByName.golden b/internal/format/testdata/asciidoc/document-SortByName.golden new file mode 100644 index 0000000..634735c --- /dev/null +++ b/internal/format/testdata/asciidoc/document-SortByName.golden @@ -0,0 +1,382 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +- tls + +== Inputs + +The following input variables are supported: + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +== Outputs + +The following outputs are exported: + +=== output-0.12 + +Description: terraform 0.12 only + +=== output-1 + +Description: It's output number one. + +=== output-2 + +Description: It's output number two. + +=== unquoted + +Description: It's unquoted output. diff --git a/internal/format/testdata/asciidoc/document-SortByRequired.golden b/internal/format/testdata/asciidoc/document-SortByRequired.golden new file mode 100644 index 0000000..357fc84 --- /dev/null +++ b/internal/format/testdata/asciidoc/document-SortByRequired.golden @@ -0,0 +1,382 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +- tls + +== Inputs + +The following input variables are supported: + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +== Outputs + +The following outputs are exported: + +=== output-0.12 + +Description: terraform 0.12 only + +=== output-1 + +Description: It's output number one. + +=== output-2 + +Description: It's output number two. + +=== unquoted + +Description: It's unquoted output. diff --git a/internal/format/testdata/asciidoc/document-WithRequired.golden b/internal/format/testdata/asciidoc/document-WithRequired.golden new file mode 100644 index 0000000..98e453e --- /dev/null +++ b/internal/format/testdata/asciidoc/document-WithRequired.golden @@ -0,0 +1,372 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Required Inputs + +The following input variables are required: + +=== unquoted + +Description: n/a + +Type: `any` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +=== string_no_default + +Description: n/a + +Type: `string` + +== Optional Inputs + +The following input variables are optional (have default values): + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/document.golden b/internal/format/testdata/asciidoc/document.golden new file mode 100644 index 0000000..ed5fae5 --- /dev/null +++ b/internal/format/testdata/asciidoc/document.golden @@ -0,0 +1,382 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +The following requirements are needed by this module: + +- terraform (>= 0.12) + +- aws (>= 2.15.0) + +- random (>= 2.2.0) + +== Providers + +The following providers are used by this module: + +- tls + +- aws (>= 2.15.0) + +- aws.ident (>= 2.15.0) + +- null + +== Inputs + +The following input variables are supported: + +=== unquoted + +Description: n/a + +Type: `any` + +Default: n/a + +=== bool-3 + +Description: n/a + +Type: `bool` + +Default: `true` + +=== bool-2 + +Description: It's bool number two. + +Type: `bool` + +Default: `false` + +=== bool-1 + +Description: It's bool number one. + +Type: `bool` + +Default: `true` + +=== string-3 + +Description: n/a + +Type: `string` + +Default: `""` + +=== string-2 + +Description: It's string number two. + +Type: `string` + +Default: n/a + +=== string-1 + +Description: It's string number one. + +Type: `string` + +Default: `"bar"` + +=== number-3 + +Description: n/a + +Type: `number` + +Default: `"19"` + +=== number-4 + +Description: n/a + +Type: `number` + +Default: `15.75` + +=== number-2 + +Description: It's number number two. + +Type: `number` + +Default: n/a + +=== number-1 + +Description: It's number number one. + +Type: `number` + +Default: `42` + +=== map-3 + +Description: n/a + +Type: `map` + +Default: `{}` + +=== map-2 + +Description: It's map number two. + +Type: `map` + +Default: n/a + +=== map-1 + +Description: It's map number one. + +Type: `map` + +Default: +[source,json] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +=== list-3 + +Description: n/a + +Type: `list` + +Default: `[]` + +=== list-2 + +Description: It's list number two. + +Type: `list` + +Default: n/a + +=== list-1 + +Description: It's list number one. + +Type: `list` + +Default: +[source,json] +---- +[ + "a", + "b", + "c" +] +---- + +=== input_with_underscores + +Description: A variable with underscores. + +Type: `any` + +Default: n/a + +=== input-with-pipe + +Description: It includes v1 \| v2 \| v3 + +Type: `string` + +Default: `"v1"` + +=== input-with-code-block + +Description: This is a complicated one. We need a newline. +And an example in a code block +``` +default = [ + "machine rack01:neptune" +] +``` + +Type: `list` + +Default: +[source,json] +---- +[ + "name rack:location" +] +---- + +=== long_type + +Description: This description is itself markdown. + +It spans over multiple lines. + +Type: +[source,hcl] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +Default: +[source,json] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +=== no-escape-default-value + +Description: The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. + +Type: `string` + +Default: `"VALUE_WITH_UNDERSCORE"` + +=== with-url + +Description: The description contains url. https://www.domain.com/foo/bar_baz.html + +Type: `string` + +Default: `""` + +=== string_default_empty + +Description: n/a + +Type: `string` + +Default: `""` + +=== string_default_null + +Description: n/a + +Type: `string` + +Default: `null` + +=== string_no_default + +Description: n/a + +Type: `string` + +Default: n/a + +=== number_default_zero + +Description: n/a + +Type: `number` + +Default: `0` + +=== bool_default_false + +Description: n/a + +Type: `bool` + +Default: `false` + +=== list_default_empty + +Description: n/a + +Type: `list(string)` + +Default: `[]` + +=== object_default_empty + +Description: n/a + +Type: `object({})` + +Default: `{}` + +== Outputs + +The following outputs are exported: + +=== unquoted + +Description: It's unquoted output. + +=== output-2 + +Description: It's output number two. + +=== output-1 + +Description: It's output number one. + +=== output-0.12 + +Description: terraform 0.12 only diff --git a/internal/format/testdata/asciidoc/table-HeaderFromFile.golden b/internal/format/testdata/asciidoc/table-HeaderFromFile.golden new file mode 100644 index 0000000..6765471 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-HeaderFromFile.golden @@ -0,0 +1,265 @@ +This header comes from a custom file + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna +aliqua. Ut enim ad minim veniam, quis nostrud exercitation +ullamco laboris nisi ut aliquip ex ea commodo consequat. +Duis aute irure dolor in reprehenderit in voluptate velit +esse cillum dolore eu fugiat nulla pariatur. + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table-IndentationAboveAllowed.golden b/internal/format/testdata/asciidoc/table-IndentationAboveAllowed.golden new file mode 100644 index 0000000..db7ce9e --- /dev/null +++ b/internal/format/testdata/asciidoc/table-IndentationAboveAllowed.golden @@ -0,0 +1,294 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table-IndentationBelowAllowed.golden b/internal/format/testdata/asciidoc/table-IndentationBelowAllowed.golden new file mode 100644 index 0000000..db7ce9e --- /dev/null +++ b/internal/format/testdata/asciidoc/table-IndentationBelowAllowed.golden @@ -0,0 +1,294 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table-IndentationOfFour.golden b/internal/format/testdata/asciidoc/table-IndentationOfFour.golden new file mode 100644 index 0000000..b9e8b2b --- /dev/null +++ b/internal/format/testdata/asciidoc/table-IndentationOfFour.golden @@ -0,0 +1,294 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +==== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +==== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +==== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +==== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table-NoHeader.golden b/internal/format/testdata/asciidoc/table-NoHeader.golden new file mode 100644 index 0000000..88dfba4 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-NoHeader.golden @@ -0,0 +1,256 @@ +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table-NoInputs.golden b/internal/format/testdata/asciidoc/table-NoInputs.golden new file mode 100644 index 0000000..58e5e30 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-NoInputs.golden @@ -0,0 +1,69 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table-NoOutputs.golden b/internal/format/testdata/asciidoc/table-NoOutputs.golden new file mode 100644 index 0000000..adeb9b4 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-NoOutputs.golden @@ -0,0 +1,283 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== diff --git a/internal/format/testdata/asciidoc/table-NoProviders.golden b/internal/format/testdata/asciidoc/table-NoProviders.golden new file mode 100644 index 0000000..6b9f5cd --- /dev/null +++ b/internal/format/testdata/asciidoc/table-NoProviders.golden @@ -0,0 +1,283 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table-NoRequirements.golden b/internal/format/testdata/asciidoc/table-NoRequirements.golden new file mode 100644 index 0000000..0df70b3 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-NoRequirements.golden @@ -0,0 +1,284 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table-OnlyHeader.golden b/internal/format/testdata/asciidoc/table-OnlyHeader.golden new file mode 100644 index 0000000..f4425a9 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-OnlyHeader.golden @@ -0,0 +1,37 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | diff --git a/internal/format/testdata/asciidoc/table-OnlyInputs.golden b/internal/format/testdata/asciidoc/table-OnlyInputs.golden new file mode 100644 index 0000000..8956f74 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-OnlyInputs.golden @@ -0,0 +1,224 @@ +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== diff --git a/internal/format/testdata/asciidoc/table-OnlyOutputs.golden b/internal/format/testdata/asciidoc/table-OnlyOutputs.golden new file mode 100644 index 0000000..0f3b49a --- /dev/null +++ b/internal/format/testdata/asciidoc/table-OnlyOutputs.golden @@ -0,0 +1,10 @@ +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table-OnlyProviders.golden b/internal/format/testdata/asciidoc/table-OnlyProviders.golden new file mode 100644 index 0000000..d54e030 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-OnlyProviders.golden @@ -0,0 +1,10 @@ +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== diff --git a/internal/format/testdata/asciidoc/table-OnlyRequirements.golden b/internal/format/testdata/asciidoc/table-OnlyRequirements.golden new file mode 100644 index 0000000..169d50f --- /dev/null +++ b/internal/format/testdata/asciidoc/table-OnlyRequirements.golden @@ -0,0 +1,9 @@ +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== diff --git a/internal/format/testdata/asciidoc/table-OutputValues.golden b/internal/format/testdata/asciidoc/table-OutputValues.golden new file mode 100644 index 0000000..1e3a079 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-OutputValues.golden @@ -0,0 +1,309 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +== Outputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Value |Sensitive +|unquoted |It's unquoted output. | + +``` +{ + "leon": "cat" +} +``` + |no +|output-2 |It's output number two. | + +``` +[ + "jack", + "lola" +] +``` + |no +|output-1 |It's output number one. |`1` |no +|output-0.12 |terraform 0.12 only |`` |yes +|=== diff --git a/internal/format/testdata/asciidoc/table-OutputValuesNoSensitivity.golden b/internal/format/testdata/asciidoc/table-OutputValuesNoSensitivity.golden new file mode 100644 index 0000000..61c9ba4 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-OutputValuesNoSensitivity.golden @@ -0,0 +1,309 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +== Outputs + +[cols="a,a,a",options="header,autowidth"] +|=== +|Name |Description |Value +|unquoted |It's unquoted output. | + +``` +{ + "leon": "cat" +} +``` + +|output-2 |It's output number two. | + +``` +[ + "jack", + "lola" +] +``` + +|output-1 |It's output number one. |`1` +|output-0.12 |terraform 0.12 only |`` +|=== diff --git a/internal/format/testdata/asciidoc/table-SortByName.golden b/internal/format/testdata/asciidoc/table-SortByName.golden new file mode 100644 index 0000000..5bba7dd --- /dev/null +++ b/internal/format/testdata/asciidoc/table-SortByName.golden @@ -0,0 +1,294 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|tls |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-3 +|n/a +|`bool` +|`true` + +|bool_default_false +|n/a +|`bool` +|`false` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-3 +|n/a +|`list` +|`[]` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-3 +|n/a +|`map` +|`{}` + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|number-1 +|It's number number one. +|`number` +|`42` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number_default_zero +|n/a +|`number` +|`0` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-3 +|n/a +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|unquoted +|n/a +|`any` +|n/a + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|output-0.12 |terraform 0.12 only +|output-1 |It's output number one. +|output-2 |It's output number two. +|unquoted |It's unquoted output. +|=== diff --git a/internal/format/testdata/asciidoc/table-SortByRequired.golden b/internal/format/testdata/asciidoc/table-SortByRequired.golden new file mode 100644 index 0000000..12ce5ef --- /dev/null +++ b/internal/format/testdata/asciidoc/table-SortByRequired.golden @@ -0,0 +1,294 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|tls |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|list-2 +|It's list number two. +|`list` +|n/a + +|map-2 +|It's map number two. +|`map` +|n/a + +|number-2 +|It's number number two. +|`number` +|n/a + +|string-2 +|It's string number two. +|`string` +|n/a + +|string_no_default +|n/a +|`string` +|n/a + +|unquoted +|n/a +|`any` +|n/a + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-3 +|n/a +|`bool` +|`true` + +|bool_default_false +|n/a +|`bool` +|`false` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|map-3 +|n/a +|`map` +|`{}` + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|number-1 +|It's number number one. +|`number` +|`42` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number_default_zero +|n/a +|`number` +|`0` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|string-3 +|n/a +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|output-0.12 |terraform 0.12 only +|output-1 |It's output number one. +|output-2 |It's output number two. +|unquoted |It's unquoted output. +|=== diff --git a/internal/format/testdata/asciidoc/table-WithRequired.golden b/internal/format/testdata/asciidoc/table-WithRequired.golden new file mode 100644 index 0000000..2f52477 --- /dev/null +++ b/internal/format/testdata/asciidoc/table-WithRequired.golden @@ -0,0 +1,328 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default |Required +|unquoted +|n/a +|`any` +|n/a +|yes + +|bool-3 +|n/a +|`bool` +|`true` +|no + +|bool-2 +|It's bool number two. +|`bool` +|`false` +|no + +|bool-1 +|It's bool number one. +|`bool` +|`true` +|no + +|string-3 +|n/a +|`string` +|`""` +|no + +|string-2 +|It's string number two. +|`string` +|n/a +|yes + +|string-1 +|It's string number one. +|`string` +|`"bar"` +|no + +|number-3 +|n/a +|`number` +|`"19"` +|no + +|number-4 +|n/a +|`number` +|`15.75` +|no + +|number-2 +|It's number number two. +|`number` +|n/a +|yes + +|number-1 +|It's number number one. +|`number` +|`42` +|no + +|map-3 +|n/a +|`map` +|`{}` +|no + +|map-2 +|It's map number two. +|`map` +|n/a +|yes + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|no + +|list-3 +|n/a +|`list` +|`[]` +|no + +|list-2 +|It's list number two. +|`list` +|n/a +|yes + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|no + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a +|yes + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` +|no + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|no + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` +|no + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` +|no + +|string_default_empty +|n/a +|`string` +|`""` +|no + +|string_default_null +|n/a +|`string` +|`null` +|no + +|string_no_default +|n/a +|`string` +|n/a +|yes + +|number_default_zero +|n/a +|`number` +|`0` +|no + +|bool_default_false +|n/a +|`bool` +|`false` +|no + +|list_default_empty +|n/a +|`list(string)` +|`[]` +|no + +|object_default_empty +|n/a +|`object({})` +|`{}` +|no + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/testdata/asciidoc/table.golden b/internal/format/testdata/asciidoc/table.golden new file mode 100644 index 0000000..db7ce9e --- /dev/null +++ b/internal/format/testdata/asciidoc/table.golden @@ -0,0 +1,294 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +```hcl +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +``` + +Here is some trailing text after code block, +followed by another line of text. + +| Name | Description | +|------|-----------------| +| Foo | Foo description | +| Bar | Bar description | + +== Requirements + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|terraform |>= 0.12 +|aws |>= 2.15.0 +|random |>= 2.2.0 +|=== + +== Providers + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Version +|tls |n/a +|aws |>= 2.15.0 +|aws.ident |>= 2.15.0 +|null |n/a +|=== + +== Inputs + +[cols="a,a,a,a",options="header,autowidth"] +|=== +|Name |Description |Type |Default +|unquoted +|n/a +|`any` +|n/a + +|bool-3 +|n/a +|`bool` +|`true` + +|bool-2 +|It's bool number two. +|`bool` +|`false` + +|bool-1 +|It's bool number one. +|`bool` +|`true` + +|string-3 +|n/a +|`string` +|`""` + +|string-2 +|It's string number two. +|`string` +|n/a + +|string-1 +|It's string number one. +|`string` +|`"bar"` + +|number-3 +|n/a +|`number` +|`"19"` + +|number-4 +|n/a +|`number` +|`15.75` + +|number-2 +|It's number number two. +|`number` +|n/a + +|number-1 +|It's number number one. +|`number` +|`42` + +|map-3 +|n/a +|`map` +|`{}` + +|map-2 +|It's map number two. +|`map` +|n/a + +|map-1 +|It's map number one. +|`map` +| + +[source] +---- +{ + "a": 1, + "b": 2, + "c": 3 +} +---- + +|list-3 +|n/a +|`list` +|`[]` + +|list-2 +|It's list number two. +|`list` +|n/a + +|list-1 +|It's list number one. +|`list` +| + +[source] +---- +[ + "a", + "b", + "c" +] +---- + +|input_with_underscores +|A variable with underscores. +|`any` +|n/a + +|input-with-pipe +|It includes v1 \| v2 \| v3 +|`string` +|`"v1"` + +|input-with-code-block +|This is a complicated one. We need a newline. +And an example in a code block +[source] +---- +default = [ + "machine rack01:neptune" +] +---- + +|`list` +| + +[source] +---- +[ + "name rack:location" +] +---- + +|long_type +|This description is itself markdown. + +It spans over multiple lines. + +| + +[source] +---- +object({ + name = string, + foo = object({ foo = string, bar = string }), + bar = object({ foo = string, bar = string }), + fizz = list(string), + buzz = list(string) + }) +---- + +| + +[source] +---- +{ + "bar": { + "bar": "bar", + "foo": "bar" + }, + "buzz": [ + "fizz", + "buzz" + ], + "fizz": [], + "foo": { + "bar": "foo", + "foo": "foo" + }, + "name": "hello" +} +---- + +|no-escape-default-value +|The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'. +|`string` +|`"VALUE_WITH_UNDERSCORE"` + +|with-url +|The description contains url. https://www.domain.com/foo/bar_baz.html +|`string` +|`""` + +|string_default_empty +|n/a +|`string` +|`""` + +|string_default_null +|n/a +|`string` +|`null` + +|string_no_default +|n/a +|`string` +|n/a + +|number_default_zero +|n/a +|`number` +|`0` + +|bool_default_false +|n/a +|`bool` +|`false` + +|list_default_empty +|n/a +|`list(string)` +|`[]` + +|object_default_empty +|n/a +|`object({})` +|`{}` + +|=== + +== Outputs + +[cols="a,a",options="header,autowidth"] +|=== +|Name |Description +|unquoted |It's unquoted output. +|output-2 |It's output number two. +|output-1 |It's output number one. +|output-0.12 |terraform 0.12 only +|=== diff --git a/internal/format/util.go b/internal/format/util.go index 2f3f952..7d3b0ac 100644 --- a/internal/format/util.go +++ b/internal/format/util.go @@ -41,3 +41,15 @@ func printFencedCodeBlock(code string, language string) (string, bool) { } return fmt.Sprintf("`%s`", code), false } + +// printFencedAsciidocCodeBlock prints codes in fences, it automatically detects if +// the input 'code' contains '\n' it will use multi line fence, otherwise it +// wraps the 'code' inside single-tick block. +// If the fenced is multi-line it also appens an extra '\n` at the end and +// returns true accordingly, otherwise returns false for non-carriage return. +func printFencedAsciidocCodeBlock(code string, language string) (string, bool) { + if strings.Contains(code, "\n") { + return fmt.Sprintf("\n[source,%s]\n----\n%s\n----\n", language, code), true + } + return fmt.Sprintf("`%s`", code), false +} diff --git a/pkg/print/settings.go b/pkg/print/settings.go index a9a039c..a9c47be 100644 --- a/pkg/print/settings.go +++ b/pkg/print/settings.go @@ -10,9 +10,9 @@ type Settings struct { // scope: Markdown EscapePipe bool - // MarkdownIndent control the indentation of Markdown headers [available: 1, 2, 3, 4, 5] (default: 2) - // scope: Markdown - MarkdownIndent int + // IndentLevel control the indentation of AsciiDoc and Markdown headers [available: 1, 2, 3, 4, 5] (default: 2) + // scope: Asciidoc, Markdown + IndentLevel int // OutputValues ailrghaekrgj // scope: Global @@ -64,7 +64,7 @@ func NewSettings() *Settings { return &Settings{ EscapeCharacters: true, EscapePipe: true, - MarkdownIndent: 2, + IndentLevel: 2, OutputValues: false, ShowColor: true, ShowHeader: true, diff --git a/pkg/tmpl/sanitizer.go b/pkg/tmpl/sanitizer.go index 529df0c..5d7e8a9 100644 --- a/pkg/tmpl/sanitizer.go +++ b/pkg/tmpl/sanitizer.go @@ -72,6 +72,28 @@ func sanitizeItemForTable(s string, settings *print.Settings) string { return result } +// sanitizeItemForAsciidocTable converts passed 'string' to suitable AsciiDoc representation +// for a table. (including line-break, illegal characters, code blocks etc) +func sanitizeItemForAsciidocTable(s string, settings *print.Settings) string { + if s == "" { + return "n/a" + } + result := processSegments( + s, + "```", + func(segment string) string { + segment = escapeIllegalCharacters(segment, settings) + return segment + }, + func(segment string) string { + segment = strings.TrimSpace(segment) + segment = fmt.Sprintf("[source]\n----\n%s\n----", segment) + return segment + }, + ) + return result +} + // convertMultiLineText converts a multi-line text into a suitable Markdown representation. func convertMultiLineText(s string, isTable bool) string { if isTable { @@ -183,18 +205,21 @@ func normalizeURLs(s string, settings *print.Settings) string { return s } -// generateIndentation generates indentation of Markdown headers -// with base level of provided 'settings.MarkdownIndent' plus any +// generateIndentation generates indentation of Markdown and AsciiDoc headers +// with base level of provided 'settings.IndentLevel' plus any // extra level needed for subsection (e.g. 'Required Inputs' which // is a subsection of 'Inputs' section) -func generateIndentation(extra int, settings *print.Settings) string { - var base = settings.MarkdownIndent +func generateIndentation(extra int, char string, settings *print.Settings) string { + if char == "" { + return "" + } + var base = settings.IndentLevel if base < 1 || base > 5 { base = 2 } var indent string for i := 0; i < base+extra; i++ { - indent += "#" + indent += char } return indent } diff --git a/pkg/tmpl/sanitizer_test.go b/pkg/tmpl/sanitizer_test.go index 47dfd14..74cec2f 100644 --- a/pkg/tmpl/sanitizer_test.go +++ b/pkg/tmpl/sanitizer_test.go @@ -187,6 +187,49 @@ func TestSanitizeItemForTable(t *testing.T) { } } +func TestSanitizeItemForAsciidocTable(t *testing.T) { + tests := []struct { + name string + filename string + escapeChars bool + escapePipe bool + }{ + { + name: "sanitize table item empty", + filename: "empty", + escapeChars: false, + }, + { + name: "sanitize table item complex", + filename: "complex", + escapeChars: false, + }, + { + name: "sanitize table item codeblock", + filename: "codeblock", + escapeChars: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert := assert.New(t) + settings := testutil.Settings().With(&print.Settings{ + EscapeCharacters: tt.escapeChars, + }).Build() + + bytes, err := ioutil.ReadFile(filepath.Join("testdata", "table", tt.filename+".golden")) + assert.Nil(err) + + actual := sanitizeItemForAsciidocTable(string(bytes), settings) + + expected, err := ioutil.ReadFile(filepath.Join("testdata", "table", tt.filename+".asciidoc.expected")) + assert.Nil(err) + + assert.Equal(string(expected), actual) + }) + } +} + func TestConvertMultiLineText(t *testing.T) { tests := []struct { name string @@ -516,9 +559,9 @@ func TestGenerateIndentation(t *testing.T) { t.Run(tt.name, func(t *testing.T) { assert := assert.New(t) settings := testutil.Settings().With(&print.Settings{ - MarkdownIndent: tt.base, + IndentLevel: tt.base, }).Build() - actual := generateIndentation(tt.extra, settings) + actual := generateIndentation(tt.extra, "#", settings) assert.Equal(tt.expected, actual) }) diff --git a/pkg/tmpl/template.go b/pkg/tmpl/template.go index c10df3b..f8e3797 100644 --- a/pkg/tmpl/template.go +++ b/pkg/tmpl/template.go @@ -142,9 +142,8 @@ func builtinFuncs(settings *print.Settings) template.FuncMap { } return s }, - - "indent": func(l int) string { - return generateIndentation(l, settings) + "indent": func(l int, char string) string { + return generateIndentation(l, char, settings) }, "name": func(n string) string { return sanitizeName(n, settings) @@ -164,6 +163,12 @@ func builtinFuncs(settings *print.Settings) template.FuncMap { settings.EscapePipe = false return s }, + "sanitizeAsciidocTbl": func(s string) string { + settings.EscapePipe = true + s = sanitizeItemForAsciidocTable(s, settings) + settings.EscapePipe = false + return s + }, } } diff --git a/pkg/tmpl/template_test.go b/pkg/tmpl/template_test.go index e8dc815..73560f3 100644 --- a/pkg/tmpl/template_test.go +++ b/pkg/tmpl/template_test.go @@ -307,7 +307,7 @@ func TestBuiltinFunc(t *testing.T) { { name: "template builtin functions indent", funcName: "indent", - funcArgs: []string{`0`}, + funcArgs: []string{`0`, `"#"`}, escapeChar: true, escapePipe: true, expected: "##", @@ -315,7 +315,7 @@ func TestBuiltinFunc(t *testing.T) { { name: "template builtin functions indent", funcName: "indent", - funcArgs: []string{`1`}, + funcArgs: []string{`1`, `"#"`}, escapeChar: true, escapePipe: true, expected: "###", @@ -323,7 +323,7 @@ func TestBuiltinFunc(t *testing.T) { { name: "template builtin functions indent", funcName: "indent", - funcArgs: []string{`2`}, + funcArgs: []string{`2`, `"#"`}, escapeChar: true, escapePipe: true, expected: "####", @@ -331,7 +331,7 @@ func TestBuiltinFunc(t *testing.T) { { name: "template builtin functions indent", funcName: "indent", - funcArgs: []string{`3`}, + funcArgs: []string{`3`, `"#"`}, escapeChar: true, escapePipe: true, expected: "#####", diff --git a/pkg/tmpl/testdata/table/codeblock.asciidoc.expected b/pkg/tmpl/testdata/table/codeblock.asciidoc.expected new file mode 100644 index 0000000..1426fed --- /dev/null +++ b/pkg/tmpl/testdata/table/codeblock.asciidoc.expected @@ -0,0 +1,10 @@ +This is a complicated one. We need a newline. +And an example in a code block. Availeble options +are: foo \| bar \| baz + +[source] +---- +default = [ + "foo" +] +---- \ No newline at end of file diff --git a/pkg/tmpl/testdata/table/complex.asciidoc.expected b/pkg/tmpl/testdata/table/complex.asciidoc.expected new file mode 100644 index 0000000..243240b --- /dev/null +++ b/pkg/tmpl/testdata/table/complex.asciidoc.expected @@ -0,0 +1,38 @@ +Usage: + +Example of 'foo_bar' module in `foo_bar.tf`. + +- list item 1 +- list item 2 + +Even inline **formatting** in _here_ is possible. +and some [link](https://domain.com/) + +* list item 3 +* list item 4 + +[source] +---- +module "foo_bar" { + source = "github.com/foo/bar" + + id = "1234567890" + name = "baz" + + zones = ["us-east-1", "us-west-1"] + + tags = { + Name = "baz" + Created-By = "first.last@email.com" + Date-Created = "20180101" + } +} +---- + +Here is some trailing text after code block, +followed by another line of text. + +\| Name \| Description \| +\|------\|-----------------\| +\| Foo \| Foo description \| +\| Bar \| Bar description \| \ No newline at end of file diff --git a/pkg/tmpl/testdata/table/empty.asciidoc.expected b/pkg/tmpl/testdata/table/empty.asciidoc.expected new file mode 100644 index 0000000..d8e0871 --- /dev/null +++ b/pkg/tmpl/testdata/table/empty.asciidoc.expected @@ -0,0 +1 @@ +n/a \ No newline at end of file