mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 04:48:33 +07:00
feat: Add support for XML renderer (#198)
* Add support for XML renderer * formatting * update docs
This commit is contained in:
@@ -9,12 +9,13 @@
|
||||
A utility to generate documentation from Terraform modules in various output formats.
|
||||
|
||||
``` bash
|
||||
terraform-docs pretty ./my-terraform-module # generate colorized pretty
|
||||
terraform-docs json ./my-terraform-module # generate json
|
||||
terraform-docs yaml ./my-terraform-module # generate yaml
|
||||
terraform-docs markdown ./my-terraform-module # generate markdown table
|
||||
terraform-docs markdown table ./my-terraform-module # generate markdown table
|
||||
terraform-docs markdown document ./my-terraform-module # generate markdown document
|
||||
terraform-docs pretty ./my-terraform-module # generate colorized pretty
|
||||
terraform-docs xml ./my-terraform-module # generate xml
|
||||
terraform-docs yaml ./my-terraform-module # generate yaml
|
||||
```
|
||||
|
||||
Read the [User Guide](./docs/USER_GUIDE.md) for detailed documentation.
|
||||
|
||||
@@ -73,6 +73,7 @@ func FormatterCmds() []*cobra.Command {
|
||||
prettyCmd,
|
||||
mdDocumentCmd,
|
||||
mdTableCmd,
|
||||
xmlCmd,
|
||||
yamlCmd,
|
||||
}
|
||||
}
|
||||
|
||||
19
cmd/xml.go
Normal file
19
cmd/xml.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/segmentio/terraform-docs/internal/format"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var xmlCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "xml [PATH]",
|
||||
Short: "Generate XML of inputs and outputs",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewXML(settings))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(xmlCmd)
|
||||
}
|
||||
@@ -29,6 +29,7 @@ A utility to generate documentation from Terraform modules in various output for
|
||||
* [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
|
||||
* [terraform-docs pretty](/docs/formats/pretty.md) - Generate colorized pretty of inputs and outputs
|
||||
* [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
|
||||
|
||||
## Terraform Versions
|
||||
|
||||
@@ -252,4 +252,4 @@ generates the following output:
|
||||
}
|
||||
|
||||
|
||||
###### Auto generated by spf13/cobra on 19-Feb-2020
|
||||
###### Auto generated by spf13/cobra on 26-Feb-2020
|
||||
|
||||
@@ -355,4 +355,4 @@ generates the following output:
|
||||
|
||||
|
||||
|
||||
###### Auto generated by spf13/cobra on 19-Feb-2020
|
||||
###### Auto generated by spf13/cobra on 26-Feb-2020
|
||||
|
||||
@@ -130,4 +130,4 @@ generates the following output:
|
||||
|
||||
|
||||
|
||||
###### Auto generated by spf13/cobra on 19-Feb-2020
|
||||
###### Auto generated by spf13/cobra on 26-Feb-2020
|
||||
|
||||
@@ -27,6 +27,8 @@ terraform-docs markdown [PATH] [flags]
|
||||
--no-outputs do not show outputs
|
||||
--no-providers do not show providers
|
||||
--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
|
||||
|
||||
@@ -213,4 +213,4 @@ generates the following output:
|
||||
|
||||
|
||||
|
||||
###### Auto generated by spf13/cobra on 19-Feb-2020
|
||||
###### Auto generated by spf13/cobra on 26-Feb-2020
|
||||
|
||||
254
docs/formats/xml.md
Normal file
254
docs/formats/xml.md
Normal file
@@ -0,0 +1,254 @@
|
||||
## terraform-docs xml
|
||||
|
||||
Generate XML of inputs and outputs
|
||||
|
||||
### Synopsis
|
||||
|
||||
Generate XML of inputs and outputs
|
||||
|
||||
```
|
||||
terraform-docs xml [PATH] [flags]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for xml
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--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-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 xml ./examples/
|
||||
```
|
||||
|
||||
generates the following output:
|
||||
|
||||
<module>
|
||||
<header>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 |</header>
|
||||
<inputs>
|
||||
<input>
|
||||
<name>bool-1</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number one.</description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-2</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number two.</description>
|
||||
<default>false</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-3</name>
|
||||
<type>bool</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-code-block</name>
|
||||
<type>list</type>
|
||||
<description>This is a complicated one. We need a newline. 
And an example in a code block
```
default = [
 "machine rack01:neptune"
]
```
</description>
|
||||
<default>
|
||||
<item>name rack:location</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-pipe</name>
|
||||
<type>string</type>
|
||||
<description>It includes v1 | v2 | v3</description>
|
||||
<default>v1</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input_with_underscores</name>
|
||||
<type>any</type>
|
||||
<description>A variable with underscores.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-1</name>
|
||||
<type>list</type>
|
||||
<description>It's list number one.</description>
|
||||
<default>
|
||||
<item>a</item>
|
||||
<item>b</item>
|
||||
<item>c</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-2</name>
|
||||
<type>list</type>
|
||||
<description>It's list number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-3</name>
|
||||
<type>list</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>long_type</name>
|
||||
<type>object({
 name = string,
 foo = object({ foo = string, bar = string }),
 bar = object({ foo = string, bar = string }),
 fizz = list(string),
 buzz = list(string)
 })</type>
|
||||
<description>This description is itself markdown.

It spans over multiple lines.
</description>
|
||||
<default>
|
||||
<bar>
|
||||
<bar>bar</bar>
|
||||
<foo>bar</foo>
|
||||
</bar>
|
||||
<buzz>
|
||||
<item>fizz</item>
|
||||
<item>buzz</item>
|
||||
</buzz>
|
||||
<fizz></fizz>
|
||||
<foo>
|
||||
<bar>foo</bar>
|
||||
<foo>foo</foo>
|
||||
</foo>
|
||||
<name>hello</name>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-1</name>
|
||||
<type>map</type>
|
||||
<description>It's map number one.</description>
|
||||
<default>
|
||||
<a>1</a>
|
||||
<b>2</b>
|
||||
<c>3</c>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-2</name>
|
||||
<type>map</type>
|
||||
<description>It's map number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-3</name>
|
||||
<type>map</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>no-escape-default-value</name>
|
||||
<type>string</type>
|
||||
<description>The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'.</description>
|
||||
<default>VALUE_WITH_UNDERSCORE</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-1</name>
|
||||
<type>number</type>
|
||||
<description>It's number number one.</description>
|
||||
<default>42</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-2</name>
|
||||
<type>number</type>
|
||||
<description>It's number number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-3</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>19</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-4</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>15.75</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-1</name>
|
||||
<type>string</type>
|
||||
<description>It's string number one.</description>
|
||||
<default>bar</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-2</name>
|
||||
<type>string</type>
|
||||
<description>It's string number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-3</name>
|
||||
<type>string</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>unquoted</name>
|
||||
<type>any</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>with-url</name>
|
||||
<type>string</type>
|
||||
<description>The description contains url. https://www.domain.com/foo/bar_baz.html</description>
|
||||
<default></default>
|
||||
</input>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<output>
|
||||
<name>output-0.12</name>
|
||||
<description>terraform 0.12 only</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-1</name>
|
||||
<description>It's output number one.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-2</name>
|
||||
<description>It's output number two.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>unquoted</name>
|
||||
<description>It's unquoted output.</description>
|
||||
</output>
|
||||
</outputs>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias>ident</alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>null</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>tls</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
</providers>
|
||||
</module>
|
||||
|
||||
|
||||
###### Auto generated by spf13/cobra on 26-Feb-2020
|
||||
@@ -225,4 +225,4 @@ generates the following output:
|
||||
version: null
|
||||
|
||||
|
||||
###### Auto generated by spf13/cobra on 19-Feb-2020
|
||||
###### Auto generated by spf13/cobra on 26-Feb-2020
|
||||
|
||||
208
internal/format/testdata/xml/xml-NoHeader.golden
vendored
Normal file
208
internal/format/testdata/xml/xml-NoHeader.golden
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
<module>
|
||||
<header></header>
|
||||
<inputs>
|
||||
<input>
|
||||
<name>unquoted</name>
|
||||
<type>any</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-3</name>
|
||||
<type>bool</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-2</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number two.</description>
|
||||
<default>false</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-1</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number one.</description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-3</name>
|
||||
<type>string</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-2</name>
|
||||
<type>string</type>
|
||||
<description>It's string number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-1</name>
|
||||
<type>string</type>
|
||||
<description>It's string number one.</description>
|
||||
<default>bar</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-3</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>19</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-4</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>15.75</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-2</name>
|
||||
<type>number</type>
|
||||
<description>It's number number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-1</name>
|
||||
<type>number</type>
|
||||
<description>It's number number one.</description>
|
||||
<default>42</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-3</name>
|
||||
<type>map</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-2</name>
|
||||
<type>map</type>
|
||||
<description>It's map number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-1</name>
|
||||
<type>map</type>
|
||||
<description>It's map number one.</description>
|
||||
<default>
|
||||
<a>1</a>
|
||||
<b>2</b>
|
||||
<c>3</c>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-3</name>
|
||||
<type>list</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-2</name>
|
||||
<type>list</type>
|
||||
<description>It's list number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-1</name>
|
||||
<type>list</type>
|
||||
<description>It's list number one.</description>
|
||||
<default>
|
||||
<item>a</item>
|
||||
<item>b</item>
|
||||
<item>c</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input_with_underscores</name>
|
||||
<type>any</type>
|
||||
<description>A variable with underscores.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-pipe</name>
|
||||
<type>string</type>
|
||||
<description>It includes v1 | v2 | v3</description>
|
||||
<default>v1</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-code-block</name>
|
||||
<type>list</type>
|
||||
<description>This is a complicated one. We need a newline. 
And an example in a code block
```
default = [
 "machine rack01:neptune"
]
```
</description>
|
||||
<default>
|
||||
<item>name rack:location</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>long_type</name>
|
||||
<type>object({
 name = string,
 foo = object({ foo = string, bar = string }),
 bar = object({ foo = string, bar = string }),
 fizz = list(string),
 buzz = list(string)
 })</type>
|
||||
<description>This description is itself markdown.

It spans over multiple lines.
</description>
|
||||
<default>
|
||||
<bar>
|
||||
<bar>bar</bar>
|
||||
<foo>bar</foo>
|
||||
</bar>
|
||||
<buzz>
|
||||
<item>fizz</item>
|
||||
<item>buzz</item>
|
||||
</buzz>
|
||||
<fizz></fizz>
|
||||
<foo>
|
||||
<bar>foo</bar>
|
||||
<foo>foo</foo>
|
||||
</foo>
|
||||
<name>hello</name>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>no-escape-default-value</name>
|
||||
<type>string</type>
|
||||
<description>The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'.</description>
|
||||
<default>VALUE_WITH_UNDERSCORE</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>with-url</name>
|
||||
<type>string</type>
|
||||
<description>The description contains url. https://www.domain.com/foo/bar_baz.html</description>
|
||||
<default></default>
|
||||
</input>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<output>
|
||||
<name>unquoted</name>
|
||||
<description>It's unquoted output.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-2</name>
|
||||
<description>It's output number two.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-1</name>
|
||||
<description>It's output number one.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-0.12</name>
|
||||
<description>terraform 0.12 only</description>
|
||||
</output>
|
||||
</outputs>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>tls</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias>ident</alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>null</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
</providers>
|
||||
</module>
|
||||
44
internal/format/testdata/xml/xml-NoInputs.golden
vendored
Normal file
44
internal/format/testdata/xml/xml-NoInputs.golden
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<module>
|
||||
<header>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 |</header>
|
||||
<inputs></inputs>
|
||||
<outputs>
|
||||
<output>
|
||||
<name>unquoted</name>
|
||||
<description>It's unquoted output.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-2</name>
|
||||
<description>It's output number two.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-1</name>
|
||||
<description>It's output number one.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-0.12</name>
|
||||
<description>terraform 0.12 only</description>
|
||||
</output>
|
||||
</outputs>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>tls</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias>ident</alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>null</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
</providers>
|
||||
</module>
|
||||
191
internal/format/testdata/xml/xml-NoOutputs.golden
vendored
Normal file
191
internal/format/testdata/xml/xml-NoOutputs.golden
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
<module>
|
||||
<header>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 |</header>
|
||||
<inputs>
|
||||
<input>
|
||||
<name>unquoted</name>
|
||||
<type>any</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-3</name>
|
||||
<type>bool</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-2</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number two.</description>
|
||||
<default>false</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-1</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number one.</description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-3</name>
|
||||
<type>string</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-2</name>
|
||||
<type>string</type>
|
||||
<description>It's string number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-1</name>
|
||||
<type>string</type>
|
||||
<description>It's string number one.</description>
|
||||
<default>bar</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-3</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>19</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-4</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>15.75</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-2</name>
|
||||
<type>number</type>
|
||||
<description>It's number number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-1</name>
|
||||
<type>number</type>
|
||||
<description>It's number number one.</description>
|
||||
<default>42</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-3</name>
|
||||
<type>map</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-2</name>
|
||||
<type>map</type>
|
||||
<description>It's map number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-1</name>
|
||||
<type>map</type>
|
||||
<description>It's map number one.</description>
|
||||
<default>
|
||||
<a>1</a>
|
||||
<b>2</b>
|
||||
<c>3</c>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-3</name>
|
||||
<type>list</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-2</name>
|
||||
<type>list</type>
|
||||
<description>It's list number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-1</name>
|
||||
<type>list</type>
|
||||
<description>It's list number one.</description>
|
||||
<default>
|
||||
<item>a</item>
|
||||
<item>b</item>
|
||||
<item>c</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input_with_underscores</name>
|
||||
<type>any</type>
|
||||
<description>A variable with underscores.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-pipe</name>
|
||||
<type>string</type>
|
||||
<description>It includes v1 | v2 | v3</description>
|
||||
<default>v1</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-code-block</name>
|
||||
<type>list</type>
|
||||
<description>This is a complicated one. We need a newline. 
And an example in a code block
```
default = [
 "machine rack01:neptune"
]
```
</description>
|
||||
<default>
|
||||
<item>name rack:location</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>long_type</name>
|
||||
<type>object({
 name = string,
 foo = object({ foo = string, bar = string }),
 bar = object({ foo = string, bar = string }),
 fizz = list(string),
 buzz = list(string)
 })</type>
|
||||
<description>This description is itself markdown.

It spans over multiple lines.
</description>
|
||||
<default>
|
||||
<bar>
|
||||
<bar>bar</bar>
|
||||
<foo>bar</foo>
|
||||
</bar>
|
||||
<buzz>
|
||||
<item>fizz</item>
|
||||
<item>buzz</item>
|
||||
</buzz>
|
||||
<fizz></fizz>
|
||||
<foo>
|
||||
<bar>foo</bar>
|
||||
<foo>foo</foo>
|
||||
</foo>
|
||||
<name>hello</name>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>no-escape-default-value</name>
|
||||
<type>string</type>
|
||||
<description>The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'.</description>
|
||||
<default>VALUE_WITH_UNDERSCORE</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>with-url</name>
|
||||
<type>string</type>
|
||||
<description>The description contains url. https://www.domain.com/foo/bar_baz.html</description>
|
||||
<default></default>
|
||||
</input>
|
||||
</inputs>
|
||||
<outputs></outputs>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>tls</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias>ident</alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>null</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
</providers>
|
||||
</module>
|
||||
187
internal/format/testdata/xml/xml-NoProviders.golden
vendored
Normal file
187
internal/format/testdata/xml/xml-NoProviders.golden
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
<module>
|
||||
<header>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 |</header>
|
||||
<inputs>
|
||||
<input>
|
||||
<name>unquoted</name>
|
||||
<type>any</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-3</name>
|
||||
<type>bool</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-2</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number two.</description>
|
||||
<default>false</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-1</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number one.</description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-3</name>
|
||||
<type>string</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-2</name>
|
||||
<type>string</type>
|
||||
<description>It's string number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-1</name>
|
||||
<type>string</type>
|
||||
<description>It's string number one.</description>
|
||||
<default>bar</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-3</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>19</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-4</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>15.75</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-2</name>
|
||||
<type>number</type>
|
||||
<description>It's number number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-1</name>
|
||||
<type>number</type>
|
||||
<description>It's number number one.</description>
|
||||
<default>42</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-3</name>
|
||||
<type>map</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-2</name>
|
||||
<type>map</type>
|
||||
<description>It's map number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-1</name>
|
||||
<type>map</type>
|
||||
<description>It's map number one.</description>
|
||||
<default>
|
||||
<a>1</a>
|
||||
<b>2</b>
|
||||
<c>3</c>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-3</name>
|
||||
<type>list</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-2</name>
|
||||
<type>list</type>
|
||||
<description>It's list number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-1</name>
|
||||
<type>list</type>
|
||||
<description>It's list number one.</description>
|
||||
<default>
|
||||
<item>a</item>
|
||||
<item>b</item>
|
||||
<item>c</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input_with_underscores</name>
|
||||
<type>any</type>
|
||||
<description>A variable with underscores.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-pipe</name>
|
||||
<type>string</type>
|
||||
<description>It includes v1 | v2 | v3</description>
|
||||
<default>v1</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-code-block</name>
|
||||
<type>list</type>
|
||||
<description>This is a complicated one. We need a newline. 
And an example in a code block
```
default = [
 "machine rack01:neptune"
]
```
</description>
|
||||
<default>
|
||||
<item>name rack:location</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>long_type</name>
|
||||
<type>object({
 name = string,
 foo = object({ foo = string, bar = string }),
 bar = object({ foo = string, bar = string }),
 fizz = list(string),
 buzz = list(string)
 })</type>
|
||||
<description>This description is itself markdown.

It spans over multiple lines.
</description>
|
||||
<default>
|
||||
<bar>
|
||||
<bar>bar</bar>
|
||||
<foo>bar</foo>
|
||||
</bar>
|
||||
<buzz>
|
||||
<item>fizz</item>
|
||||
<item>buzz</item>
|
||||
</buzz>
|
||||
<fizz></fizz>
|
||||
<foo>
|
||||
<bar>foo</bar>
|
||||
<foo>foo</foo>
|
||||
</foo>
|
||||
<name>hello</name>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>no-escape-default-value</name>
|
||||
<type>string</type>
|
||||
<description>The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'.</description>
|
||||
<default>VALUE_WITH_UNDERSCORE</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>with-url</name>
|
||||
<type>string</type>
|
||||
<description>The description contains url. https://www.domain.com/foo/bar_baz.html</description>
|
||||
<default></default>
|
||||
</input>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<output>
|
||||
<name>unquoted</name>
|
||||
<description>It's unquoted output.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-2</name>
|
||||
<description>It's output number two.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-1</name>
|
||||
<description>It's output number one.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-0.12</name>
|
||||
<description>terraform 0.12 only</description>
|
||||
</output>
|
||||
</outputs>
|
||||
<providers></providers>
|
||||
</module>
|
||||
6
internal/format/testdata/xml/xml-OnlyHeader.golden
vendored
Normal file
6
internal/format/testdata/xml/xml-OnlyHeader.golden
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
<module>
|
||||
<header>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 |</header>
|
||||
<inputs></inputs>
|
||||
<outputs></outputs>
|
||||
<providers></providers>
|
||||
</module>
|
||||
170
internal/format/testdata/xml/xml-OnlyInputs.golden
vendored
Normal file
170
internal/format/testdata/xml/xml-OnlyInputs.golden
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
<module>
|
||||
<header></header>
|
||||
<inputs>
|
||||
<input>
|
||||
<name>unquoted</name>
|
||||
<type>any</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-3</name>
|
||||
<type>bool</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-2</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number two.</description>
|
||||
<default>false</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-1</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number one.</description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-3</name>
|
||||
<type>string</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-2</name>
|
||||
<type>string</type>
|
||||
<description>It's string number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-1</name>
|
||||
<type>string</type>
|
||||
<description>It's string number one.</description>
|
||||
<default>bar</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-3</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>19</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-4</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>15.75</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-2</name>
|
||||
<type>number</type>
|
||||
<description>It's number number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-1</name>
|
||||
<type>number</type>
|
||||
<description>It's number number one.</description>
|
||||
<default>42</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-3</name>
|
||||
<type>map</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-2</name>
|
||||
<type>map</type>
|
||||
<description>It's map number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-1</name>
|
||||
<type>map</type>
|
||||
<description>It's map number one.</description>
|
||||
<default>
|
||||
<a>1</a>
|
||||
<b>2</b>
|
||||
<c>3</c>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-3</name>
|
||||
<type>list</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-2</name>
|
||||
<type>list</type>
|
||||
<description>It's list number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-1</name>
|
||||
<type>list</type>
|
||||
<description>It's list number one.</description>
|
||||
<default>
|
||||
<item>a</item>
|
||||
<item>b</item>
|
||||
<item>c</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input_with_underscores</name>
|
||||
<type>any</type>
|
||||
<description>A variable with underscores.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-pipe</name>
|
||||
<type>string</type>
|
||||
<description>It includes v1 | v2 | v3</description>
|
||||
<default>v1</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-code-block</name>
|
||||
<type>list</type>
|
||||
<description>This is a complicated one. We need a newline. 
And an example in a code block
```
default = [
 "machine rack01:neptune"
]
```
</description>
|
||||
<default>
|
||||
<item>name rack:location</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>long_type</name>
|
||||
<type>object({
 name = string,
 foo = object({ foo = string, bar = string }),
 bar = object({ foo = string, bar = string }),
 fizz = list(string),
 buzz = list(string)
 })</type>
|
||||
<description>This description is itself markdown.

It spans over multiple lines.
</description>
|
||||
<default>
|
||||
<bar>
|
||||
<bar>bar</bar>
|
||||
<foo>bar</foo>
|
||||
</bar>
|
||||
<buzz>
|
||||
<item>fizz</item>
|
||||
<item>buzz</item>
|
||||
</buzz>
|
||||
<fizz></fizz>
|
||||
<foo>
|
||||
<bar>foo</bar>
|
||||
<foo>foo</foo>
|
||||
</foo>
|
||||
<name>hello</name>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>no-escape-default-value</name>
|
||||
<type>string</type>
|
||||
<description>The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'.</description>
|
||||
<default>VALUE_WITH_UNDERSCORE</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>with-url</name>
|
||||
<type>string</type>
|
||||
<description>The description contains url. https://www.domain.com/foo/bar_baz.html</description>
|
||||
<default></default>
|
||||
</input>
|
||||
</inputs>
|
||||
<outputs></outputs>
|
||||
<providers></providers>
|
||||
</module>
|
||||
23
internal/format/testdata/xml/xml-OnlyOutputs.golden
vendored
Normal file
23
internal/format/testdata/xml/xml-OnlyOutputs.golden
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<module>
|
||||
<header></header>
|
||||
<inputs></inputs>
|
||||
<outputs>
|
||||
<output>
|
||||
<name>unquoted</name>
|
||||
<description>It's unquoted output.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-2</name>
|
||||
<description>It's output number two.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-1</name>
|
||||
<description>It's output number one.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-0.12</name>
|
||||
<description>terraform 0.12 only</description>
|
||||
</output>
|
||||
</outputs>
|
||||
<providers></providers>
|
||||
</module>
|
||||
27
internal/format/testdata/xml/xml-OnlyProviders.golden
vendored
Normal file
27
internal/format/testdata/xml/xml-OnlyProviders.golden
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<module>
|
||||
<header></header>
|
||||
<inputs></inputs>
|
||||
<outputs></outputs>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>tls</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias>ident</alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>null</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
</providers>
|
||||
</module>
|
||||
221
internal/format/testdata/xml/xml-OutputValues.golden
vendored
Normal file
221
internal/format/testdata/xml/xml-OutputValues.golden
vendored
Normal file
@@ -0,0 +1,221 @@
|
||||
<module>
|
||||
<header>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 |</header>
|
||||
<inputs>
|
||||
<input>
|
||||
<name>unquoted</name>
|
||||
<type>any</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-3</name>
|
||||
<type>bool</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-2</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number two.</description>
|
||||
<default>false</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-1</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number one.</description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-3</name>
|
||||
<type>string</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-2</name>
|
||||
<type>string</type>
|
||||
<description>It's string number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-1</name>
|
||||
<type>string</type>
|
||||
<description>It's string number one.</description>
|
||||
<default>bar</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-3</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>19</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-4</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>15.75</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-2</name>
|
||||
<type>number</type>
|
||||
<description>It's number number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-1</name>
|
||||
<type>number</type>
|
||||
<description>It's number number one.</description>
|
||||
<default>42</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-3</name>
|
||||
<type>map</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-2</name>
|
||||
<type>map</type>
|
||||
<description>It's map number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-1</name>
|
||||
<type>map</type>
|
||||
<description>It's map number one.</description>
|
||||
<default>
|
||||
<a>1</a>
|
||||
<b>2</b>
|
||||
<c>3</c>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-3</name>
|
||||
<type>list</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-2</name>
|
||||
<type>list</type>
|
||||
<description>It's list number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-1</name>
|
||||
<type>list</type>
|
||||
<description>It's list number one.</description>
|
||||
<default>
|
||||
<item>a</item>
|
||||
<item>b</item>
|
||||
<item>c</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input_with_underscores</name>
|
||||
<type>any</type>
|
||||
<description>A variable with underscores.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-pipe</name>
|
||||
<type>string</type>
|
||||
<description>It includes v1 | v2 | v3</description>
|
||||
<default>v1</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-code-block</name>
|
||||
<type>list</type>
|
||||
<description>This is a complicated one. We need a newline. 
And an example in a code block
```
default = [
 "machine rack01:neptune"
]
```
</description>
|
||||
<default>
|
||||
<item>name rack:location</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>long_type</name>
|
||||
<type>object({
 name = string,
 foo = object({ foo = string, bar = string }),
 bar = object({ foo = string, bar = string }),
 fizz = list(string),
 buzz = list(string)
 })</type>
|
||||
<description>This description is itself markdown.

It spans over multiple lines.
</description>
|
||||
<default>
|
||||
<bar>
|
||||
<bar>bar</bar>
|
||||
<foo>bar</foo>
|
||||
</bar>
|
||||
<buzz>
|
||||
<item>fizz</item>
|
||||
<item>buzz</item>
|
||||
</buzz>
|
||||
<fizz></fizz>
|
||||
<foo>
|
||||
<bar>foo</bar>
|
||||
<foo>foo</foo>
|
||||
</foo>
|
||||
<name>hello</name>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>no-escape-default-value</name>
|
||||
<type>string</type>
|
||||
<description>The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'.</description>
|
||||
<default>VALUE_WITH_UNDERSCORE</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>with-url</name>
|
||||
<type>string</type>
|
||||
<description>The description contains url. https://www.domain.com/foo/bar_baz.html</description>
|
||||
<default></default>
|
||||
</input>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<output>
|
||||
<name>unquoted</name>
|
||||
<description>It's unquoted output.</description>
|
||||
<value>
|
||||
<leon>cat</leon>
|
||||
</value>
|
||||
<sensitive>false</sensitive>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-2</name>
|
||||
<description>It's output number two.</description>
|
||||
<value>
|
||||
<item>jack</item>
|
||||
<item>lola</item>
|
||||
</value>
|
||||
<sensitive>false</sensitive>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-1</name>
|
||||
<description>It's output number one.</description>
|
||||
<value>1</value>
|
||||
<sensitive>false</sensitive>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-0.12</name>
|
||||
<description>terraform 0.12 only</description>
|
||||
<value><sensitive></value>
|
||||
<sensitive>true</sensitive>
|
||||
</output>
|
||||
</outputs>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>tls</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias>ident</alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>null</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
</providers>
|
||||
</module>
|
||||
208
internal/format/testdata/xml/xml-SortByName.golden
vendored
Normal file
208
internal/format/testdata/xml/xml-SortByName.golden
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
<module>
|
||||
<header>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 |</header>
|
||||
<inputs>
|
||||
<input>
|
||||
<name>bool-1</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number one.</description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-2</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number two.</description>
|
||||
<default>false</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-3</name>
|
||||
<type>bool</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-code-block</name>
|
||||
<type>list</type>
|
||||
<description>This is a complicated one. We need a newline. 
And an example in a code block
```
default = [
 "machine rack01:neptune"
]
```
</description>
|
||||
<default>
|
||||
<item>name rack:location</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-pipe</name>
|
||||
<type>string</type>
|
||||
<description>It includes v1 | v2 | v3</description>
|
||||
<default>v1</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input_with_underscores</name>
|
||||
<type>any</type>
|
||||
<description>A variable with underscores.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-1</name>
|
||||
<type>list</type>
|
||||
<description>It's list number one.</description>
|
||||
<default>
|
||||
<item>a</item>
|
||||
<item>b</item>
|
||||
<item>c</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-2</name>
|
||||
<type>list</type>
|
||||
<description>It's list number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-3</name>
|
||||
<type>list</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>long_type</name>
|
||||
<type>object({
 name = string,
 foo = object({ foo = string, bar = string }),
 bar = object({ foo = string, bar = string }),
 fizz = list(string),
 buzz = list(string)
 })</type>
|
||||
<description>This description is itself markdown.

It spans over multiple lines.
</description>
|
||||
<default>
|
||||
<bar>
|
||||
<bar>bar</bar>
|
||||
<foo>bar</foo>
|
||||
</bar>
|
||||
<buzz>
|
||||
<item>fizz</item>
|
||||
<item>buzz</item>
|
||||
</buzz>
|
||||
<fizz></fizz>
|
||||
<foo>
|
||||
<bar>foo</bar>
|
||||
<foo>foo</foo>
|
||||
</foo>
|
||||
<name>hello</name>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-1</name>
|
||||
<type>map</type>
|
||||
<description>It's map number one.</description>
|
||||
<default>
|
||||
<a>1</a>
|
||||
<b>2</b>
|
||||
<c>3</c>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-2</name>
|
||||
<type>map</type>
|
||||
<description>It's map number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-3</name>
|
||||
<type>map</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>no-escape-default-value</name>
|
||||
<type>string</type>
|
||||
<description>The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'.</description>
|
||||
<default>VALUE_WITH_UNDERSCORE</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-1</name>
|
||||
<type>number</type>
|
||||
<description>It's number number one.</description>
|
||||
<default>42</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-2</name>
|
||||
<type>number</type>
|
||||
<description>It's number number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-3</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>19</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-4</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>15.75</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-1</name>
|
||||
<type>string</type>
|
||||
<description>It's string number one.</description>
|
||||
<default>bar</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-2</name>
|
||||
<type>string</type>
|
||||
<description>It's string number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-3</name>
|
||||
<type>string</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>unquoted</name>
|
||||
<type>any</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>with-url</name>
|
||||
<type>string</type>
|
||||
<description>The description contains url. https://www.domain.com/foo/bar_baz.html</description>
|
||||
<default></default>
|
||||
</input>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<output>
|
||||
<name>output-0.12</name>
|
||||
<description>terraform 0.12 only</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-1</name>
|
||||
<description>It's output number one.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-2</name>
|
||||
<description>It's output number two.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>unquoted</name>
|
||||
<description>It's unquoted output.</description>
|
||||
</output>
|
||||
</outputs>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias>ident</alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>null</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>tls</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
</providers>
|
||||
</module>
|
||||
208
internal/format/testdata/xml/xml-SortByRequired.golden
vendored
Normal file
208
internal/format/testdata/xml/xml-SortByRequired.golden
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
<module>
|
||||
<header>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 |</header>
|
||||
<inputs>
|
||||
<input>
|
||||
<name>input_with_underscores</name>
|
||||
<type>any</type>
|
||||
<description>A variable with underscores.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-2</name>
|
||||
<type>list</type>
|
||||
<description>It's list number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-2</name>
|
||||
<type>map</type>
|
||||
<description>It's map number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-2</name>
|
||||
<type>number</type>
|
||||
<description>It's number number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-2</name>
|
||||
<type>string</type>
|
||||
<description>It's string number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>unquoted</name>
|
||||
<type>any</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-1</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number one.</description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-2</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number two.</description>
|
||||
<default>false</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-3</name>
|
||||
<type>bool</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-code-block</name>
|
||||
<type>list</type>
|
||||
<description>This is a complicated one. We need a newline. 
And an example in a code block
```
default = [
 "machine rack01:neptune"
]
```
</description>
|
||||
<default>
|
||||
<item>name rack:location</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-pipe</name>
|
||||
<type>string</type>
|
||||
<description>It includes v1 | v2 | v3</description>
|
||||
<default>v1</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-1</name>
|
||||
<type>list</type>
|
||||
<description>It's list number one.</description>
|
||||
<default>
|
||||
<item>a</item>
|
||||
<item>b</item>
|
||||
<item>c</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-3</name>
|
||||
<type>list</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>long_type</name>
|
||||
<type>object({
 name = string,
 foo = object({ foo = string, bar = string }),
 bar = object({ foo = string, bar = string }),
 fizz = list(string),
 buzz = list(string)
 })</type>
|
||||
<description>This description is itself markdown.

It spans over multiple lines.
</description>
|
||||
<default>
|
||||
<bar>
|
||||
<bar>bar</bar>
|
||||
<foo>bar</foo>
|
||||
</bar>
|
||||
<buzz>
|
||||
<item>fizz</item>
|
||||
<item>buzz</item>
|
||||
</buzz>
|
||||
<fizz></fizz>
|
||||
<foo>
|
||||
<bar>foo</bar>
|
||||
<foo>foo</foo>
|
||||
</foo>
|
||||
<name>hello</name>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-1</name>
|
||||
<type>map</type>
|
||||
<description>It's map number one.</description>
|
||||
<default>
|
||||
<a>1</a>
|
||||
<b>2</b>
|
||||
<c>3</c>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-3</name>
|
||||
<type>map</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>no-escape-default-value</name>
|
||||
<type>string</type>
|
||||
<description>The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'.</description>
|
||||
<default>VALUE_WITH_UNDERSCORE</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-1</name>
|
||||
<type>number</type>
|
||||
<description>It's number number one.</description>
|
||||
<default>42</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-3</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>19</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-4</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>15.75</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-1</name>
|
||||
<type>string</type>
|
||||
<description>It's string number one.</description>
|
||||
<default>bar</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-3</name>
|
||||
<type>string</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>with-url</name>
|
||||
<type>string</type>
|
||||
<description>The description contains url. https://www.domain.com/foo/bar_baz.html</description>
|
||||
<default></default>
|
||||
</input>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<output>
|
||||
<name>output-0.12</name>
|
||||
<description>terraform 0.12 only</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-1</name>
|
||||
<description>It's output number one.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-2</name>
|
||||
<description>It's output number two.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>unquoted</name>
|
||||
<description>It's unquoted output.</description>
|
||||
</output>
|
||||
</outputs>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias>ident</alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>null</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>tls</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
</providers>
|
||||
</module>
|
||||
208
internal/format/testdata/xml/xml.golden
vendored
Normal file
208
internal/format/testdata/xml/xml.golden
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
<module>
|
||||
<header>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 |</header>
|
||||
<inputs>
|
||||
<input>
|
||||
<name>unquoted</name>
|
||||
<type>any</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-3</name>
|
||||
<type>bool</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-2</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number two.</description>
|
||||
<default>false</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>bool-1</name>
|
||||
<type>bool</type>
|
||||
<description>It's bool number one.</description>
|
||||
<default>true</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-3</name>
|
||||
<type>string</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-2</name>
|
||||
<type>string</type>
|
||||
<description>It's string number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>string-1</name>
|
||||
<type>string</type>
|
||||
<description>It's string number one.</description>
|
||||
<default>bar</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-3</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>19</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-4</name>
|
||||
<type>number</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default>15.75</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-2</name>
|
||||
<type>number</type>
|
||||
<description>It's number number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>number-1</name>
|
||||
<type>number</type>
|
||||
<description>It's number number one.</description>
|
||||
<default>42</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-3</name>
|
||||
<type>map</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-2</name>
|
||||
<type>map</type>
|
||||
<description>It's map number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>map-1</name>
|
||||
<type>map</type>
|
||||
<description>It's map number one.</description>
|
||||
<default>
|
||||
<a>1</a>
|
||||
<b>2</b>
|
||||
<c>3</c>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-3</name>
|
||||
<type>list</type>
|
||||
<description xsi:nil="true"></description>
|
||||
<default></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-2</name>
|
||||
<type>list</type>
|
||||
<description>It's list number two.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>list-1</name>
|
||||
<type>list</type>
|
||||
<description>It's list number one.</description>
|
||||
<default>
|
||||
<item>a</item>
|
||||
<item>b</item>
|
||||
<item>c</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input_with_underscores</name>
|
||||
<type>any</type>
|
||||
<description>A variable with underscores.</description>
|
||||
<default xsi:nil="true"></default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-pipe</name>
|
||||
<type>string</type>
|
||||
<description>It includes v1 | v2 | v3</description>
|
||||
<default>v1</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>input-with-code-block</name>
|
||||
<type>list</type>
|
||||
<description>This is a complicated one. We need a newline. 
And an example in a code block
```
default = [
 "machine rack01:neptune"
]
```
</description>
|
||||
<default>
|
||||
<item>name rack:location</item>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>long_type</name>
|
||||
<type>object({
 name = string,
 foo = object({ foo = string, bar = string }),
 bar = object({ foo = string, bar = string }),
 fizz = list(string),
 buzz = list(string)
 })</type>
|
||||
<description>This description is itself markdown.

It spans over multiple lines.
</description>
|
||||
<default>
|
||||
<bar>
|
||||
<bar>bar</bar>
|
||||
<foo>bar</foo>
|
||||
</bar>
|
||||
<buzz>
|
||||
<item>fizz</item>
|
||||
<item>buzz</item>
|
||||
</buzz>
|
||||
<fizz></fizz>
|
||||
<foo>
|
||||
<bar>foo</bar>
|
||||
<foo>foo</foo>
|
||||
</foo>
|
||||
<name>hello</name>
|
||||
</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>no-escape-default-value</name>
|
||||
<type>string</type>
|
||||
<description>The description contains `something_with_underscore`. Defaults to 'VALUE_WITH_UNDERSCORE'.</description>
|
||||
<default>VALUE_WITH_UNDERSCORE</default>
|
||||
</input>
|
||||
<input>
|
||||
<name>with-url</name>
|
||||
<type>string</type>
|
||||
<description>The description contains url. https://www.domain.com/foo/bar_baz.html</description>
|
||||
<default></default>
|
||||
</input>
|
||||
</inputs>
|
||||
<outputs>
|
||||
<output>
|
||||
<name>unquoted</name>
|
||||
<description>It's unquoted output.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-2</name>
|
||||
<description>It's output number two.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-1</name>
|
||||
<description>It's output number one.</description>
|
||||
</output>
|
||||
<output>
|
||||
<name>output-0.12</name>
|
||||
<description>terraform 0.12 only</description>
|
||||
</output>
|
||||
</outputs>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>tls</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>aws</name>
|
||||
<alias>ident</alias>
|
||||
<version>>= 2.15.0</version>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>null</name>
|
||||
<alias xsi:nil="true"></alias>
|
||||
<version xsi:nil="true"></version>
|
||||
</provider>
|
||||
</providers>
|
||||
</module>
|
||||
47
internal/format/xml.go
Normal file
47
internal/format/xml.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package format
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
|
||||
"github.com/segmentio/terraform-docs/pkg/print"
|
||||
"github.com/segmentio/terraform-docs/pkg/tfconf"
|
||||
)
|
||||
|
||||
// XML represents XML format.
|
||||
type XML struct{}
|
||||
|
||||
// NewXML returns new instance of XML.
|
||||
func NewXML(settings *print.Settings) *XML {
|
||||
return &XML{}
|
||||
}
|
||||
|
||||
// Print prints a Terraform module as xml.
|
||||
func (x *XML) Print(module *tfconf.Module, settings *print.Settings) (string, error) {
|
||||
copy := &tfconf.Module{
|
||||
Header: "",
|
||||
Providers: make([]*tfconf.Provider, 0),
|
||||
Inputs: make([]*tfconf.Input, 0),
|
||||
Outputs: make([]*tfconf.Output, 0),
|
||||
}
|
||||
|
||||
if settings.ShowHeader {
|
||||
copy.Header = module.Header
|
||||
}
|
||||
if settings.ShowProviders {
|
||||
copy.Providers = module.Providers
|
||||
}
|
||||
if settings.ShowInputs {
|
||||
copy.Inputs = module.Inputs
|
||||
}
|
||||
if settings.ShowOutputs {
|
||||
copy.Outputs = module.Outputs
|
||||
}
|
||||
|
||||
out, err := xml.MarshalIndent(copy, "", " ")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.TrimSuffix(string(out), "\n"), nil
|
||||
}
|
||||
285
internal/format/xml_test.go
Normal file
285
internal/format/xml_test.go
Normal file
@@ -0,0 +1,285 @@
|
||||
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 TestXml(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().WithSections().Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions()
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlSortByName(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().WithSections().With(&print.Settings{
|
||||
SortByName: true,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-SortByName")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions().With(&module.Options{
|
||||
SortBy: &module.SortBy{
|
||||
Name: true,
|
||||
},
|
||||
})
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlSortByRequired(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().WithSections().With(&print.Settings{
|
||||
SortByName: true,
|
||||
SortByRequired: true,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-SortByRequired")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions().With(&module.Options{
|
||||
SortBy: &module.SortBy{
|
||||
Name: true,
|
||||
Required: true,
|
||||
},
|
||||
})
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlNoHeader(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().With(&print.Settings{
|
||||
ShowHeader: false,
|
||||
ShowProviders: true,
|
||||
ShowInputs: true,
|
||||
ShowOutputs: true,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-NoHeader")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions()
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlNoProviders(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().With(&print.Settings{
|
||||
ShowHeader: true,
|
||||
ShowProviders: false,
|
||||
ShowInputs: true,
|
||||
ShowOutputs: true,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-NoProviders")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions()
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlNoInputs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().With(&print.Settings{
|
||||
ShowHeader: true,
|
||||
ShowProviders: true,
|
||||
ShowInputs: false,
|
||||
ShowOutputs: true,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-NoInputs")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions()
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlNoOutputs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().With(&print.Settings{
|
||||
ShowHeader: true,
|
||||
ShowProviders: true,
|
||||
ShowInputs: true,
|
||||
ShowOutputs: false,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-NoOutputs")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions()
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlOnlyHeader(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().With(&print.Settings{
|
||||
ShowHeader: true,
|
||||
ShowProviders: false,
|
||||
ShowInputs: false,
|
||||
ShowOutputs: false,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-OnlyHeader")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions()
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlOnlyProviders(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().With(&print.Settings{
|
||||
ShowHeader: false,
|
||||
ShowProviders: true,
|
||||
ShowInputs: false,
|
||||
ShowOutputs: false,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-OnlyProviders")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions()
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlOnlyInputs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().With(&print.Settings{
|
||||
ShowHeader: false,
|
||||
ShowProviders: false,
|
||||
ShowInputs: true,
|
||||
ShowOutputs: false,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-OnlyInputs")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions()
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlOnlyOutputs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().With(&print.Settings{
|
||||
ShowHeader: false,
|
||||
ShowProviders: false,
|
||||
ShowInputs: false,
|
||||
ShowOutputs: true,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-OnlyOutputs")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions()
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
|
||||
func TestXmlOutputValues(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
settings := testutil.Settings().WithSections().With(&print.Settings{
|
||||
OutputValues: true,
|
||||
}).Build()
|
||||
|
||||
expected, err := testutil.GetExpected("xml", "xml-OutputValues")
|
||||
assert.Nil(err)
|
||||
|
||||
options := module.NewOptions().With(&module.Options{
|
||||
OutputValues: true,
|
||||
OutputValuesPath: "output_values.json",
|
||||
})
|
||||
module, err := testutil.GetModule(options)
|
||||
assert.Nil(err)
|
||||
|
||||
printer := NewXML(settings)
|
||||
actual, err := printer.Print(module, settings)
|
||||
|
||||
assert.Nil(err)
|
||||
assert.Equal(expected, actual)
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"go/types"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -21,10 +23,9 @@ type Value interface {
|
||||
HasDefault() bool
|
||||
}
|
||||
|
||||
// ValueOf returns actual value of a variable
|
||||
// casted to 'Value' interface. This is done
|
||||
// to be able to attach specific marshaller func
|
||||
// to the type (if such a custom function was needed)
|
||||
// ValueOf returns actual value of a variable casted to 'Default' interface.
|
||||
// This is done to be able to attach specific marshaller func to the type
|
||||
// (if such a custom function was needed)
|
||||
func ValueOf(v interface{}) Value {
|
||||
if v == nil {
|
||||
return new(Nil)
|
||||
@@ -50,9 +51,8 @@ func ValueOf(v interface{}) Value {
|
||||
return new(Nil)
|
||||
}
|
||||
|
||||
// TypeOf returns Terraform type of a value
|
||||
// based on provided type by terraform-inspect
|
||||
// or by looking the underlying type of the value
|
||||
// TypeOf returns Terraform type of a value based on provided type by
|
||||
// terraform-inspect or by looking the underlying type of the value
|
||||
func TypeOf(t string, v interface{}) String {
|
||||
if t != "" {
|
||||
return String(t)
|
||||
@@ -74,9 +74,7 @@ func TypeOf(t string, v interface{}) String {
|
||||
return String("any")
|
||||
}
|
||||
|
||||
// Nil represents a 'nil' value which is
|
||||
// marshaled to `null` when empty for JSON
|
||||
// and YAML
|
||||
// Nil represents a 'nil' value which is marshaled to `null` when empty for JSON and YAML
|
||||
type Nil types.Nil
|
||||
|
||||
// HasDefault return false for Nil, because there's no value set for the variable
|
||||
@@ -84,21 +82,24 @@ func (n Nil) HasDefault() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// MarshalJSON custom marshal function which
|
||||
// sets the value to literal `null`
|
||||
// MarshalJSON custom marshal function which sets the value to literal `null`
|
||||
func (n Nil) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`null`), nil
|
||||
}
|
||||
|
||||
// MarshalYAML custom marshal function which
|
||||
// sets the value to literal `null`
|
||||
// MarshalXML custom marshal function which adds property 'xsi:nil="true"' to a tag
|
||||
// of a 'nil' item
|
||||
func (n Nil) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xsi:nil"}, Value: "true"})
|
||||
return e.EncodeElement(``, start)
|
||||
}
|
||||
|
||||
// MarshalYAML custom marshal function which sets the value to literal `null`
|
||||
func (n Nil) MarshalYAML() (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// String represents a 'string' value which is
|
||||
// marshaled to `null` when empty for JSON and
|
||||
// YAML
|
||||
// String represents a 'string' value which is marshaled to `null` when empty for JSON and YAML
|
||||
type String string
|
||||
|
||||
// String returns s as an actual string value
|
||||
@@ -116,8 +117,7 @@ func (s String) HasDefault() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// MarshalJSON custom marshal function which
|
||||
// sets the value to literal `null` when empty
|
||||
// MarshalJSON custom marshal function which sets the value to literal `null` when empty
|
||||
func (s String) MarshalJSON() ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
if len(s.String()) == 0 {
|
||||
@@ -131,8 +131,17 @@ func (s String) MarshalJSON() ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// MarshalYAML custom marshal function which
|
||||
// sets the value to literal `null` when empty
|
||||
// MarshalXML custom marshal function which adds property 'xsi:nil="true"' to a tag
|
||||
// if the underlying item is 'nil'
|
||||
func (s String) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
if string(s) == "" {
|
||||
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xsi:nil"}, Value: "true"})
|
||||
return e.EncodeElement(``, start)
|
||||
}
|
||||
return e.EncodeElement(string(s), start)
|
||||
}
|
||||
|
||||
// MarshalYAML custom marshal function which sets the value to literal `null` when empty
|
||||
func (s String) MarshalYAML() (interface{}, error) {
|
||||
if len(s.String()) == 0 {
|
||||
return nil, nil
|
||||
@@ -140,8 +149,7 @@ func (s String) MarshalYAML() (interface{}, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Empty represents an empty 'string' which is
|
||||
// marshaled to `""` in JSON and YAML
|
||||
// Empty represents an empty 'string' which is marshaled to `""` in JSON and YAML
|
||||
type Empty string
|
||||
|
||||
// nolint
|
||||
@@ -154,14 +162,12 @@ func (e Empty) HasDefault() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// MarshalJSON custom marshal function which
|
||||
// sets the value to `""`
|
||||
// MarshalJSON custom marshal function which sets the value to `""`
|
||||
func (e Empty) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`""`), nil
|
||||
}
|
||||
|
||||
// Number represents a 'number' value which is
|
||||
// marshaled to `null` when emty in JSON and YAML
|
||||
// Number represents a 'number' value which is marshaled to `null` when emty in JSON and YAML
|
||||
type Number float64
|
||||
|
||||
// nolint
|
||||
@@ -204,6 +210,27 @@ func (l List) HasDefault() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type xmllistentry struct {
|
||||
XMLName xml.Name
|
||||
Value interface{} `xml:",chardata"`
|
||||
}
|
||||
|
||||
// MarshalXML custom marshal function which wraps list items in '<default></default>'
|
||||
// tag and each items of the list will be wrapped in a '<item></item>' tag
|
||||
func (l List) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
if len(l) == 0 {
|
||||
return e.EncodeElement(``, start)
|
||||
}
|
||||
err := e.EncodeToken(start)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, i := range l {
|
||||
e.Encode(xmllistentry{XMLName: xml.Name{Local: "item"}, Value: i}) //nolint: errcheck
|
||||
}
|
||||
return e.EncodeToken(start.End())
|
||||
}
|
||||
|
||||
// Map represents a 'map' of values
|
||||
type Map map[string]interface{}
|
||||
|
||||
@@ -220,3 +247,64 @@ func (m Map) underlying() map[string]interface{} {
|
||||
func (m Map) HasDefault() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type xmlmapentry struct {
|
||||
XMLName xml.Name
|
||||
Value interface{} `xml:",chardata"`
|
||||
}
|
||||
|
||||
type sortmapkeys []string
|
||||
|
||||
func (s sortmapkeys) Len() int { return len(s) }
|
||||
func (s sortmapkeys) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s sortmapkeys) Less(i, j int) bool { return s[i] < s[j] }
|
||||
|
||||
// MarshalXML custom marshal function which converts map to its literal
|
||||
// XML representation. For example:
|
||||
//
|
||||
// m := Map{
|
||||
// "a": 1,
|
||||
// "b": 2,
|
||||
// "c": 3,
|
||||
// }
|
||||
//
|
||||
// type foo struct {
|
||||
// Value Map `xml:"value"`
|
||||
// }
|
||||
//
|
||||
// will get marshaled to:
|
||||
//
|
||||
// <foo>
|
||||
// <value>
|
||||
// <a>1</a>
|
||||
// <b>2</b>
|
||||
// <c>3</c>
|
||||
// </value>
|
||||
// </foo>
|
||||
func (m Map) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
if len(m) == 0 {
|
||||
return e.EncodeElement(``, start)
|
||||
}
|
||||
err := e.EncodeToken(start)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
keys := make([]string, 0)
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Sort(sortmapkeys(keys))
|
||||
for _, k := range keys {
|
||||
switch reflect.TypeOf(m[k]).Kind() {
|
||||
case reflect.Map:
|
||||
is := xml.StartElement{Name: xml.Name{Local: k}}
|
||||
Map(m[k].(map[string]interface{})).MarshalXML(e, is) //nolint: errcheck
|
||||
case reflect.Slice:
|
||||
is := xml.StartElement{Name: xml.Name{Local: k}}
|
||||
List(m[k].([]interface{})).MarshalXML(e, is) //nolint: errcheck
|
||||
default:
|
||||
e.Encode(xmlmapentry{XMLName: xml.Name{Local: k}, Value: m[k]}) //nolint: errcheck
|
||||
}
|
||||
}
|
||||
return e.EncodeToken(start.End())
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
|
||||
// Input represents a Terraform input.
|
||||
type Input struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Type types.String `json:"type" yaml:"type"`
|
||||
Description types.String `json:"description" yaml:"description"`
|
||||
Default types.Value `json:"default" yaml:"default"`
|
||||
Position Position `json:"-" yaml:"-"`
|
||||
Name string `json:"name" xml:"name" yaml:"name"`
|
||||
Type types.String `json:"type" xml:"type" yaml:"type"`
|
||||
Description types.String `json:"description" xml:"description" yaml:"description"`
|
||||
Default types.Value `json:"default" xml:"default" yaml:"default"`
|
||||
Position Position `json:"-" xml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
// GetValue returns JSON representation of the 'Default' value, which is an 'interface'.
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
package tfconf
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
// Module represents a Terraform module. It consists of
|
||||
// - Header ('header' json key): Module header found in shape of multi line comments at the beginning of 'main.tf'
|
||||
// - Inputs ('inputs' json key): List of input 'variables' extracted from the Terraform module .tf files
|
||||
// - Outputs ('outputs' json key): List of 'outputs' extracted from Terraform module .tf files
|
||||
// - Providers ('providers' json key): List of 'providers' extracted from resources used in Terraform module
|
||||
type Module struct {
|
||||
Header string `json:"header" yaml:"header"`
|
||||
Inputs []*Input `json:"inputs" yaml:"inputs"`
|
||||
Outputs []*Output `json:"outputs" yaml:"outputs"`
|
||||
Providers []*Provider `json:"providers" yaml:"providers"`
|
||||
XMLName xml.Name `json:"-" xml:"module" yaml:"-"`
|
||||
|
||||
RequiredInputs []*Input `json:"-" yaml:"-"`
|
||||
OptionalInputs []*Input `json:"-" yaml:"-"`
|
||||
Header string `json:"header" xml:"header" yaml:"header"`
|
||||
Inputs []*Input `json:"inputs" xml:"inputs>input" yaml:"inputs"`
|
||||
Outputs []*Output `json:"outputs" xml:"outputs>output" yaml:"outputs"`
|
||||
Providers []*Provider `json:"providers" xml:"providers>provider" yaml:"providers"`
|
||||
|
||||
RequiredInputs []*Input `json:"-" xml:"-" yaml:"-"`
|
||||
OptionalInputs []*Input `json:"-" xml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
// HasHeader indicates if the module has header.
|
||||
|
||||
@@ -3,27 +3,28 @@ package tfconf
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
|
||||
"github.com/segmentio/terraform-docs/internal/types"
|
||||
)
|
||||
|
||||
// Output represents a Terraform output.
|
||||
type Output struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Description types.String `json:"description" yaml:"description"`
|
||||
Value types.Value `json:"value,omitempty" yaml:"value,omitempty"`
|
||||
Sensitive bool `json:"sensitive,omitempty" yaml:"sensitive,omitempty"`
|
||||
Position Position `json:"-" yaml:"-"`
|
||||
ShowValue bool `json:"-" yaml:"-"`
|
||||
Name string `json:"name" xml:"name" yaml:"name"`
|
||||
Description types.String `json:"description" xml:"description" yaml:"description"`
|
||||
Value types.Value `json:"value,omitempty" xml:"value,omitempty" yaml:"value,omitempty"`
|
||||
Sensitive bool `json:"sensitive,omitempty" xml:"sensitive,omitempty" yaml:"sensitive,omitempty"`
|
||||
Position Position `json:"-" xml:"-" yaml:"-"`
|
||||
ShowValue bool `json:"-" xml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
type withvalue struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Description types.String `json:"description" yaml:"description"`
|
||||
Value types.Value `json:"value" yaml:"value"`
|
||||
Sensitive bool `json:"sensitive" yaml:"sensitive"`
|
||||
Position Position `json:"-" yaml:"-"`
|
||||
ShowValue bool `json:"-" yaml:"-"`
|
||||
Name string `json:"name" xml:"name" yaml:"name"`
|
||||
Description types.String `json:"description" xml:"description" yaml:"description"`
|
||||
Value types.Value `json:"value" xml:"value" yaml:"value"`
|
||||
Sensitive bool `json:"sensitive" xml:"sensitive" yaml:"sensitive"`
|
||||
Position Position `json:"-" xml:"-" yaml:"-"`
|
||||
ShowValue bool `json:"-" xml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
// GetValue returns JSON representation of the 'Value', which is an 'interface'.
|
||||
@@ -65,7 +66,29 @@ func (o *Output) MarshalJSON() ([]byte, error) {
|
||||
return fn(withvalue(*o))
|
||||
}
|
||||
return fn(*o)
|
||||
}
|
||||
|
||||
// MarshalXML custom xml marshal function to take
|
||||
// '--output-values' flag into consideration. It means
|
||||
// if the flag is not set Value and Sensitive fields
|
||||
// are set to 'omitempty', otherwise if output values
|
||||
// are being shown 'omitempty' gets explicitly removed
|
||||
// to show even empty and false values.
|
||||
func (o *Output) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
fn := func(v interface{}, name string) error {
|
||||
return e.EncodeElement(v, xml.StartElement{Name: xml.Name{Local: name}})
|
||||
}
|
||||
err := e.EncodeToken(start)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fn(o.Name, "name") //nolint: errcheck
|
||||
fn(o.Description, "description") //nolint: errcheck
|
||||
if o.ShowValue {
|
||||
fn(o.Value, "value") //nolint: errcheck
|
||||
fn(o.Sensitive, "sensitive") //nolint: errcheck
|
||||
}
|
||||
return e.EncodeToken(start.End())
|
||||
}
|
||||
|
||||
// MarshalYAML custom yaml marshal function to take
|
||||
|
||||
@@ -2,6 +2,6 @@ package tfconf
|
||||
|
||||
// Position represents position of Terraform input or output in a file.
|
||||
type Position struct {
|
||||
Filename string `json:"-" yaml:"-"`
|
||||
Line int `json:"-" yaml:"-"`
|
||||
Filename string `json:"-" xml:"-" yaml:"-"`
|
||||
Line int `json:"-" xml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
|
||||
// Provider represents a Terraform output.
|
||||
type Provider struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Alias types.String `json:"alias" yaml:"alias"`
|
||||
Version types.String `json:"version" yaml:"version"`
|
||||
Position Position `json:"-" yaml:"-"`
|
||||
Name string `json:"name" xml:"name" yaml:"name"`
|
||||
Alias types.String `json:"alias" xml:"alias" yaml:"alias"`
|
||||
Version types.String `json:"version" xml:"version" yaml:"version"`
|
||||
Position Position `json:"-" xml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
// FullName returns full name of the provider, with alias if available
|
||||
|
||||
@@ -131,6 +131,8 @@ func getPrinter(name string, settings *print.Settings) print.Format {
|
||||
return format.NewTable(settings)
|
||||
case "pretty":
|
||||
return format.NewPretty(settings)
|
||||
case "xml":
|
||||
return format.NewXML(settings)
|
||||
case "yaml":
|
||||
return format.NewYAML(settings)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user