Repository: segmentio/terraform-docs
Pull request #243 (2020-04-10 19:47:22)

Add factory function to return format types
### Prerequisites

Put an `x` into the box(es) that apply:

- [ ] This pull request fixes a bug.
- [ ] This pull request adds a feature.
- [x] This pull request enhances existing functionality.
- [ ] This pull request introduces breaking change.

For more information, see the [Contributing Guide](https://github.com/segmentio/terraform-docs/tree/master/CONTRIBUTING.md).

### Description

This PR adds a new factory function as `format.Factory()` as a helper method to consolidate the creation of format types of interface `print.Format`.

### Issues Resolved

List any existing issues this pull request resolves.

### Checklist

Put an `x` into all boxes that apply:

- [ ] I have read the [Contributing Guidelines](https://github.com/segmentio/terraform-docs/tree/master/CONTRIBUTING.md).

#### Tests

- [x] I have added tests to cover my changes.
- [x] All tests pass when I run `make test`.

#### Documentation

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.

#### Code Style

- [ ] My code follows the code style of this project.


codecov-io: # [Codecov](https://codecov.io/gh/segmentio/terraform-docs/pull/243?src=pr&el=h1) Report
> Merging [#243](https://codecov.io/gh/segmentio/terraform-docs/pull/243?src=pr&el=desc) into [master](https://codecov.io/gh/segmentio/terraform-docs/commit/f060a2df4d539da0cdfd177a34ca31eb6c8d28f1&el=desc) will **increase** coverage by `0.25%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master     #243      +/-   ##
==========================================
+ Coverage   80.36%   80.61%   +0.25%     
==========================================
  Files          30       31       +1     
  Lines        1594     1615      +21     
==========================================
+ Hits         1281     1302      +21     
  Misses        263      263              
  Partials       50       50              
```


| [Impacted Files](https://codecov.io/gh/segmentio/terraform-docs/pull/243?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/format/factory.go](https://codecov.io/gh/segmentio/terraform-docs/pull/243/diff?src=pr&el=tree#diff-aW50ZXJuYWwvZm9ybWF0L2ZhY3RvcnkuZ28=) | `100.00% <100.00%> (ø)` | |


Patch:
diff --git a/cmd/json.go b/cmd/json.go
index 949eef3..1712146 100644
--- a/cmd/json.go
+++ b/cmd/json.go
@@ -1,20 +1,15 @@
 package cmd
 
 import (
-	"github.com/segmentio/terraform-docs/internal/format"
 	"github.com/spf13/cobra"
 )
 
 var jsonCmd = &cobra.Command{
-	Args:  cobra.ExactArgs(1),
-	Use:   "json [PATH]",
-	Short: "Generate JSON of inputs and outputs",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
-	RunE: func(cmd *cobra.Command, args []string) error {
-		return doPrint(args[0], format.NewJSON(settings))
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "json [PATH]",
+	Short:       "Generate JSON of inputs and outputs",
+	Annotations: formatAnnotations("json"),
+	RunE:        formatRunE,
 }
 
 func init() {
diff --git a/cmd/markdown.go b/cmd/markdown.go
index 20d287c..3e4baec 100644
--- a/cmd/markdown.go
+++ b/cmd/markdown.go
@@ -1,47 +1,34 @@
 package cmd
 
 import (
-	"github.com/segmentio/terraform-docs/internal/format"
 	"github.com/spf13/cobra"
 )
 
 var markdownCmd = &cobra.Command{
-	Args:    cobra.ExactArgs(1),
-	Use:     "markdown [PATH]",
-	Aliases: []string{"md"},
-	Short:   "Generate Markdown of inputs and outputs",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
-	RunE: func(cmd *cobra.Command, args []string) error {
-		return doPrint(args[0], format.NewTable(settings))
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "markdown [PATH]",
+	Aliases:     []string{"md"},
+	Short:       "Generate Markdown of inputs and outputs",
+	Annotations: formatAnnotations("markdown"),
+	RunE:        formatRunE,
 }
 
 var markdownTableCmd = &cobra.Command{
-	Args:    cobra.ExactArgs(1),
-	Use:     "table [PATH]",
-	Aliases: []string{"tbl"},
-	Short:   "Generate Markdown tables of inputs and outputs",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
-	RunE: func(cmd *cobra.Command, args []string) error {
-		return doPrint(args[0], format.NewTable(settings))
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "table [PATH]",
+	Aliases:     []string{"tbl"},
+	Short:       "Generate Markdown tables of inputs and outputs",
+	Annotations: formatAnnotations("markdown table"),
+	RunE:        formatRunE,
 }
 
 var markdownDocumentCmd = &cobra.Command{
-	Args:    cobra.ExactArgs(1),
-	Use:     "document [PATH]",
-	Aliases: []string{"doc"},
-	Short:   "Generate Markdown document of inputs and outputs",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
-	RunE: func(cmd *cobra.Command, args []string) error {
-		return doPrint(args[0], format.NewDocument(settings))
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "document [PATH]",
+	Aliases:     []string{"doc"},
+	Short:       "Generate Markdown document of inputs and outputs",
+	Annotations: formatAnnotations("markdown document"),
+	RunE:        formatRunE,
 }
 
 func init() {
diff --git a/cmd/pretty.go b/cmd/pretty.go
index 45ca5fd..247dab2 100644
--- a/cmd/pretty.go
+++ b/cmd/pretty.go
@@ -1,20 +1,15 @@
 package cmd
 
 import (
-	"github.com/segmentio/terraform-docs/internal/format"
 	"github.com/spf13/cobra"
 )
 
 var prettyCmd = &cobra.Command{
-	Args:  cobra.ExactArgs(1),
-	Use:   "pretty [PATH]",
-	Short: "Generate colorized pretty of inputs and outputs",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
-	RunE: func(cmd *cobra.Command, args []string) error {
-		return doPrint(args[0], format.NewPretty(settings))
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "pretty [PATH]",
+	Short:       "Generate colorized pretty of inputs and outputs",
+	Annotations: formatAnnotations("pretty"),
+	RunE:        formatRunE,
 }
 
 func init() {
diff --git a/cmd/root.go b/cmd/root.go
index 1054337..c8d67e2 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -2,7 +2,9 @@ package cmd
 
 import (
 	"fmt"
+	"strings"
 
+	"github.com/segmentio/terraform-docs/internal/format"
 	"github.com/segmentio/terraform-docs/internal/module"
 	"github.com/segmentio/terraform-docs/internal/version"
 	"github.com/segmentio/terraform-docs/pkg/print"
@@ -80,9 +82,14 @@ func RootCmd() *cobra.Command {
 	return rootCmd
 }
 
-func doPrint(path string, printer print.Format) error {
-	_, err := options.With(&module.Options{
-		Path: path,
+var formatRunE = func(cmd *cobra.Command, args []string) error {
+	name := strings.Replace(cmd.CommandPath(), "terraform-docs ", "", -1)
+	printer, err := format.Factory(name, settings)
+	if err != nil {
+		return err
+	}
+	_, err = options.With(&module.Options{
+		Path: args[0],
 		SortBy: &module.SortBy{
 			Name:     settings.SortByName,
 			Required: settings.SortByRequired,
@@ -102,3 +109,12 @@ func doPrint(path string, printer print.Format) error {
 	fmt.Println(output)
 	return nil
 }
+
+var formatAnnotations = func(cmd string) map[string]string {
+	annotations := make(map[string]string)
+	for _, s := range strings.Split(cmd, " ") {
+		annotations["command"] = s
+	}
+	annotations["kind"] = "formatter"
+	return annotations
+}
diff --git a/cmd/tfvars.go b/cmd/tfvars.go
index 80b4e4d..c988e6b 100644
--- a/cmd/tfvars.go
+++ b/cmd/tfvars.go
@@ -1,41 +1,30 @@
 package cmd
 
 import (
-	"github.com/segmentio/terraform-docs/internal/format"
 	"github.com/spf13/cobra"
 )
 
 var tfvarsCmd = &cobra.Command{
-	Args:  cobra.ExactArgs(1),
-	Use:   "tfvars [PATH]",
-	Short: "Generate terraform.tfvars of inputs",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "tfvars [PATH]",
+	Short:       "Generate terraform.tfvars of inputs",
+	Annotations: formatAnnotations("tfvars"),
 }
 
 var tfvarsHCLCmd = &cobra.Command{
-	Args:  cobra.ExactArgs(1),
-	Use:   "hcl [PATH]",
-	Short: "Generate HCL format of terraform.tfvars of inputs",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
-	RunE: func(cmd *cobra.Command, args []string) error {
-		return doPrint(args[0], format.NewTfvarsHCL(settings))
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "hcl [PATH]",
+	Short:       "Generate HCL format of terraform.tfvars of inputs",
+	Annotations: formatAnnotations("tfvars hcl"),
+	RunE:        formatRunE,
 }
 
 var tfvarsJSONCmd = &cobra.Command{
-	Args:  cobra.ExactArgs(1),
-	Use:   "json [PATH]",
-	Short: "Generate JSON format of terraform.tfvars of inputs",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
-	RunE: func(cmd *cobra.Command, args []string) error {
-		return doPrint(args[0], format.NewTfvarsJSON(settings))
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "json [PATH]",
+	Short:       "Generate JSON format of terraform.tfvars of inputs",
+	Annotations: formatAnnotations("tfvars json"),
+	RunE:        formatRunE,
 }
 
 func init() {
diff --git a/cmd/xml.go b/cmd/xml.go
index daafb9b..38f4937 100644
--- a/cmd/xml.go
+++ b/cmd/xml.go
@@ -1,20 +1,15 @@
 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",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
-	RunE: func(cmd *cobra.Command, args []string) error {
-		return doPrint(args[0], format.NewXML(settings))
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "xml [PATH]",
+	Short:       "Generate XML of inputs and outputs",
+	Annotations: formatAnnotations("xml"),
+	RunE:        formatRunE,
 }
 
 func init() {
diff --git a/cmd/yaml.go b/cmd/yaml.go
index 1ec5586..1433132 100644
--- a/cmd/yaml.go
+++ b/cmd/yaml.go
@@ -1,20 +1,15 @@
 package cmd
 
 import (
-	"github.com/segmentio/terraform-docs/internal/format"
 	"github.com/spf13/cobra"
 )
 
 var yamlCmd = &cobra.Command{
-	Args:  cobra.ExactArgs(1),
-	Use:   "yaml [PATH]",
-	Short: "Generate YAML of inputs and outputs",
-	Annotations: map[string]string{
-		"kind": "formatter",
-	},
-	RunE: func(cmd *cobra.Command, args []string) error {
-		return doPrint(args[0], format.NewYAML(settings))
-	},
+	Args:        cobra.ExactArgs(1),
+	Use:         "yaml [PATH]",
+	Short:       "Generate YAML of inputs and outputs",
+	Annotations: formatAnnotations("yaml"),
+	RunE:        formatRunE,
 }
 
 func init() {
diff --git a/docs/FORMATS_GUIDE.md b/docs/FORMATS_GUIDE.md
index 44957ed..eddcac9 100644
--- a/docs/FORMATS_GUIDE.md
+++ b/docs/FORMATS_GUIDE.md
@@ -37,4 +37,4 @@ A utility to generate documentation from Terraform modules in various output for
 * [terraform-docs xml](/docs/formats/xml.md)	 - Generate XML of inputs and outputs
 * [terraform-docs yaml](/docs/formats/yaml.md)	 - Generate YAML of inputs and outputs
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/json.md b/docs/formats/json.md
index fe6b22a..a1c5167 100644
--- a/docs/formats/json.md
+++ b/docs/formats/json.md
@@ -331,9 +331,13 @@ generates the following output:
         {
           "name": "aws",
           "version": "\u003e= 2.15.0"
+        },
+        {
+          "name": "random",
+          "version": "\u003e= 2.2.0"
         }
       ]
     }
 
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/markdown-document.md b/docs/formats/markdown-document.md
index 673ff95..dc284d6 100644
--- a/docs/formats/markdown-document.md
+++ b/docs/formats/markdown-document.md
@@ -93,6 +93,8 @@ generates the following output:
 
     - aws (>= 2.15.0)
 
+    - random (>= 2.2.0)
+
     ## Providers
 
     The following providers are used by this module:
@@ -420,4 +422,4 @@ generates the following output:
 
 
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/markdown-table.md b/docs/formats/markdown-table.md
index 4727e2b..bcc815c 100644
--- a/docs/formats/markdown-table.md
+++ b/docs/formats/markdown-table.md
@@ -91,6 +91,7 @@ generates the following output:
     |------|---------|
     | terraform | >= 0.12 |
     | aws | >= 2.15.0 |
+    | random | >= 2.2.0 |
 
     ## Providers
 
@@ -147,4 +148,4 @@ generates the following output:
 
 
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/markdown.md b/docs/formats/markdown.md
index 9f24c2f..20f600a 100644
--- a/docs/formats/markdown.md
+++ b/docs/formats/markdown.md
@@ -42,4 +42,4 @@ terraform-docs markdown [PATH] [flags]
 * [terraform-docs markdown document](/docs/formats/markdown-document.md)	 - Generate Markdown document of inputs and outputs
 * [terraform-docs markdown table](/docs/formats/markdown-table.md)	 - Generate Markdown tables of inputs and outputs
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/pretty.md b/docs/formats/pretty.md
index e14654b..0a8b261 100644
--- a/docs/formats/pretty.md
+++ b/docs/formats/pretty.md
@@ -90,6 +90,8 @@ generates the following output:
 
     requirement.aws (>= 2.15.0)
 
+    requirement.random (>= 2.2.0)
+
 
 
     provider.aws (>= 2.15.0)
@@ -242,4 +244,4 @@ generates the following output:
 
 
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/tfvars-hcl.md b/docs/formats/tfvars-hcl.md
index c998d96..ad5529c 100644
--- a/docs/formats/tfvars-hcl.md
+++ b/docs/formats/tfvars-hcl.md
@@ -100,4 +100,4 @@ generates the following output:
     with-url                = ""
 
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/tfvars-json.md b/docs/formats/tfvars-json.md
index 2b89a3b..40babf3 100644
--- a/docs/formats/tfvars-json.md
+++ b/docs/formats/tfvars-json.md
@@ -102,4 +102,4 @@ generates the following output:
     }
 
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/tfvars.md b/docs/formats/tfvars.md
index 3a32fac..b6e6e27 100644
--- a/docs/formats/tfvars.md
+++ b/docs/formats/tfvars.md
@@ -34,4 +34,4 @@ Generate terraform.tfvars of inputs
 * [terraform-docs tfvars hcl](/docs/formats/tfvars-hcl.md)	 - Generate HCL format of terraform.tfvars of inputs
 * [terraform-docs tfvars json](/docs/formats/tfvars-json.md)	 - Generate JSON format of terraform.tfvars of inputs
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/xml.md b/docs/formats/xml.md
index e6dc0eb..ffbb72f 100644
--- a/docs/formats/xml.md
+++ b/docs/formats/xml.md
@@ -331,8 +331,12 @@ generates the following output:
           <name>aws</name>
           <version>&gt;= 2.15.0</version>
         </requirement>
+        <requirement>
+          <name>random</name>
+          <version>&gt;= 2.2.0</version>
+        </requirement>
       </requirements>
     </module>
 
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/docs/formats/yaml.md b/docs/formats/yaml.md
index b6b4f14..60a1f02 100644
--- a/docs/formats/yaml.md
+++ b/docs/formats/yaml.md
@@ -288,6 +288,8 @@ generates the following output:
       version: '>= 0.12'
     - name: aws
       version: '>= 2.15.0'
+    - name: random
+      version: '>= 2.2.0'
 
 
-###### Auto generated by spf13/cobra on 30-Mar-2020
+###### Auto generated by spf13/cobra on 10-Apr-2020
diff --git a/internal/format/factory.go b/internal/format/factory.go
new file mode 100644
index 0000000..736d4b4
--- /dev/null
+++ b/internal/format/factory.go
@@ -0,0 +1,35 @@
+package format
+
+import (
+	"fmt"
+
+	"github.com/segmentio/terraform-docs/pkg/print"
+)
+
+// Factory initializes and returns the conceret implementation of
+// print.Format based on the provided 'name', for example for name
+// of 'json' it will return '*format.JSON' through 'format.NewJSON'
+// function.
+func Factory(name string, settings *print.Settings) (print.Format, error) {
+	switch name {
+	case "json":
+		return NewJSON(settings), nil
+	case "markdown":
+		return NewTable(settings), nil
+	case "markdown document":
+		return NewDocument(settings), nil
+	case "markdown table":
+		return NewTable(settings), nil
+	case "pretty":
+		return NewPretty(settings), nil
+	case "tfvars hcl":
+		return NewTfvarsHCL(settings), nil
+	case "tfvars json":
+		return NewTfvarsJSON(settings), nil
+	case "xml":
+		return NewXML(settings), nil
+	case "yaml":
+		return NewYAML(settings), nil
+	}
+	return nil, fmt.Errorf("formatter '%s' not found", name)
+}
diff --git a/internal/format/testdata/document/document-EscapeCharacters.golden b/internal/format/testdata/markdown/document-EscapeCharacters.golden
similarity index 100%
rename from internal/format/testdata/document/document-EscapeCharacters.golden
rename to internal/format/testdata/markdown/document-EscapeCharacters.golden
diff --git a/internal/format/testdata/document/document-HeaderFromFile.golden b/internal/format/testdata/markdown/document-HeaderFromFile.golden
similarity index 100%
rename from internal/format/testdata/document/document-HeaderFromFile.golden
rename to internal/format/testdata/markdown/document-HeaderFromFile.golden
diff --git a/internal/format/testdata/document/document-IndentationAboveAllowed.golden b/internal/format/testdata/markdown/document-IndentationAboveAllowed.golden
similarity index 100%
rename from internal/format/testdata/document/document-IndentationAboveAllowed.golden
rename to internal/format/testdata/markdown/document-IndentationAboveAllowed.golden
diff --git a/internal/format/testdata/document/document-IndentationBelowAllowed.golden b/internal/format/testdata/markdown/document-IndentationBelowAllowed.golden
similarity index 100%
rename from internal/format/testdata/document/document-IndentationBelowAllowed.golden
rename to internal/format/testdata/markdown/document-IndentationBelowAllowed.golden
diff --git a/internal/format/testdata/document/document-IndentationOfFour.golden b/internal/format/testdata/markdown/document-IndentationOfFour.golden
similarity index 100%
rename from internal/format/testdata/document/document-IndentationOfFour.golden
rename to internal/format/testdata/markdown/document-IndentationOfFour.golden
diff --git a/internal/format/testdata/document/document-NoHeader.golden b/internal/format/testdata/markdown/document-NoHeader.golden
similarity index 100%
rename from internal/format/testdata/document/document-NoHeader.golden
rename to internal/format/testdata/markdown/document-NoHeader.golden
diff --git a/internal/format/testdata/document/document-NoInputs.golden b/internal/format/testdata/markdown/document-NoInputs.golden
similarity index 100%
rename from internal/format/testdata/document/document-NoInputs.golden
rename to internal/format/testdata/markdown/document-NoInputs.golden
diff --git a/internal/format/testdata/document/document-NoOutputs.golden b/internal/format/testdata/markdown/document-NoOutputs.golden
similarity index 100%
rename from internal/format/testdata/document/document-NoOutputs.golden
rename to internal/format/testdata/markdown/document-NoOutputs.golden
diff --git a/internal/format/testdata/document/document-NoProviders.golden b/internal/format/testdata/markdown/document-NoProviders.golden
similarity index 100%
rename from internal/format/testdata/document/document-NoProviders.golden
rename to internal/format/testdata/markdown/document-NoProviders.golden
diff --git a/internal/format/testdata/document/document-NoRequirements.golden b/internal/format/testdata/markdown/document-NoRequirements.golden
similarity index 100%
rename from internal/format/testdata/document/document-NoRequirements.golden
rename to internal/format/testdata/markdown/document-NoRequirements.golden
diff --git a/internal/format/testdata/document/document-OnlyHeader.golden b/internal/format/testdata/markdown/document-OnlyHeader.golden
similarity index 100%
rename from internal/format/testdata/document/document-OnlyHeader.golden
rename to internal/format/testdata/markdown/document-OnlyHeader.golden
diff --git a/internal/format/testdata/document/document-OnlyInputs.golden b/internal/format/testdata/markdown/document-OnlyInputs.golden
similarity index 100%
rename from internal/format/testdata/document/document-OnlyInputs.golden
rename to internal/format/testdata/markdown/document-OnlyInputs.golden
diff --git a/internal/format/testdata/document/document-OnlyOutputs.golden b/internal/format/testdata/markdown/document-OnlyOutputs.golden
similarity index 100%
rename from internal/format/testdata/document/document-OnlyOutputs.golden
rename to internal/format/testdata/markdown/document-OnlyOutputs.golden
diff --git a/internal/format/testdata/document/document-OnlyProviders.golden b/internal/format/testdata/markdown/document-OnlyProviders.golden
similarity index 100%
rename from internal/format/testdata/document/document-OnlyProviders.golden
rename to internal/format/testdata/markdown/document-OnlyProviders.golden
diff --git a/internal/format/testdata/document/document-OnlyRequirements.golden b/internal/format/testdata/markdown/document-OnlyRequirements.golden
similarity index 100%
rename from internal/format/testdata/document/document-OnlyRequirements.golden
rename to internal/format/testdata/markdown/document-OnlyRequirements.golden
diff --git a/internal/format/testdata/document/document-OutputValues.golden b/internal/format/testdata/markdown/document-OutputValues.golden
similarity index 100%
rename from internal/format/testdata/document/document-OutputValues.golden
rename to internal/format/testdata/markdown/document-OutputValues.golden
diff --git a/internal/format/testdata/document/document-OutputValuesNoSensitivity.golden b/internal/format/testdata/markdown/document-OutputValuesNoSensitivity.golden
similarity index 100%
rename from internal/format/testdata/document/document-OutputValuesNoSensitivity.golden
rename to internal/format/testdata/markdown/document-OutputValuesNoSensitivity.golden
diff --git a/internal/format/testdata/document/document-SortByName.golden b/internal/format/testdata/markdown/document-SortByName.golden
similarity index 100%
rename from internal/format/testdata/document/document-SortByName.golden
rename to internal/format/testdata/markdown/document-SortByName.golden
diff --git a/internal/format/testdata/document/document-SortByRequired.golden b/internal/format/testdata/markdown/document-SortByRequired.golden
similarity index 100%
rename from internal/format/testdata/document/document-SortByRequired.golden
rename to internal/format/testdata/markdown/document-SortByRequired.golden
diff --git a/internal/format/testdata/document/document-WithRequired.golden b/internal/format/testdata/markdown/document-WithRequired.golden
similarity index 100%
rename from internal/format/testdata/document/document-WithRequired.golden
rename to internal/format/testdata/markdown/document-WithRequired.golden
diff --git a/internal/format/testdata/document/document.golden b/internal/format/testdata/markdown/document.golden
similarity index 100%
rename from internal/format/testdata/document/document.golden
rename to internal/format/testdata/markdown/document.golden
diff --git a/internal/format/testdata/table/table-EscapeCharacters.golden b/internal/format/testdata/markdown/table-EscapeCharacters.golden
similarity index 100%
rename from internal/format/testdata/table/table-EscapeCharacters.golden
rename to internal/format/testdata/markdown/table-EscapeCharacters.golden
diff --git a/internal/format/testdata/table/table-HeaderFromFile.golden b/internal/format/testdata/markdown/table-HeaderFromFile.golden
similarity index 100%
rename from internal/format/testdata/table/table-HeaderFromFile.golden
rename to internal/format/testdata/markdown/table-HeaderFromFile.golden
diff --git a/internal/format/testdata/table/table-IndentationAboveAllowed.golden b/internal/format/testdata/markdown/table-IndentationAboveAllowed.golden
similarity index 100%
rename from internal/format/testdata/table/table-IndentationAboveAllowed.golden
rename to internal/format/testdata/markdown/table-IndentationAboveAllowed.golden
diff --git a/internal/format/testdata/table/table-IndentationBelowAllowed.golden b/internal/format/testdata/markdown/table-IndentationBelowAllowed.golden
similarity index 100%
rename from internal/format/testdata/table/table-IndentationBelowAllowed.golden
rename to internal/format/testdata/markdown/table-IndentationBelowAllowed.golden
diff --git a/internal/format/testdata/table/table-IndentationOfFour.golden b/internal/format/testdata/markdown/table-IndentationOfFour.golden
similarity index 100%
rename from internal/format/testdata/table/table-IndentationOfFour.golden
rename to internal/format/testdata/markdown/table-IndentationOfFour.golden
diff --git a/internal/format/testdata/table/table-NoHeader.golden b/internal/format/testdata/markdown/table-NoHeader.golden
similarity index 100%
rename from internal/format/testdata/table/table-NoHeader.golden
rename to internal/format/testdata/markdown/table-NoHeader.golden
diff --git a/internal/format/testdata/table/table-NoInputs.golden b/internal/format/testdata/markdown/table-NoInputs.golden
similarity index 100%
rename from internal/format/testdata/table/table-NoInputs.golden
rename to internal/format/testdata/markdown/table-NoInputs.golden
diff --git a/internal/format/testdata/table/table-NoOutputs.golden b/internal/format/testdata/markdown/table-NoOutputs.golden
similarity index 100%
rename from internal/format/testdata/table/table-NoOutputs.golden
rename to internal/format/testdata/markdown/table-NoOutputs.golden
diff --git a/internal/format/testdata/table/table-NoProviders.golden b/internal/format/testdata/markdown/table-NoProviders.golden
similarity index 100%
rename from internal/format/testdata/table/table-NoProviders.golden
rename to internal/format/testdata/markdown/table-NoProviders.golden
diff --git a/internal/format/testdata/table/table-NoRequirements.golden b/internal/format/testdata/markdown/table-NoRequirements.golden
similarity index 100%
rename from internal/format/testdata/table/table-NoRequirements.golden
rename to internal/format/testdata/markdown/table-NoRequirements.golden
diff --git a/internal/format/testdata/table/table-OnlyHeader.golden b/internal/format/testdata/markdown/table-OnlyHeader.golden
similarity index 100%
rename from internal/format/testdata/table/table-OnlyHeader.golden
rename to internal/format/testdata/markdown/table-OnlyHeader.golden
diff --git a/internal/format/testdata/table/table-OnlyInputs.golden b/internal/format/testdata/markdown/table-OnlyInputs.golden
similarity index 100%
rename from internal/format/testdata/table/table-OnlyInputs.golden
rename to internal/format/testdata/markdown/table-OnlyInputs.golden
diff --git a/internal/format/testdata/table/table-OnlyOutputs.golden b/internal/format/testdata/markdown/table-OnlyOutputs.golden
similarity index 100%
rename from internal/format/testdata/table/table-OnlyOutputs.golden
rename to internal/format/testdata/markdown/table-OnlyOutputs.golden
diff --git a/internal/format/testdata/table/table-OnlyProviders.golden b/internal/format/testdata/markdown/table-OnlyProviders.golden
similarity index 100%
rename from internal/format/testdata/table/table-OnlyProviders.golden
rename to internal/format/testdata/markdown/table-OnlyProviders.golden
diff --git a/internal/format/testdata/table/table-OnlyRequirements.golden b/internal/format/testdata/markdown/table-OnlyRequirements.golden
similarity index 100%
rename from internal/format/testdata/table/table-OnlyRequirements.golden
rename to internal/format/testdata/markdown/table-OnlyRequirements.golden
diff --git a/internal/format/testdata/table/table-OutputValues.golden b/internal/format/testdata/markdown/table-OutputValues.golden
similarity index 100%
rename from internal/format/testdata/table/table-OutputValues.golden
rename to internal/format/testdata/markdown/table-OutputValues.golden
diff --git a/internal/format/testdata/table/table-OutputValuesNoSensitivity.golden b/internal/format/testdata/markdown/table-OutputValuesNoSensitivity.golden
similarity index 100%
rename from internal/format/testdata/table/table-OutputValuesNoSensitivity.golden
rename to internal/format/testdata/markdown/table-OutputValuesNoSensitivity.golden
diff --git a/internal/format/testdata/table/table-SortByName.golden b/internal/format/testdata/markdown/table-SortByName.golden
similarity index 100%
rename from internal/format/testdata/table/table-SortByName.golden
rename to internal/format/testdata/markdown/table-SortByName.golden
diff --git a/internal/format/testdata/table/table-SortByRequired.golden b/internal/format/testdata/markdown/table-SortByRequired.golden
similarity index 100%
rename from internal/format/testdata/table/table-SortByRequired.golden
rename to internal/format/testdata/markdown/table-SortByRequired.golden
diff --git a/internal/format/testdata/table/table-WithRequired.golden b/internal/format/testdata/markdown/table-WithRequired.golden
similarity index 100%
rename from internal/format/testdata/table/table-WithRequired.golden
rename to internal/format/testdata/markdown/table-WithRequired.golden
diff --git a/internal/format/testdata/table/table.golden b/internal/format/testdata/markdown/table.golden
similarity index 100%
rename from internal/format/testdata/table/table.golden
rename to internal/format/testdata/markdown/table.golden
diff --git a/scripts/docs/generate.go b/scripts/docs/generate.go
index d377222..54c1705 100644
--- a/scripts/docs/generate.go
+++ b/scripts/docs/generate.go
@@ -129,28 +129,6 @@ func printOptions(buf *bytes.Buffer, cmd *cobra.Command, name string) error {
 	return nil
 }
 
-func getPrinter(name string, settings *print.Settings) print.Format {
-	switch strings.Replace(name, "terraform-docs ", "", -1) {
-	case "json":
-		return format.NewJSON(settings)
-	case "markdown document":
-		return format.NewDocument(settings)
-	case "markdown table":
-		return format.NewTable(settings)
-	case "pretty":
-		return format.NewPretty(settings)
-	case "tfvars hcl":
-		return format.NewTfvarsHCL(settings)
-	case "tfvars json":
-		return format.NewTfvarsJSON(settings)
-	case "xml":
-		return format.NewXML(settings)
-	case "yaml":
-		return format.NewYAML(settings)
-	}
-	return nil
-}
-
 func getFlags(name string) string {
 	switch strings.Replace(name, "terraform-docs ", "", -1) {
 	case "pretty":
@@ -179,25 +157,27 @@ func printExample(buf *bytes.Buffer, name string) error {
 		},
 	}
 
-	if printer := getPrinter(name, settings); printer != nil {
-		tfmodule, err := module.LoadWithOptions(options)
-		if err != nil {
-			log.Fatal(err)
-		}
-		output, err := printer.Print(tfmodule, settings)
-		if err != nil {
-			return err
-		}
-		segments := strings.Split(output, "\n")
-		for _, s := range segments {
-			if s == "" {
-				buf.WriteString("\n")
-			} else {
-				buf.WriteString(fmt.Sprintf("    %s\n", s))
-			}
+	name = strings.Replace(name, "terraform-docs ", "", -1)
+	printer, err := format.Factory(name, settings)
+	if err != nil {
+		return err
+	}
+	tfmodule, err := module.LoadWithOptions(options)
+	if err != nil {
+		log.Fatal(err)
+	}
+	output, err := printer.Print(tfmodule, settings)
+	if err != nil {
+		return err
+	}
+	segments := strings.Split(output, "\n")
+	for _, s := range segments {
+		if s == "" {
+			buf.WriteString("\n")
+		} else {
+			buf.WriteString(fmt.Sprintf("    %s\n", s))
 		}
 	}
-
 	buf.WriteString("\n\n")
 	return nil
 }


Test patch:
diff --git a/internal/format/factory_test.go b/internal/format/factory_test.go
new file mode 100644
index 0000000..ceeabed
--- /dev/null
+++ b/internal/format/factory_test.go
@@ -0,0 +1,92 @@
+package format
+
+import (
+	"reflect"
+	"testing"
+
+	"github.com/segmentio/terraform-docs/pkg/print"
+	"github.com/stretchr/testify/assert"
+)
+
+func TestFormatFactory(t *testing.T) {
+	tests := []struct {
+		name     string
+		format   string
+		expected string
+		wantErr  bool
+	}{
+		{
+			name:     "format factory from name",
+			format:   "json",
+			expected: "*format.JSON",
+			wantErr:  false,
+		},
+		{
+			name:     "format factory from name",
+			format:   "markdown",
+			expected: "*format.Table",
+			wantErr:  false,
+		},
+		{
+			name:     "format factory from name",
+			format:   "markdown document",
+			expected: "*format.Document",
+			wantErr:  false,
+		},
+		{
+			name:     "format factory from name",
+			format:   "markdown table",
+			expected: "*format.Table",
+			wantErr:  false,
+		},
+		{
+			name:     "format factory from name",
+			format:   "pretty",
+			expected: "*format.Pretty",
+			wantErr:  false,
+		},
+		{
+			name:     "format factory from name",
+			format:   "tfvars hcl",
+			expected: "*format.TfvarsHCL",
+			wantErr:  false,
+		},
+		{
+			name:     "format factory from name",
+			format:   "tfvars json",
+			expected: "*format.TfvarsJSON",
+			wantErr:  false,
+		},
+		{
+			name:     "format factory from name",
+			format:   "xml",
+			expected: "*format.XML",
+			wantErr:  false,
+		},
+		{
+			name:     "format factory from name",
+			format:   "yaml",
+			expected: "*format.YAML",
+			wantErr:  false,
+		},
+		{
+			name:     "format factory from name",
+			format:   "unknown",
+			expected: "",
+			wantErr:  true,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			assert := assert.New(t)
+			settings := &print.Settings{}
+			actual, err := Factory(tt.format, settings)
+			if tt.wantErr {
+				assert.NotNil(err)
+			} else {
+				assert.Nil(err)
+				assert.Equal(tt.expected, reflect.TypeOf(actual).String())
+			}
+		})
+	}
+}
diff --git a/internal/format/document.go b/internal/format/markdown_document.go
similarity index 100%
rename from internal/format/document.go
rename to internal/format/markdown_document.go
diff --git a/internal/format/document_test.go b/internal/format/markdown_document_test.go
similarity index 89%
rename from internal/format/document_test.go
rename to internal/format/markdown_document_test.go
index 0bccbd4..b098ecd 100644
--- a/internal/format/document_test.go
+++ b/internal/format/markdown_document_test.go
@@ -13,7 +13,7 @@ func TestDocument(t *testing.T) {
 	assert := assert.New(t)
 	settings := testutil.Settings().WithSections().Build()
 
-	expected, err := testutil.GetExpected("document", "document")
+	expected, err := testutil.GetExpected("markdown", "document")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -33,7 +33,7 @@ func TestDocumentWithRequired(t *testing.T) {
 		ShowRequired: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-WithRequired")
+	expected, err := testutil.GetExpected("markdown", "document-WithRequired")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -53,7 +53,7 @@ func TestDocumentSortByName(t *testing.T) {
 		SortByName: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-SortByName")
+	expected, err := testutil.GetExpected("markdown", "document-SortByName")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().With(&module.Options{
@@ -80,7 +80,7 @@ func TestDocumentSortByRequired(t *testing.T) {
 		SortByRequired: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-SortByRequired")
+	expected, err := testutil.GetExpected("markdown", "document-SortByRequired")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().With(&module.Options{
@@ -111,7 +111,7 @@ func TestDocumentNoHeader(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-NoHeader")
+	expected, err := testutil.GetExpected("markdown", "document-NoHeader")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -135,7 +135,7 @@ func TestDocumentNoInputs(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-NoInputs")
+	expected, err := testutil.GetExpected("markdown", "document-NoInputs")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -159,7 +159,7 @@ func TestDocumentNoOutputs(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-NoOutputs")
+	expected, err := testutil.GetExpected("markdown", "document-NoOutputs")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -183,7 +183,7 @@ func TestDocumentNoProviders(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-NoProviders")
+	expected, err := testutil.GetExpected("markdown", "document-NoProviders")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -207,7 +207,7 @@ func TestDocumentNoRequirements(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-NoRequirements")
+	expected, err := testutil.GetExpected("markdown", "document-NoRequirements")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -231,7 +231,7 @@ func TestDocumentOnlyHeader(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-OnlyHeader")
+	expected, err := testutil.GetExpected("markdown", "document-OnlyHeader")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -255,7 +255,7 @@ func TestDocumentOnlyInputs(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-OnlyInputs")
+	expected, err := testutil.GetExpected("markdown", "document-OnlyInputs")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -279,7 +279,7 @@ func TestDocumentOnlyOutputs(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-OnlyOutputs")
+	expected, err := testutil.GetExpected("markdown", "document-OnlyOutputs")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -303,7 +303,7 @@ func TestDocumentOnlyProviders(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-OnlyProviders")
+	expected, err := testutil.GetExpected("markdown", "document-OnlyProviders")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -327,7 +327,7 @@ func TestDocumentOnlyRequirements(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-OnlyRequirements")
+	expected, err := testutil.GetExpected("markdown", "document-OnlyRequirements")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -347,7 +347,7 @@ func TestDocumentEscapeCharacters(t *testing.T) {
 		EscapeCharacters: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-EscapeCharacters")
+	expected, err := testutil.GetExpected("markdown", "document-EscapeCharacters")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -367,7 +367,7 @@ func TestDocumentIndentationBelowAllowed(t *testing.T) {
 		MarkdownIndent: 0,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-IndentationBelowAllowed")
+	expected, err := testutil.GetExpected("markdown", "document-IndentationBelowAllowed")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -387,7 +387,7 @@ func TestDocumentIndentationAboveAllowed(t *testing.T) {
 		MarkdownIndent: 10,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-IndentationAboveAllowed")
+	expected, err := testutil.GetExpected("markdown", "document-IndentationAboveAllowed")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -407,7 +407,7 @@ func TestDocumentIndentationOfFour(t *testing.T) {
 		MarkdownIndent: 4,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-IndentationOfFour")
+	expected, err := testutil.GetExpected("markdown", "document-IndentationOfFour")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -428,7 +428,7 @@ func TestDocumentOutputValues(t *testing.T) {
 		ShowSensitivity: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-OutputValues")
+	expected, err := testutil.GetExpected("markdown", "document-OutputValues")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().With(&module.Options{
@@ -451,7 +451,7 @@ func TestDocumentHeaderFromFile(t *testing.T) {
 	assert := assert.New(t)
 	settings := testutil.Settings().WithSections().Build()
 
-	expected, err := testutil.GetExpected("document", "document-HeaderFromFile")
+	expected, err := testutil.GetExpected("markdown", "document-HeaderFromFile")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().WithOverwrite(&module.Options{
@@ -476,7 +476,7 @@ func TestDocumentOutputValuesNoSensitivity(t *testing.T) {
 		ShowSensitivity: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("document", "document-OutputValuesNoSensitivity")
+	expected, err := testutil.GetExpected("markdown", "document-OutputValuesNoSensitivity")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().With(&module.Options{
diff --git a/internal/format/table.go b/internal/format/markdown_table.go
similarity index 100%
rename from internal/format/table.go
rename to internal/format/markdown_table.go
diff --git a/internal/format/table_test.go b/internal/format/markdown_table_test.go
similarity index 87%
rename from internal/format/table_test.go
rename to internal/format/markdown_table_test.go
index 36f3101..2a8c770 100644
--- a/internal/format/table_test.go
+++ b/internal/format/markdown_table_test.go
@@ -13,7 +13,7 @@ func TestTable(t *testing.T) {
 	assert := assert.New(t)
 	settings := testutil.Settings().WithSections().Build()
 
-	expected, err := testutil.GetExpected("table", "table")
+	expected, err := testutil.GetExpected("markdown", "table")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -33,7 +33,7 @@ func TestTableWithRequired(t *testing.T) {
 		ShowRequired: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-WithRequired")
+	expected, err := testutil.GetExpected("markdown", "table-WithRequired")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -53,7 +53,7 @@ func TestTableSortByName(t *testing.T) {
 		SortByName: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-SortByName")
+	expected, err := testutil.GetExpected("markdown", "table-SortByName")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().With(&module.Options{
@@ -80,7 +80,7 @@ func TestTableSortByRequired(t *testing.T) {
 		SortByRequired: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-SortByRequired")
+	expected, err := testutil.GetExpected("markdown", "table-SortByRequired")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().With(&module.Options{
@@ -111,7 +111,7 @@ func TestTableNoHeader(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-NoHeader")
+	expected, err := testutil.GetExpected("markdown", "table-NoHeader")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -135,7 +135,7 @@ func TestTableNoInputs(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-NoInputs")
+	expected, err := testutil.GetExpected("markdown", "table-NoInputs")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -159,7 +159,7 @@ func TestTableNoOutputs(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-NoOutputs")
+	expected, err := testutil.GetExpected("markdown", "table-NoOutputs")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -183,7 +183,7 @@ func TestTableNoProviders(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-NoProviders")
+	expected, err := testutil.GetExpected("markdown", "table-NoProviders")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -207,7 +207,7 @@ func TestTableNoRequirements(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-NoRequirements")
+	expected, err := testutil.GetExpected("markdown", "table-NoRequirements")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -231,7 +231,7 @@ func TestTableOnlyHeader(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-OnlyHeader")
+	expected, err := testutil.GetExpected("markdown", "table-OnlyHeader")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -255,7 +255,7 @@ func TestTableOnlyInputs(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-OnlyInputs")
+	expected, err := testutil.GetExpected("markdown", "table-OnlyInputs")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -279,7 +279,7 @@ func TestTableOnlyOutputs(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-OnlyOutputs")
+	expected, err := testutil.GetExpected("markdown", "table-OnlyOutputs")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -303,7 +303,7 @@ func TestTableOnlyProviders(t *testing.T) {
 		ShowRequirements: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-OnlyProviders")
+	expected, err := testutil.GetExpected("markdown", "table-OnlyProviders")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -327,7 +327,7 @@ func TestTableOnlyRequirements(t *testing.T) {
 		ShowRequirements: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-OnlyRequirements")
+	expected, err := testutil.GetExpected("markdown", "table-OnlyRequirements")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -347,7 +347,7 @@ func TestTableEscapeCharacters(t *testing.T) {
 		EscapeCharacters: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-EscapeCharacters")
+	expected, err := testutil.GetExpected("markdown", "table-EscapeCharacters")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -367,7 +367,7 @@ func TestTableIndentationBelowAllowed(t *testing.T) {
 		MarkdownIndent: 0,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-IndentationBelowAllowed")
+	expected, err := testutil.GetExpected("markdown", "table-IndentationBelowAllowed")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -387,7 +387,7 @@ func TestTableIndentationAboveAllowed(t *testing.T) {
 		MarkdownIndent: 10,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-IndentationAboveAllowed")
+	expected, err := testutil.GetExpected("markdown", "table-IndentationAboveAllowed")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -407,7 +407,7 @@ func TestTableIndentationOfFour(t *testing.T) {
 		MarkdownIndent: 4,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-IndentationOfFour")
+	expected, err := testutil.GetExpected("markdown", "table-IndentationOfFour")
 	assert.Nil(err)
 
 	options := module.NewOptions()
@@ -428,7 +428,7 @@ func TestTableOutputValues(t *testing.T) {
 		ShowSensitivity: true,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-OutputValues")
+	expected, err := testutil.GetExpected("markdown", "table-OutputValues")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().With(&module.Options{
@@ -451,7 +451,7 @@ func TestTableHeaderFromFile(t *testing.T) {
 	assert := assert.New(t)
 	settings := testutil.Settings().WithSections().Build()
 
-	expected, err := testutil.GetExpected("table", "table-HeaderFromFile")
+	expected, err := testutil.GetExpected("markdown", "table-HeaderFromFile")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().WithOverwrite(&module.Options{
@@ -476,7 +476,7 @@ func TestTableOutputValuesNoSensitivity(t *testing.T) {
 		ShowSensitivity: false,
 	}).Build()
 
-	expected, err := testutil.GetExpected("table", "table-OutputValuesNoSensitivity")
+	expected, err := testutil.GetExpected("markdown", "table-OutputValuesNoSensitivity")
 	assert.Nil(err)
 
 	options, err := module.NewOptions().With(&module.Options{