Skip to content

Commit bec0736

Browse files
authored
Merge pull request #15 from starius/rm-env-col
remove "Environment variables" if all are none
2 parents b03c6da + f9f58cf commit bec0736

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

markdown_tabular.md.gotmpl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
{{ define "flags" }}
2-
| Name | Description | Type | Default value | Environment variables |
3-
|------|-------------|------|:-------------:|:---------------------:|
2+
{{- $hasEnvVars := false -}}
3+
{{- range . -}}
4+
{{- if and (not $hasEnvVars) .EnvVars -}}
5+
{{- $hasEnvVars = true -}}
6+
{{- end -}}
7+
{{- end }}
8+
| Name | Description | Type | Default value {{ if $hasEnvVars }}| Environment variables {{ end }}|
9+
|------|-------------|------|:-------------:{{ if $hasEnvVars }}|:---------------------:{{ end }}|
410
{{ range $flag := . -}}
511
{{- /**/ -}} | `{{ $flag.Name }}{{ if $flag.TakesValue }}="…"{{ end }}` {{ if $flag.Aliases }}(`{{ join $flag.Aliases "`, `" }}`) {{ end }}
612
{{- /**/ -}} | {{ $flag.Usage }}
713
{{- /**/ -}} | {{ $flag.Type }}
814
{{- /**/ -}} | {{ if $flag.Default }}`{{ $flag.Default }}`{{ end }}
15+
{{- if $hasEnvVars -}}
916
{{- /**/ -}} | {{ if $flag.EnvVars }}`{{ join $flag.EnvVars "`, `" }}`{{ else }}*none*{{ end }}
17+
{{- end -}}
1018
{{- /**/ -}} |
1119
{{ end }}
1220
{{ end }}

testdata/expected-tabular-markdown-custom-app-path.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ $ /usr/local/bin [GLOBAL FLAGS] config [COMMAND FLAGS] [ARGUMENTS...]
3232

3333
The following flags are supported:
3434

35-
| Name | Description | Type | Default value | Environment variables |
36-
|-----------------------------|--------------------|--------|:-------------:|:---------------------:|
37-
| `--flag="…"` (`--fl`, `-f`) | | string | | *none* |
38-
| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* |
35+
| Name | Description | Type | Default value |
36+
|-----------------------------|--------------------|--------|:-------------:|
37+
| `--flag="…"` (`--fl`, `-f`) | | string |
38+
| `--another-flag` (`-b`) | another usage text | bool | `false` |
3939

4040
### `config sub-config` subcommand (aliases: `s`, `ss`)
4141

@@ -49,10 +49,10 @@ $ /usr/local/bin [GLOBAL FLAGS] config sub-config [COMMAND FLAGS] [ARGUMENTS...]
4949

5050
The following flags are supported:
5151

52-
| Name | Description | Type | Default value | Environment variables |
53-
|-------------------------------------|-----------------|--------|:-------------:|:---------------------:|
54-
| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string | | *none* |
55-
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* |
52+
| Name | Description | Type | Default value |
53+
|-------------------------------------|-----------------|--------|:-------------:|
54+
| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string |
55+
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` |
5656

5757
### `info` command (aliases: `i`, `in`)
5858

@@ -93,10 +93,10 @@ $ /usr/local/bin [GLOBAL FLAGS] usage [COMMAND FLAGS] [ARGUMENTS...]
9393
9494
The following flags are supported:
9595

96-
| Name | Description | Type | Default value | Environment variables |
97-
|-----------------------------|--------------------|--------|:-------------:|:---------------------:|
98-
| `--flag="…"` (`--fl`, `-f`) | | string | | *none* |
99-
| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* |
96+
| Name | Description | Type | Default value |
97+
|-----------------------------|--------------------|--------|:-------------:|
98+
| `--flag="…"` (`--fl`, `-f`) | | string |
99+
| `--another-flag` (`-b`) | another usage text | bool | `false` |
100100

101101
### `usage sub-usage` subcommand (aliases: `su`)
102102

@@ -112,6 +112,6 @@ $ /usr/local/bin [GLOBAL FLAGS] usage sub-usage [COMMAND FLAGS] [ARGUMENTS...]
112112

113113
The following flags are supported:
114114

115-
| Name | Description | Type | Default value | Environment variables |
116-
|-----------------------------|-----------------|------|:-------------:|:---------------------:|
117-
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* |
115+
| Name | Description | Type | Default value |
116+
|-----------------------------|-----------------|------|:-------------:|
117+
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` |

testdata/expected-tabular-markdown-full.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ $ app [GLOBAL FLAGS] config [COMMAND FLAGS] [ARGUMENTS...]
3232

3333
The following flags are supported:
3434

35-
| Name | Description | Type | Default value | Environment variables |
36-
|-----------------------------|--------------------|--------|:-------------:|:---------------------:|
37-
| `--flag="…"` (`--fl`, `-f`) | | string | | *none* |
38-
| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* |
35+
| Name | Description | Type | Default value |
36+
|-----------------------------|--------------------|--------|:-------------:|
37+
| `--flag="…"` (`--fl`, `-f`) | | string |
38+
| `--another-flag` (`-b`) | another usage text | bool | `false` |
3939

4040
### `config sub-config` subcommand (aliases: `s`, `ss`)
4141

@@ -49,10 +49,10 @@ $ app [GLOBAL FLAGS] config sub-config [COMMAND FLAGS] [ARGUMENTS...]
4949

5050
The following flags are supported:
5151

52-
| Name | Description | Type | Default value | Environment variables |
53-
|-------------------------------------|-----------------|--------|:-------------:|:---------------------:|
54-
| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string | | *none* |
55-
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* |
52+
| Name | Description | Type | Default value |
53+
|-------------------------------------|-----------------|--------|:-------------:|
54+
| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string |
55+
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` |
5656

5757
### `info` command (aliases: `i`, `in`)
5858

@@ -93,10 +93,10 @@ $ app [GLOBAL FLAGS] usage [COMMAND FLAGS] [ARGUMENTS...]
9393
9494
The following flags are supported:
9595

96-
| Name | Description | Type | Default value | Environment variables |
97-
|-----------------------------|--------------------|--------|:-------------:|:---------------------:|
98-
| `--flag="…"` (`--fl`, `-f`) | | string | | *none* |
99-
| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* |
96+
| Name | Description | Type | Default value |
97+
|-----------------------------|--------------------|--------|:-------------:|
98+
| `--flag="…"` (`--fl`, `-f`) | | string |
99+
| `--another-flag` (`-b`) | another usage text | bool | `false` |
100100

101101
### `usage sub-usage` subcommand (aliases: `su`)
102102

@@ -112,6 +112,6 @@ $ app [GLOBAL FLAGS] usage sub-usage [COMMAND FLAGS] [ARGUMENTS...]
112112

113113
The following flags are supported:
114114

115-
| Name | Description | Type | Default value | Environment variables |
116-
|-----------------------------|-----------------|------|:-------------:|:---------------------:|
117-
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* |
115+
| Name | Description | Type | Default value |
116+
|-----------------------------|-----------------|------|:-------------:|
117+
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` |

0 commit comments

Comments
 (0)