Skip to content

Commit 1ef60b5

Browse files
authored
Unify description text of inputs and outputs (terraform-docs#96)
1 parent 57c27b9 commit 1ef60b5

14 files changed

+48
-108
lines changed

internal/pkg/print/markdown/document/document.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,6 @@ func getInputDefaultValue(input *doc.Input, settings settings.Settings) string {
6060
return result
6161
}
6262

63-
func getInputDescription(input *doc.Input) string {
64-
var result = "-"
65-
66-
if input.HasDescription() {
67-
result = input.Description
68-
}
69-
70-
return result
71-
}
72-
73-
func getOutputDescription(output *doc.Output) string {
74-
var result = "-"
75-
76-
if output.HasDescription() {
77-
result = output.Description
78-
}
79-
80-
return result
81-
}
82-
8363
func printComment(buffer *bytes.Buffer, comment string, settings settings.Settings) {
8464
buffer.WriteString(fmt.Sprintf("%s\n", comment))
8565
}
@@ -97,7 +77,7 @@ func printFencedCodeBlock(code string) string {
9777
func printInput(buffer *bytes.Buffer, input doc.Input, settings settings.Settings) {
9878
buffer.WriteString("\n")
9979
buffer.WriteString(fmt.Sprintf("### %s\n\n", strings.Replace(input.Name, "_", "\\_", -1)))
100-
buffer.WriteString(fmt.Sprintf("Description: %s\n\n", markdown.ConvertMultiLineText(getInputDescription(&input))))
80+
buffer.WriteString(fmt.Sprintf("Description: %s\n\n", markdown.ConvertMultiLineText(input.Description)))
10181
buffer.WriteString(fmt.Sprintf("Type: `%s`\n", input.Type))
10282

10383
// Don't print defaults for required inputs when we're already explicit about it being required
@@ -143,6 +123,6 @@ func printOutputs(buffer *bytes.Buffer, outputs []doc.Output, settings settings.
143123
for _, output := range outputs {
144124
buffer.WriteString("\n")
145125
buffer.WriteString(fmt.Sprintf("### %s\n\n", strings.Replace(output.Name, "_", "\\_", -1)))
146-
buffer.WriteString(fmt.Sprintf("Description: %s\n", markdown.ConvertMultiLineText(getOutputDescription(&output))))
126+
buffer.WriteString(fmt.Sprintf("Description: %s\n", markdown.ConvertMultiLineText(output.Description)))
147127
}
148128
}

internal/pkg/print/markdown/document/testdata/document-WithAggregateTypeDefaults.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The following input variables are supported:
2121

2222
### unquoted
2323

24-
Description: -
24+
Description:
2525

2626
Type: `string`
2727

@@ -45,7 +45,7 @@ Default: `bar`
4545

4646
### map-3
4747

48-
Description: -
48+
Description:
4949

5050
Type: `map`
5151

@@ -81,7 +81,7 @@ Default:
8181

8282
### list-3
8383

84-
Description: -
84+
Description:
8585

8686
Type: `list`
8787

internal/pkg/print/markdown/document/testdata/document-WithRequired.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The following input variables are required:
2121

2222
### unquoted
2323

24-
Description: -
24+
Description:
2525

2626
Type: `string`
2727

@@ -63,7 +63,7 @@ Default: `bar`
6363

6464
### map-3
6565

66-
Description: -
66+
Description:
6767

6868
Type: `map`
6969

@@ -79,7 +79,7 @@ Default: `<map>`
7979

8080
### list-3
8181

82-
Description: -
82+
Description:
8383

8484
Type: `list`
8585

internal/pkg/print/markdown/document/testdata/document-WithSortByName.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Default: -
4545

4646
### list-3
4747

48-
Description: -
48+
Description:
4949

5050
Type: `list`
5151

@@ -69,7 +69,7 @@ Default: -
6969

7070
### map-3
7171

72-
Description: -
72+
Description:
7373

7474
Type: `map`
7575

@@ -93,7 +93,7 @@ Default: -
9393

9494
### unquoted
9595

96-
Description: -
96+
Description:
9797

9898
Type: `string`
9999

internal/pkg/print/markdown/document/testdata/document-WithSortInputsByRequired.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Default: -
5353

5454
### unquoted
5555

56-
Description: -
56+
Description:
5757

5858
Type: `string`
5959

@@ -69,7 +69,7 @@ Default: `<list>`
6969

7070
### list-3
7171

72-
Description: -
72+
Description:
7373

7474
Type: `list`
7575

@@ -85,7 +85,7 @@ Default: `<map>`
8585

8686
### map-3
8787

88-
Description: -
88+
Description:
8989

9090
Type: `map`
9191

internal/pkg/print/markdown/document/testdata/document.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The following input variables are supported:
2121

2222
### unquoted
2323

24-
Description: -
24+
Description:
2525

2626
Type: `string`
2727

@@ -45,7 +45,7 @@ Default: `bar`
4545

4646
### map-3
4747

48-
Description: -
48+
Description:
4949

5050
Type: `map`
5151

@@ -69,7 +69,7 @@ Default: `<map>`
6969

7070
### list-3
7171

72-
Description: -
72+
Description:
7373

7474
Type: `list`
7575

internal/pkg/print/markdown/table/table.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,6 @@ func getInputDefaultValue(input *doc.Input, settings settings.Settings) string {
5656
return result
5757
}
5858

59-
func getInputDescription(input *doc.Input) string {
60-
var result = "-"
61-
62-
if input.HasDescription() {
63-
result = input.Description
64-
}
65-
66-
return result
67-
}
68-
69-
func getOutputDescription(output *doc.Output) string {
70-
var result = "-"
71-
72-
if output.HasDescription() {
73-
result = output.Description
74-
}
75-
76-
return result
77-
}
78-
7959
func printComment(buffer *bytes.Buffer, comment string, settings settings.Settings) {
8060
buffer.WriteString(fmt.Sprintf("%s\n", comment))
8161
}
@@ -102,7 +82,7 @@ func printInputs(buffer *bytes.Buffer, inputs []doc.Input, settings settings.Set
10282
buffer.WriteString(
10383
fmt.Sprintf("| %s | %s | %s | %s |",
10484
strings.Replace(input.Name, "_", "\\_", -1),
105-
markdown.ConvertMultiLineText(getInputDescription(&input)),
85+
markdown.ConvertMultiLineText(input.Description),
10686
input.Type,
10787
getInputDefaultValue(&input, settings)))
10888

@@ -131,6 +111,6 @@ func printOutputs(buffer *bytes.Buffer, outputs []doc.Output, settings settings.
131111
buffer.WriteString(
132112
fmt.Sprintf("| %s | %s |\n",
133113
strings.Replace(output.Name, "_", "\\_", -1),
134-
markdown.ConvertMultiLineText(getOutputDescription(&output))))
114+
markdown.ConvertMultiLineText(output.Description)))
135115
}
136116
}

internal/pkg/print/markdown/table/testdata/table-WithAggregateTypeDefaults.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ module "foo" {
1919

2020
| Name | Description | Type | Default |
2121
|------|-------------|:----:|:-----:|
22-
| unquoted | - | string | - |
22+
| unquoted | | string | - |
2323
| string-2 | It's string number two. | string | - |
2424
| string-1 | It's string number one. | string | `bar` |
25-
| map-3 | - | map | `{}` |
25+
| map-3 | | map | `{}` |
2626
| map-2 | It's map number two. | map | - |
2727
| map-1 | It's map number one. | map | `{ "a": 1, "b": 2, "c": 3 }` |
28-
| list-3 | - | list | `[]` |
28+
| list-3 | | list | `[]` |
2929
| list-2 | It's list number two. | list | - |
3030
| list-1 | It's list number one. | list | `[ "a", "b", "c" ]` |
3131
| input\_with\_underscores | A variable with underscores. | string | - |

internal/pkg/print/markdown/table/testdata/table-WithRequired.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ module "foo" {
1919

2020
| Name | Description | Type | Default | Required |
2121
|------|-------------|:----:|:-----:|:-----:|
22-
| unquoted | - | string | - | yes |
22+
| unquoted | | string | - | yes |
2323
| string-2 | It's string number two. | string | - | yes |
2424
| string-1 | It's string number one. | string | `bar` | no |
25-
| map-3 | - | map | `<map>` | no |
25+
| map-3 | | map | `<map>` | no |
2626
| map-2 | It's map number two. | map | - | yes |
2727
| map-1 | It's map number one. | map | `<map>` | no |
28-
| list-3 | - | list | `<list>` | no |
28+
| list-3 | | list | `<list>` | no |
2929
| list-2 | It's list number two. | list | - | yes |
3030
| list-1 | It's list number one. | list | `<list>` | no |
3131
| input\_with\_underscores | A variable with underscores. | string | - | yes |

internal/pkg/print/markdown/table/testdata/table-WithSortByName.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ module "foo" {
2222
| input\_with\_underscores | A variable with underscores. | string | - |
2323
| list-1 | It's list number one. | list | `<list>` |
2424
| list-2 | It's list number two. | list | - |
25-
| list-3 | - | list | `<list>` |
25+
| list-3 | | list | `<list>` |
2626
| map-1 | It's map number one. | map | `<map>` |
2727
| map-2 | It's map number two. | map | - |
28-
| map-3 | - | map | `<map>` |
28+
| map-3 | | map | `<map>` |
2929
| string-1 | It's string number one. | string | `bar` |
3030
| string-2 | It's string number two. | string | - |
31-
| unquoted | - | string | - |
31+
| unquoted | | string | - |
3232

3333
## Outputs
3434

internal/pkg/print/markdown/table/testdata/table-WithSortInputsByRequired.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ module "foo" {
2323
| list-2 | It's list number two. | list | - |
2424
| map-2 | It's map number two. | map | - |
2525
| string-2 | It's string number two. | string | - |
26-
| unquoted | - | string | - |
26+
| unquoted | | string | - |
2727
| list-1 | It's list number one. | list | `<list>` |
28-
| list-3 | - | list | `<list>` |
28+
| list-3 | | list | `<list>` |
2929
| map-1 | It's map number one. | map | `<map>` |
30-
| map-3 | - | map | `<map>` |
30+
| map-3 | | map | `<map>` |
3131
| string-1 | It's string number one. | string | `bar` |
3232

3333
## Outputs

internal/pkg/print/markdown/table/testdata/table.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ module "foo" {
1919

2020
| Name | Description | Type | Default |
2121
|------|-------------|:----:|:-----:|
22-
| unquoted | - | string | - |
22+
| unquoted | | string | - |
2323
| string-2 | It's string number two. | string | - |
2424
| string-1 | It's string number one. | string | `bar` |
25-
| map-3 | - | map | `<map>` |
25+
| map-3 | | map | `<map>` |
2626
| map-2 | It's map number two. | map | - |
2727
| map-1 | It's map number one. | map | `<map>` |
28-
| list-3 | - | list | `<list>` |
28+
| list-3 | | list | `<list>` |
2929
| list-2 | It's list number two. | list | - |
3030
| list-1 | It's list number one. | list | `<list>` |
3131
| input\_with\_underscores | A variable with underscores. | string | - |

internal/pkg/print/pretty/pretty.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,6 @@ func getInputDefaultValue(input *doc.Input, settings settings.Settings) string {
5050
return result
5151
}
5252

53-
func getInputDescription(input *doc.Input) string {
54-
var result = "-"
55-
56-
if input.HasDescription() {
57-
result = input.Description
58-
}
59-
60-
return result
61-
}
62-
63-
func getOutputDescription(output *doc.Output) string {
64-
var result = "-"
65-
66-
if output.HasDescription() {
67-
result = output.Description
68-
}
69-
70-
return result
71-
}
72-
7353
func printComment(buffer *bytes.Buffer, comment string, settings settings.Settings) {
7454
buffer.WriteString(fmt.Sprintf("\n%s\n", comment))
7555
}
@@ -84,7 +64,7 @@ func printInputs(buffer *bytes.Buffer, inputs []doc.Input, settings settings.Set
8464
format,
8565
input.Name,
8666
getInputDefaultValue(&input, settings),
87-
getInputDescription(&input)))
67+
input.Description))
8868
}
8969

9070
buffer.WriteString("\n")
@@ -100,7 +80,7 @@ func printOutputs(buffer *bytes.Buffer, outputs []doc.Output, settings settings.
10080
fmt.Sprintf(
10181
format,
10282
output.Name,
103-
getOutputDescription(&output)))
83+
output.Description))
10484
}
10585

10686
buffer.WriteString("\n")

0 commit comments

Comments
 (0)