mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 12:58:35 +07:00
Merge pull request #475 from khos2ow/show-hide
Deprecate --show-all and --hide-all flags
This commit is contained in:
11
cmd/root.go
11
cmd/root.go
@@ -60,8 +60,6 @@ func NewCommand() *cobra.Command {
|
||||
|
||||
cmd.PersistentFlags().StringSliceVar(&config.Sections.Show, "show", []string{}, "show section ["+cli.AllSections+"]")
|
||||
cmd.PersistentFlags().StringSliceVar(&config.Sections.Hide, "hide", []string{}, "hide section ["+cli.AllSections+"]")
|
||||
cmd.PersistentFlags().BoolVar(&config.Sections.ShowAll, "show-all", true, "show all sections")
|
||||
cmd.PersistentFlags().BoolVar(&config.Sections.HideAll, "hide-all", false, "hide all sections (default false)")
|
||||
|
||||
cmd.PersistentFlags().StringVar(&config.Output.File, "output-file", "", "File in module directory to insert output into (default \"\")")
|
||||
cmd.PersistentFlags().StringVar(&config.Output.Mode, "output-mode", "inject", "Output to file method ["+cli.OutputModes+"]")
|
||||
@@ -71,10 +69,15 @@ func NewCommand() *cobra.Command {
|
||||
cmd.PersistentFlags().StringVar(&config.Sort.By, "sort-by", "name", "sort items by criteria ["+cli.SortTypes+"]")
|
||||
|
||||
// deprecated flags ==>
|
||||
cmd.PersistentFlags().BoolVar(new(bool), "show-all", true, "show all sections")
|
||||
cmd.PersistentFlags().BoolVar(new(bool), "hide-all", false, "hide all sections (default false)")
|
||||
cmd.PersistentFlags().MarkDeprecated("show-all", "more information: https://terraform-docs.io/user-guide/how-to/#visibility-of-sections\n\n") //nolint:errcheck,gosec
|
||||
cmd.PersistentFlags().MarkDeprecated("hide-all", "more information: https://terraform-docs.io/user-guide/how-to/#visibility-of-sections\n\n") //nolint:errcheck,gosec
|
||||
|
||||
cmd.PersistentFlags().BoolVar(&config.Sort.Criteria.Required, "sort-by-required", false, "sort items by name and print required ones first (default false)")
|
||||
cmd.PersistentFlags().BoolVar(&config.Sort.Criteria.Type, "sort-by-type", false, "sort items by type of them (default false)")
|
||||
cmd.PersistentFlags().MarkDeprecated("sort-by-required", "use '--sort-by required' instead") //nolint:errcheck,gosec
|
||||
cmd.PersistentFlags().MarkDeprecated("sort-by-type", "use '--sort-by type' instead") //nolint:errcheck,gosec
|
||||
cmd.PersistentFlags().MarkDeprecated("sort-by-required", "use '--sort-by required' instead\n\n") //nolint:errcheck,gosec
|
||||
cmd.PersistentFlags().MarkDeprecated("sort-by-type", "use '--sort-by type' instead\n\n") //nolint:errcheck,gosec
|
||||
// <==
|
||||
|
||||
cmd.PersistentFlags().StringVar(&config.HeaderFrom, "header-from", "main.tf", "relative path of a file to read header from")
|
||||
|
||||
@@ -31,7 +31,6 @@ terraform-docs asciidoc document [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--indent int indention level of AsciiDoc sections [1, 2, 3, 4, 5] (default 2)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
@@ -41,7 +40,6 @@ terraform-docs asciidoc document [PATH] [flags]
|
||||
--required show Required column or section (default true)
|
||||
--sensitive show Sensitive column or section (default true)
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
--type show Type column or section (default true)
|
||||
|
||||
@@ -31,7 +31,6 @@ terraform-docs asciidoc table [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--indent int indention level of AsciiDoc sections [1, 2, 3, 4, 5] (default 2)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
@@ -41,7 +40,6 @@ terraform-docs asciidoc table [PATH] [flags]
|
||||
--required show Required column or section (default true)
|
||||
--sensitive show Sensitive column or section (default true)
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
--type show Type column or section (default true)
|
||||
|
||||
@@ -35,14 +35,12 @@ terraform-docs asciidoc [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -30,14 +30,12 @@ terraform-docs json [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -32,7 +32,6 @@ terraform-docs markdown document [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--indent int indention level of Markdown sections [1, 2, 3, 4, 5] (default 2)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
@@ -42,7 +41,6 @@ terraform-docs markdown document [PATH] [flags]
|
||||
--required show Required column or section (default true)
|
||||
--sensitive show Sensitive column or section (default true)
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
--type show Type column or section (default true)
|
||||
|
||||
@@ -32,7 +32,6 @@ terraform-docs markdown table [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--indent int indention level of Markdown sections [1, 2, 3, 4, 5] (default 2)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
@@ -42,7 +41,6 @@ terraform-docs markdown table [PATH] [flags]
|
||||
--required show Required column or section (default true)
|
||||
--sensitive show Sensitive column or section (default true)
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
--type show Type column or section (default true)
|
||||
|
||||
@@ -36,14 +36,12 @@ terraform-docs markdown [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -30,14 +30,12 @@ terraform-docs pretty [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -24,14 +24,12 @@ terraform-docs [PATH] [flags]
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
-h, --help help for terraform-docs
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -30,14 +30,12 @@ terraform-docs tfvars hcl [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -29,14 +29,12 @@ terraform-docs tfvars json [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -25,14 +25,12 @@ Generate terraform.tfvars of inputs.
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -29,14 +29,12 @@ terraform-docs toml [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -29,14 +29,12 @@ terraform-docs xml [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -29,14 +29,12 @@ terraform-docs yaml [PATH] [flags]
|
||||
--footer-from string relative path of a file to read footer from (default "")
|
||||
--header-from string relative path of a file to read header from (default "main.tf")
|
||||
--hide strings hide section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--hide-all hide all sections (default false)
|
||||
--output-file string File in module directory to insert output into (default "")
|
||||
--output-mode string Output to file method [inject, replace] (default "inject")
|
||||
--output-template string Output template (default "<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->")
|
||||
--output-values inject output values into outputs (default false)
|
||||
--output-values-from string inject output values from file into outputs (default "")
|
||||
--show strings show section [data-sources, footer, header, inputs, modules, outputs, providers, requirements, resources]
|
||||
--show-all show all sections (default true)
|
||||
--sort sort items (default true)
|
||||
--sort-by string sort items by criteria [name, required, type] (default "name")
|
||||
```
|
||||
|
||||
@@ -49,11 +49,12 @@ header-from: main.tf
|
||||
footer-from: ""
|
||||
|
||||
sections:
|
||||
hide-all: false
|
||||
hide: []
|
||||
show-all: true
|
||||
show: []
|
||||
|
||||
hide-all: false # deprecated in v0.13.0
|
||||
show-all: true # deprecated in v0.13.0
|
||||
|
||||
output:
|
||||
file: ""
|
||||
mode: inject
|
||||
@@ -88,6 +89,9 @@ settings:
|
||||
- `sections.hide-all` and `sections.hide`
|
||||
- `sections.show-all` and `sections.show`
|
||||
|
||||
**Note:** As of `v0.13.0`, `sections.hide-all` and `settings.show-all` are deprecated
|
||||
and removed in favor of explicit use of `settings.hide` and `settings.show`.
|
||||
|
||||
## Formatters
|
||||
|
||||
The following options are supported out of the box by terraform-docs and can be
|
||||
|
||||
@@ -21,17 +21,49 @@ Error: accepts 1 arg(s), received 2
|
||||
## Visibility of Sections
|
||||
|
||||
Output generated by `terraform-docs` consists of different [sections] which are
|
||||
visible by default. The visibility of these can be controlled by one or combination
|
||||
of:
|
||||
visible by default. The visibility of these can be controlled by one of the following
|
||||
options:
|
||||
|
||||
- `--show-all`
|
||||
- `--hide-all`
|
||||
- `--show <name>`
|
||||
- and `--hide <name>`
|
||||
- `--hide <name>`
|
||||
- `--show-all` (deprecated in `v0.13.0`)
|
||||
- `--hide-all` (deprecated in `v0.13.0`)
|
||||
|
||||
```console
|
||||
terraform-docs --show-all --hide header ... # show all sections except 'header'
|
||||
terraform-docs --hide-all --show inputs --show outputs ... # hide all sections except 'inputs' and 'outputs'
|
||||
As of `v0.13.0` flags `--show-all` and `--hide-all` are deprecated in favor of
|
||||
explicit use of `--show` and `--hide`. In other words when `--show <section>` is
|
||||
used, only `<section>` will be shown. If you want to show multiple sections and
|
||||
hide the rest you can specify `--show` flag multiple times. The same logic is also
|
||||
applied to `--hide`.
|
||||
|
||||
```bash
|
||||
# show 'inputs' and hide everything else
|
||||
$ terraform-docs --show inputs <formatter>
|
||||
|
||||
# show 'inputs' and show 'outputs' and hide everything else
|
||||
$ terraform-docs --show inputs --show outputs <formatter>
|
||||
|
||||
# hide 'header' and show everything else
|
||||
$ terraform-docs --hide header <formatter>
|
||||
|
||||
# hide 'header' and hide 'providers' and show everything else
|
||||
$ terraform-docs --hide header --hide providers <formatter>
|
||||
```
|
||||
|
||||
**Note:** Using `--show` or `--hide` CLI flag will completely override the values
|
||||
from `.terraform-docs.yml`.
|
||||
|
||||
```bash
|
||||
$ cat .terraform-docs.yml
|
||||
sections:
|
||||
show:
|
||||
- inputs
|
||||
- outputs
|
||||
|
||||
# example 1: this will only show 'providers'
|
||||
$ terraform-docs --show providers .
|
||||
|
||||
# example 2: this will hide 'inputs' and hide 'providers' and show everything else
|
||||
$ terraform-docs --hide inputs --hide providers .
|
||||
```
|
||||
|
||||
## Module Header
|
||||
|
||||
@@ -3,7 +3,6 @@ header-from: doc.txt
|
||||
footer-from: footer.md
|
||||
|
||||
sections:
|
||||
hide-all: true
|
||||
show:
|
||||
- header
|
||||
- inputs
|
||||
|
||||
@@ -46,10 +46,8 @@ var allSections = []string{
|
||||
var AllSections = strings.Join(allSections, ", ")
|
||||
|
||||
type sections struct {
|
||||
Show []string `yaml:"show"`
|
||||
Hide []string `yaml:"hide"`
|
||||
ShowAll bool `yaml:"show-all"`
|
||||
HideAll bool `yaml:"hide-all"`
|
||||
Show []string `yaml:"show"`
|
||||
Hide []string `yaml:"hide"`
|
||||
|
||||
dataSources bool `yaml:"-"`
|
||||
header bool `yaml:"-"`
|
||||
@@ -64,10 +62,8 @@ type sections struct {
|
||||
|
||||
func defaultSections() sections {
|
||||
return sections{
|
||||
Show: []string{},
|
||||
Hide: []string{},
|
||||
ShowAll: true,
|
||||
HideAll: false,
|
||||
Show: []string{},
|
||||
Hide: []string{},
|
||||
|
||||
dataSources: false,
|
||||
header: false,
|
||||
@@ -81,44 +77,25 @@ func defaultSections() sections {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *sections) validate() error { //nolint:gocyclo
|
||||
// NOTE(khos2ow): this function is over our cyclomatic complexity goal.
|
||||
// Be wary when adding branches, and look for functionality that could
|
||||
// be reasonably moved into an injected dependency.
|
||||
|
||||
func (s *sections) validate() error {
|
||||
if len(s.Show) > 0 && len(s.Hide) > 0 {
|
||||
return fmt.Errorf("'--show' and '--hide' can't be used together")
|
||||
}
|
||||
for _, item := range s.Show {
|
||||
switch item {
|
||||
case allSections[0], allSections[1], allSections[2], allSections[3], allSections[4], allSections[5], allSections[6], allSections[7], allSections[8]:
|
||||
default:
|
||||
if !contains(allSections, item) {
|
||||
return fmt.Errorf("'%s' is not a valid section", item)
|
||||
}
|
||||
}
|
||||
for _, item := range s.Hide {
|
||||
switch item {
|
||||
case allSections[0], allSections[1], allSections[2], allSections[3], allSections[4], allSections[5], allSections[6], allSections[7], allSections[8]:
|
||||
default:
|
||||
if !contains(allSections, item) {
|
||||
return fmt.Errorf("'%s' is not a valid section", item)
|
||||
}
|
||||
}
|
||||
if s.ShowAll && s.HideAll {
|
||||
return fmt.Errorf("'--show-all' and '--hide-all' can't be used together")
|
||||
}
|
||||
if s.ShowAll && len(s.Show) != 0 {
|
||||
return fmt.Errorf("'--show-all' and '--show' can't be used together")
|
||||
}
|
||||
if s.HideAll && len(s.Hide) != 0 {
|
||||
return fmt.Errorf("'--hide-all' and '--hide' can't be used together")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sections) visibility(section string) bool {
|
||||
if s.ShowAll && !s.HideAll {
|
||||
for _, n := range s.Hide {
|
||||
if n == section {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if len(s.Show) == 0 && len(s.Hide) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, n := range s.Show {
|
||||
@@ -131,7 +108,9 @@ func (s *sections) visibility(section string) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
// hidden : if s.Show NOT empty AND s.Show does NOT contain section
|
||||
// visible: if s.Hide NOT empty AND s.Hide does NOT contain section
|
||||
return len(s.Hide) > 0
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -303,14 +282,7 @@ func defaultSort() sort {
|
||||
}
|
||||
|
||||
func (s *sort) validate() error {
|
||||
found := false
|
||||
for _, item := range allSorts {
|
||||
if item == s.By {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
if !contains(allSorts, s.By) {
|
||||
return fmt.Errorf("'%s' is not a valid sort type", s.By)
|
||||
}
|
||||
if s.Criteria.Required && s.Criteria.Type {
|
||||
@@ -382,13 +354,6 @@ func DefaultConfig() *Config {
|
||||
// process provided Config
|
||||
func (c *Config) process() {
|
||||
// sections
|
||||
if c.Sections.HideAll && !changedfs["show-all"] {
|
||||
c.Sections.ShowAll = false
|
||||
}
|
||||
if !c.Sections.ShowAll && !changedfs["hide-all"] {
|
||||
c.Sections.HideAll = true
|
||||
}
|
||||
|
||||
c.Sections.dataSources = c.Sections.visibility("data-sources")
|
||||
c.Sections.header = c.Sections.visibility("header")
|
||||
c.Sections.footer = c.Sections.visibility("footer")
|
||||
@@ -427,8 +392,8 @@ func (c *Config) validate() error { //nolint:gocyclo
|
||||
return fmt.Errorf("value of '--header-from' can't be empty")
|
||||
}
|
||||
|
||||
// footer-from, not a 'default' section so can be empty even if show-all enabled
|
||||
if c.Sections.footer && !c.Sections.ShowAll && c.FooterFrom == "" {
|
||||
// footer-from, not a 'default' section so can be empty
|
||||
if c.Sections.footer && c.FooterFrom == "" {
|
||||
return fmt.Errorf("value of '--footer-from' can't be empty")
|
||||
}
|
||||
|
||||
|
||||
@@ -54,11 +54,121 @@ func (c *cfgreader) parse() error { //nolint:gocyclo
|
||||
return err
|
||||
}
|
||||
|
||||
if c.config.Sections.HideAll && !changedfs["show-all"] {
|
||||
c.config.Sections.ShowAll = false
|
||||
mappings := map[string]struct {
|
||||
flag string
|
||||
from interface{}
|
||||
to interface{}
|
||||
}{
|
||||
"header-from": {
|
||||
flag: "header-from",
|
||||
from: &c.overrides,
|
||||
to: c.config,
|
||||
},
|
||||
"footer-from": {
|
||||
flag: "footer-from",
|
||||
from: &c.overrides,
|
||||
to: c.config,
|
||||
},
|
||||
|
||||
// sort
|
||||
"sort": {
|
||||
flag: "enabled",
|
||||
from: &c.overrides.Sort,
|
||||
to: &c.config.Sort,
|
||||
},
|
||||
"sort-by": {
|
||||
flag: "by",
|
||||
from: &c.overrides.Sort,
|
||||
to: &c.config.Sort,
|
||||
},
|
||||
"sort-by-required": {
|
||||
flag: "required",
|
||||
from: nil,
|
||||
to: nil,
|
||||
},
|
||||
"sort-by-type": {
|
||||
flag: "type",
|
||||
from: nil,
|
||||
to: nil,
|
||||
},
|
||||
|
||||
// output
|
||||
"output-file": {
|
||||
flag: "file",
|
||||
from: &c.overrides.Output,
|
||||
to: &c.config.Output,
|
||||
},
|
||||
"output-mode": {
|
||||
flag: "mode",
|
||||
from: &c.overrides.Output,
|
||||
to: &c.config.Output,
|
||||
},
|
||||
"output-template": {
|
||||
flag: "template",
|
||||
from: &c.overrides.Output,
|
||||
to: &c.config.Output,
|
||||
},
|
||||
|
||||
// output-values
|
||||
"output-values": {
|
||||
flag: "enabled",
|
||||
from: &c.overrides.OutputValues,
|
||||
to: &c.config.OutputValues,
|
||||
},
|
||||
"output-values-from": {
|
||||
flag: "from",
|
||||
from: &c.overrides.OutputValues,
|
||||
to: &c.config.OutputValues,
|
||||
},
|
||||
|
||||
// settings
|
||||
"anchor": {
|
||||
flag: "anchor",
|
||||
from: &c.overrides.Settings,
|
||||
to: &c.config.Settings,
|
||||
},
|
||||
"color": {
|
||||
flag: "color",
|
||||
from: &c.overrides.Settings,
|
||||
to: &c.config.Settings,
|
||||
},
|
||||
"default": {
|
||||
flag: "default",
|
||||
from: &c.overrides.Settings,
|
||||
to: &c.config.Settings,
|
||||
},
|
||||
"escape": {
|
||||
flag: "escape",
|
||||
from: &c.overrides.Settings,
|
||||
to: &c.config.Settings,
|
||||
},
|
||||
"indent": {
|
||||
flag: "indent",
|
||||
from: &c.overrides.Settings,
|
||||
to: &c.config.Settings,
|
||||
},
|
||||
"required": {
|
||||
flag: "required",
|
||||
from: &c.overrides.Settings,
|
||||
to: &c.config.Settings,
|
||||
},
|
||||
"sensitive": {
|
||||
flag: "sensitive",
|
||||
from: &c.overrides.Settings,
|
||||
to: &c.config.Settings,
|
||||
},
|
||||
"type": {
|
||||
flag: "type",
|
||||
from: &c.overrides.Settings,
|
||||
to: &c.config.Settings,
|
||||
},
|
||||
}
|
||||
if !c.config.Sections.ShowAll && !changedfs["hide-all"] {
|
||||
c.config.Sections.HideAll = true
|
||||
|
||||
// If '--show' or '--hide' CLI flag is used, explicitly override and remove
|
||||
// all items from 'show' and 'hide' set in '.terraform-doc.yml'.
|
||||
if changedfs["show"] || changedfs["hide"] {
|
||||
c.config.Sections.Show = []string{}
|
||||
c.config.Sections.Hide = []string{}
|
||||
}
|
||||
|
||||
for flag, enabled := range changedfs {
|
||||
@@ -67,34 +177,17 @@ func (c *cfgreader) parse() error { //nolint:gocyclo
|
||||
}
|
||||
|
||||
switch flag {
|
||||
case "header-from", "footer-from":
|
||||
if err := c.overrideValue(flag, c.config, &c.overrides); err != nil {
|
||||
return err
|
||||
}
|
||||
case "show":
|
||||
c.overrideShow()
|
||||
case "hide":
|
||||
c.overrideHide()
|
||||
case "sort", "sort-by":
|
||||
mapping := map[string]string{"sort": "enabled", "sort-by": "by"}
|
||||
if err := c.overrideValue(mapping[flag], &c.config.Sort, &c.overrides.Sort); err != nil {
|
||||
return err
|
||||
}
|
||||
case "sort-by-required", "sort-by-type":
|
||||
mapping := map[string]string{"sort-by-required": "required", "sort-by-type": "type"}
|
||||
c.config.Sort.By = mapping[flag]
|
||||
case "output-file", "output-mode", "output-template":
|
||||
mapping := map[string]string{"output-file": "file", "output-mode": "mode", "output-template": "template"}
|
||||
if err := c.overrideValue(mapping[flag], &c.config.Output, &c.overrides.Output); err != nil {
|
||||
return err
|
||||
c.config.Sort.By = mappings[flag].flag
|
||||
default:
|
||||
if _, ok := mappings[flag]; !ok {
|
||||
continue
|
||||
}
|
||||
case "output-values", "output-values-from":
|
||||
mapping := map[string]string{"output-values": "enabled", "output-values-from": "from"}
|
||||
if err := c.overrideValue(mapping[flag], &c.config.OutputValues, &c.overrides.OutputValues); err != nil {
|
||||
return err
|
||||
}
|
||||
case "anchor", "color", "default", "escape", "indent", "required", "sensitive", "type":
|
||||
if err := c.overrideValue(flag, &c.config.Settings, &c.overrides.Settings); err != nil {
|
||||
if err := c.overrideValue(mappings[flag].flag, mappings[flag].to, mappings[flag].from); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -119,30 +212,16 @@ func (c *cfgreader) overrideValue(name string, to interface{}, from interface{})
|
||||
|
||||
func (c *cfgreader) overrideShow() {
|
||||
for _, item := range c.overrides.Sections.Show {
|
||||
if c.config.Sections.ShowAll {
|
||||
if contains(c.config.Sections.Hide, item) {
|
||||
c.config.Sections.Hide = remove(c.config.Sections.Hide, item)
|
||||
c.config.Sections.Show = remove(c.config.Sections.Show, item)
|
||||
}
|
||||
} else {
|
||||
if !contains(c.config.Sections.Show, item) {
|
||||
c.config.Sections.Show = append(c.config.Sections.Show, item)
|
||||
}
|
||||
if !contains(c.config.Sections.Show, item) {
|
||||
c.config.Sections.Show = append(c.config.Sections.Show, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cfgreader) overrideHide() {
|
||||
for _, item := range c.overrides.Sections.Hide {
|
||||
if c.config.Sections.HideAll {
|
||||
if contains(c.config.Sections.Show, item) {
|
||||
c.config.Sections.Show = remove(c.config.Sections.Show, item)
|
||||
c.config.Sections.Hide = remove(c.config.Sections.Hide, item)
|
||||
}
|
||||
} else {
|
||||
if !contains(c.config.Sections.Hide, item) {
|
||||
c.config.Sections.Hide = append(c.config.Sections.Hide, item)
|
||||
}
|
||||
if !contains(c.config.Sections.Hide, item) {
|
||||
c.config.Sections.Hide = append(c.config.Sections.Hide, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,34 +189,30 @@ func TestOverrideShow(t *testing.T) {
|
||||
name string
|
||||
show []string
|
||||
hide []string
|
||||
showall bool
|
||||
overrideShow []string
|
||||
expectedShow []string
|
||||
expectedHide []string
|
||||
}{
|
||||
{
|
||||
name: "override section show",
|
||||
show: []string{""},
|
||||
show: []string{},
|
||||
hide: []string{"inputs", "outputs"},
|
||||
showall: true,
|
||||
overrideShow: []string{"inputs"},
|
||||
expectedShow: []string{""},
|
||||
expectedHide: []string{"outputs"},
|
||||
expectedShow: []string{"inputs"},
|
||||
expectedHide: []string{"inputs", "outputs"},
|
||||
},
|
||||
{
|
||||
name: "override section show",
|
||||
show: []string{"providers"},
|
||||
hide: []string{"inputs"},
|
||||
showall: true,
|
||||
overrideShow: []string{"outputs"},
|
||||
expectedShow: []string{"providers"},
|
||||
expectedShow: []string{"providers", "outputs"},
|
||||
expectedHide: []string{"inputs"},
|
||||
},
|
||||
{
|
||||
name: "override section show",
|
||||
show: []string{"inputs"},
|
||||
hide: []string{"providers"},
|
||||
showall: false,
|
||||
overrideShow: []string{"outputs"},
|
||||
expectedShow: []string{"inputs", "outputs"},
|
||||
expectedHide: []string{"providers"},
|
||||
@@ -225,7 +221,6 @@ func TestOverrideShow(t *testing.T) {
|
||||
name: "override section show",
|
||||
show: []string{"inputs"},
|
||||
hide: []string{"inputs"},
|
||||
showall: false,
|
||||
overrideShow: []string{"inputs"},
|
||||
expectedShow: []string{"inputs"},
|
||||
expectedHide: []string{"inputs"},
|
||||
@@ -240,7 +235,6 @@ func TestOverrideShow(t *testing.T) {
|
||||
|
||||
c.config.Sections.Show = tt.show
|
||||
c.config.Sections.Hide = tt.hide
|
||||
c.config.Sections.ShowAll = tt.showall
|
||||
c.overrides.Sections.Show = tt.overrideShow
|
||||
|
||||
c.overrideShow()
|
||||
@@ -256,7 +250,6 @@ func TestOverrideHide(t *testing.T) {
|
||||
name string
|
||||
show []string
|
||||
hide []string
|
||||
hideall bool
|
||||
overrideHide []string
|
||||
expectedShow []string
|
||||
expectedHide []string
|
||||
@@ -264,26 +257,23 @@ func TestOverrideHide(t *testing.T) {
|
||||
{
|
||||
name: "override section hide",
|
||||
show: []string{"inputs", "outputs"},
|
||||
hide: []string{""},
|
||||
hideall: true,
|
||||
hide: []string{},
|
||||
overrideHide: []string{"inputs"},
|
||||
expectedShow: []string{"outputs"},
|
||||
expectedHide: []string{""},
|
||||
expectedShow: []string{"inputs", "outputs"},
|
||||
expectedHide: []string{"inputs"},
|
||||
},
|
||||
{
|
||||
name: "override section hide",
|
||||
show: []string{"inputs"},
|
||||
hide: []string{"providers"},
|
||||
hideall: true,
|
||||
overrideHide: []string{"outputs"},
|
||||
expectedShow: []string{"inputs"},
|
||||
expectedHide: []string{"providers"},
|
||||
expectedHide: []string{"providers", "outputs"},
|
||||
},
|
||||
{
|
||||
name: "override section hide",
|
||||
show: []string{"providers"},
|
||||
hide: []string{"inputs"},
|
||||
hideall: false,
|
||||
overrideHide: []string{"outputs"},
|
||||
expectedShow: []string{"providers"},
|
||||
expectedHide: []string{"inputs", "outputs"},
|
||||
@@ -292,7 +282,6 @@ func TestOverrideHide(t *testing.T) {
|
||||
name: "override section hide",
|
||||
show: []string{"inputs"},
|
||||
hide: []string{"inputs"},
|
||||
hideall: false,
|
||||
overrideHide: []string{"inputs"},
|
||||
expectedShow: []string{"inputs"},
|
||||
expectedHide: []string{"inputs"},
|
||||
@@ -307,7 +296,6 @@ func TestOverrideHide(t *testing.T) {
|
||||
|
||||
c.config.Sections.Show = tt.show
|
||||
c.config.Sections.Hide = tt.hide
|
||||
c.config.Sections.HideAll = tt.hideall
|
||||
c.overrides.Sections.Hide = tt.overrideHide
|
||||
|
||||
c.overrideHide()
|
||||
|
||||
Reference in New Issue
Block a user