Skip to content

Commit

Permalink
Add option to hide Type and Default columns
Browse files Browse the repository at this point in the history
Two new flags are added: '--default bool' and '--type bool' to
control the visibility of Default and Type columns and section
respectively in Markdown and AsciiDoc.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
  • Loading branch information
khos2ow committed Mar 2, 2021
1 parent 7b7a86f commit 3d39a94
Show file tree
Hide file tree
Showing 32 changed files with 1,513 additions and 50 deletions.
6 changes: 4 additions & 2 deletions cmd/asciidoc/asciidoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ func NewCommand(config *cli.Config) *cobra.Command {
}

// flags
cmd.PersistentFlags().BoolVar(&config.Settings.Anchor, "anchor", true, "create anchor links")
cmd.PersistentFlags().BoolVar(&config.Settings.Default, "default", true, "show Default column or section")
cmd.PersistentFlags().IntVar(&config.Settings.Indent, "indent", 2, "indention level of AsciiDoc sections [1, 2, 3, 4, 5]")
cmd.PersistentFlags().BoolVar(&config.Settings.Required, "required", true, "show Required column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Sensitive, "sensitive", true, "show Sensitive column or section")
cmd.PersistentFlags().IntVar(&config.Settings.Indent, "indent", 2, "indention level of AsciiDoc sections [1, 2, 3, 4, 5]")
cmd.PersistentFlags().BoolVar(&config.Settings.Anchor, "anchor", true, "create anchor links")
cmd.PersistentFlags().BoolVar(&config.Settings.Type, "type", true, "show Type column or section")

// subcommands
cmd.AddCommand(document.NewCommand(config))
Expand Down
8 changes: 5 additions & 3 deletions cmd/markdown/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ func NewCommand(config *cli.Config) *cobra.Command {
}

// flags
cmd.PersistentFlags().BoolVar(&config.Settings.Required, "required", true, "show Required column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Sensitive, "sensitive", true, "show Sensitive column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Anchor, "anchor", true, "create anchor links")
cmd.PersistentFlags().BoolVar(&config.Settings.Default, "default", true, "show Default column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Escape, "escape", true, "escape special characters")
cmd.PersistentFlags().IntVar(&config.Settings.Indent, "indent", 2, "indention level of Markdown sections [1, 2, 3, 4, 5]")
cmd.PersistentFlags().BoolVar(&config.Settings.Anchor, "anchor", true, "create anchor links")
cmd.PersistentFlags().BoolVar(&config.Settings.Required, "required", true, "show Required column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Sensitive, "sensitive", true, "show Sensitive column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Type, "type", true, "show Type column or section")

// subcommands
cmd.AddCommand(document.NewCommand(config))
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/asciidoc-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ terraform-docs asciidoc document [PATH] [flags]
```console
--anchor create anchor links (default true)
-c, --config string config file name (default ".terraform-docs.yml")
--default show Default column or section (default true)
--header-from string relative path of a file to read header from (default "main.tf")
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
--hide-all hide all sections (default false)
Expand All @@ -40,6 +41,7 @@ terraform-docs asciidoc document [PATH] [flags]
--sort sort items (default true)
--sort-by-required sort items by name and print required ones first (default false)
--sort-by-type sort items by type of them (default false)
--type show Type column or section (default true)
```

## Example
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/asciidoc-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ terraform-docs asciidoc table [PATH] [flags]
```console
--anchor create anchor links (default true)
-c, --config string config file name (default ".terraform-docs.yml")
--default show Default column or section (default true)
--header-from string relative path of a file to read header from (default "main.tf")
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
--hide-all hide all sections (default false)
Expand All @@ -40,6 +41,7 @@ terraform-docs asciidoc table [PATH] [flags]
--sort sort items (default true)
--sort-by-required sort items by name and print required ones first (default false)
--sort-by-type sort items by type of them (default false)
--type show Type column or section (default true)
```

## Example
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/asciidoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ terraform-docs asciidoc [PATH] [flags]

```console
--anchor create anchor links (default true)
--default show Default column or section (default true)
-h, --help help for asciidoc
--indent int indention level of AsciiDoc sections [1, 2, 3, 4, 5] (default 2)
--required show Required column or section (default true)
--sensitive show Sensitive column or section (default true)
--type show Type column or section (default true)
```

## Inherited Options
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ sort:
settings:
anchors: true
color: true
default: true
escape: true
indent: 2
required: true
sensitive: true
type: true
```

**Note:** The following options cannot be used together:
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/markdown-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ terraform-docs markdown document [PATH] [flags]
```console
--anchor create anchor links (default true)
-c, --config string config file name (default ".terraform-docs.yml")
--default show Default column or section (default true)
--escape escape special characters (default true)
--header-from string relative path of a file to read header from (default "main.tf")
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
Expand All @@ -41,6 +42,7 @@ terraform-docs markdown document [PATH] [flags]
--sort sort items (default true)
--sort-by-required sort items by name and print required ones first (default false)
--sort-by-type sort items by type of them (default false)
--type show Type column or section (default true)
```

## Example
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/markdown-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ terraform-docs markdown table [PATH] [flags]
```console
--anchor create anchor links (default true)
-c, --config string config file name (default ".terraform-docs.yml")
--default show Default column or section (default true)
--escape escape special characters (default true)
--header-from string relative path of a file to read header from (default "main.tf")
--hide strings hide section [header, inputs, modules, outputs, providers, requirements, resources]
Expand All @@ -41,6 +42,7 @@ terraform-docs markdown table [PATH] [flags]
--sort sort items (default true)
--sort-by-required sort items by name and print required ones first (default false)
--sort-by-type sort items by type of them (default false)
--type show Type column or section (default true)
```

## Example
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ terraform-docs markdown [PATH] [flags]

```console
--anchor create anchor links (default true)
--default show Default column or section (default true)
--escape escape special characters (default true)
-h, --help help for markdown
--indent int indention level of Markdown sections [1, 2, 3, 4, 5] (default 2)
--required show Required column or section (default true)
--sensitive show Sensitive column or section (default true)
--type show Type column or section (default true)
```

## Inherited Options
Expand Down
3 changes: 3 additions & 0 deletions examples/.terraform-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ sort:
settings:
indent: 4
escape: false
default: false
required: false
type: true
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/terraform-docs/plugin-sdk v0.1.0
github.com/terraform-docs/plugin-sdk v0.1.1-0.20210302190742-d48efdc5f937
github.com/terraform-docs/terraform-config-inspect v0.0.0-20210126151735-6ef25af8884f
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
honnef.co/go/tools v0.1.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/terraform-docs/plugin-sdk v0.1.0 h1:fLoSYS32Oxh3yP1lQsiH7uaf7/vSnbod6QuLBUd4Z+E=
github.com/terraform-docs/plugin-sdk v0.1.0/go.mod h1:H9E+yVwyOGLXcR28wcWaDODqmhKanZF/uj1H4uCesVM=
github.com/terraform-docs/plugin-sdk v0.1.1-0.20210302190742-d48efdc5f937 h1:Agy6VTh9FW8xhLbceM0kookCN4+lS1DgbNTZjA/mS04=
github.com/terraform-docs/plugin-sdk v0.1.1-0.20210302190742-d48efdc5f937/go.mod h1:3G+0nZTeaMF1c5CZh8cOEYeNq0kUL6+DlQOVcxK7eCQ=
github.com/terraform-docs/terraform-config-inspect v0.0.0-20210126151735-6ef25af8884f h1:WXgHENMC8JOyj6aRpOlnAnJkZ3ZAkPBOhqYrJ5GOhDE=
github.com/terraform-docs/terraform-config-inspect v0.0.0-20210126151735-6ef25af8884f/go.mod h1:GtanFwTsRRXScYHOMb5h4K18XQBFeS2tXat9/LrPtPc=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
8 changes: 7 additions & 1 deletion internal/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,24 @@ func (s *sort) validate() error {
type settings struct {
Anchor bool `yaml:"anchor"`
Color bool `yaml:"color"`
Default bool `yaml:"default"`
Escape bool `yaml:"escape"`
Indent int `yaml:"indent"`
Required bool `yaml:"required"`
Sensitive bool `yaml:"sensitive"`
Type bool `yaml:"type"`
}

func defaultSettings() settings {
return settings{
Anchor: true,
Color: true,
Default: true,
Escape: true,
Indent: 2,
Required: true,
Sensitive: true,
Type: true,
}
}

Expand Down Expand Up @@ -289,10 +293,12 @@ func (c *Config) extract() (*print.Settings, *terraform.Options) {
// settings
settings.EscapeCharacters = c.Settings.Escape
settings.IndentLevel = c.Settings.Indent
settings.ShowAnchor = c.Settings.Anchor
settings.ShowColor = c.Settings.Color
settings.ShowDefault = c.Settings.Default
settings.ShowRequired = c.Settings.Required
settings.ShowSensitivity = c.Settings.Sensitive
settings.ShowAnchor = c.Settings.Anchor
settings.ShowType = c.Settings.Type

return settings, options
}
2 changes: 1 addition & 1 deletion internal/cli/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *cfgreader) parse() error {
if err := c.overrideValue(mapping[flag], &c.config.OutputValues, &c.overrides.OutputValues); err != nil {
return err
}
case "anchor", "color", "escape", "indent", "required", "sensitive":
case "anchor", "color", "default", "escape", "indent", "required", "sensitive", "type":
if err := c.overrideValue(flag, &c.config.Settings, &c.overrides.Settings); err != nil {
return err
}
Expand Down
24 changes: 22 additions & 2 deletions internal/format/asciidoc_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ func TestAsciidocDocument(t *testing.T) {
),
options: terraform.Options{},
},
"WithoutDefault": {
settings: print.Settings{
ShowInputs: true,
ShowDefault: false,
ShowType: true,
},
options: terraform.Options{},
},
"WithoutType": {
settings: print.Settings{
ShowInputs: true,
ShowDefault: true,
ShowType: false,
},
options: terraform.Options{},
},
"IndentationOfFour": {
settings: testutil.WithSections(
print.Settings{
Expand Down Expand Up @@ -98,8 +114,12 @@ func TestAsciidocDocument(t *testing.T) {
options: terraform.Options{},
},
"OnlyInputs": {
settings: print.Settings{ShowInputs: true},
options: terraform.Options{},
settings: print.Settings{
ShowInputs: true,
ShowDefault: true,
ShowType: true,
},
options: terraform.Options{},
},
"OnlyOutputs": {
settings: print.Settings{ShowOutputs: true},
Expand Down
24 changes: 22 additions & 2 deletions internal/format/asciidoc_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ func TestAsciidocTable(t *testing.T) {
),
options: terraform.Options{},
},
"WithoutDefault": {
settings: print.Settings{
ShowInputs: true,
ShowDefault: false,
ShowType: true,
},
options: terraform.Options{},
},
"WithoutType": {
settings: print.Settings{
ShowInputs: true,
ShowDefault: true,
ShowType: false,
},
options: terraform.Options{},
},
"IndentationOfFour": {
settings: testutil.WithSections(
print.Settings{
Expand Down Expand Up @@ -98,8 +114,12 @@ func TestAsciidocTable(t *testing.T) {
options: terraform.Options{},
},
"OnlyInputs": {
settings: print.Settings{ShowInputs: true},
options: terraform.Options{},
settings: print.Settings{
ShowInputs: true,
ShowDefault: true,
ShowType: true,
},
options: terraform.Options{},
},
"OnlyOutputs": {
settings: print.Settings{ShowOutputs: true},
Expand Down
24 changes: 22 additions & 2 deletions internal/format/markdown_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ func TestMarkdownDocument(t *testing.T) {
),
options: terraform.Options{},
},
"WithoutDefault": {
settings: print.Settings{
ShowInputs: true,
ShowDefault: false,
ShowType: true,
},
options: terraform.Options{},
},
"WithoutType": {
settings: print.Settings{
ShowInputs: true,
ShowDefault: true,
ShowType: false,
},
options: terraform.Options{},
},
"EscapeCharacters": {
settings: testutil.WithSections(
print.Settings{
Expand Down Expand Up @@ -106,8 +122,12 @@ func TestMarkdownDocument(t *testing.T) {
options: terraform.Options{},
},
"OnlyInputs": {
settings: print.Settings{ShowInputs: true},
options: terraform.Options{},
settings: print.Settings{
ShowInputs: true,
ShowDefault: true,
ShowType: true,
},
options: terraform.Options{},
},
"OnlyOutputs": {
settings: print.Settings{ShowOutputs: true},
Expand Down
24 changes: 22 additions & 2 deletions internal/format/markdown_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ func TestMarkdownTable(t *testing.T) {
),
options: terraform.Options{},
},
"WithoutDefault": {
settings: print.Settings{
ShowInputs: true,
ShowDefault: false,
ShowType: true,
},
options: terraform.Options{},
},
"WithoutType": {
settings: print.Settings{
ShowInputs: true,
ShowDefault: true,
ShowType: false,
},
options: terraform.Options{},
},
"EscapeCharacters": {
settings: testutil.WithSections(
print.Settings{
Expand Down Expand Up @@ -106,8 +122,12 @@ func TestMarkdownTable(t *testing.T) {
options: terraform.Options{},
},
"OnlyInputs": {
settings: print.Settings{ShowInputs: true},
options: terraform.Options{},
settings: print.Settings{
ShowInputs: true,
ShowDefault: true,
ShowType: true,
},
options: terraform.Options{},
},
"OnlyOutputs": {
settings: print.Settings{ShowOutputs: true},
Expand Down

0 comments on commit 3d39a94

Please sign in to comment.