From f9f58cf7c57349da5933c576364cf57454da1eb5 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Mon, 6 Oct 2025 20:07:41 -0300 Subject: [PATCH] remove "Environment variables" if all are none Some commands may not use environment variables for their flags so we can drop the column in this case. --- markdown_tabular.md.gotmpl | 12 ++++++-- ...pected-tabular-markdown-custom-app-path.md | 30 +++++++++---------- testdata/expected-tabular-markdown-full.md | 30 +++++++++---------- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/markdown_tabular.md.gotmpl b/markdown_tabular.md.gotmpl index f11bf92..4697d33 100644 --- a/markdown_tabular.md.gotmpl +++ b/markdown_tabular.md.gotmpl @@ -1,12 +1,20 @@ {{ define "flags" }} -| Name | Description | Type | Default value | Environment variables | -|------|-------------|------|:-------------:|:---------------------:| +{{- $hasEnvVars := false -}} +{{- range . -}} +{{- if and (not $hasEnvVars) .EnvVars -}} +{{- $hasEnvVars = true -}} +{{- end -}} +{{- end }} +| Name | Description | Type | Default value {{ if $hasEnvVars }}| Environment variables {{ end }}| +|------|-------------|------|:-------------:{{ if $hasEnvVars }}|:---------------------:{{ end }}| {{ range $flag := . -}} {{- /**/ -}} | `{{ $flag.Name }}{{ if $flag.TakesValue }}="…"{{ end }}` {{ if $flag.Aliases }}(`{{ join $flag.Aliases "`, `" }}`) {{ end }} {{- /**/ -}} | {{ $flag.Usage }} {{- /**/ -}} | {{ $flag.Type }} {{- /**/ -}} | {{ if $flag.Default }}`{{ $flag.Default }}`{{ end }} +{{- if $hasEnvVars -}} {{- /**/ -}} | {{ if $flag.EnvVars }}`{{ join $flag.EnvVars "`, `" }}`{{ else }}*none*{{ end }} +{{- end -}} {{- /**/ -}} | {{ end }} {{ end }} diff --git a/testdata/expected-tabular-markdown-custom-app-path.md b/testdata/expected-tabular-markdown-custom-app-path.md index 70242cf..a972c06 100644 --- a/testdata/expected-tabular-markdown-custom-app-path.md +++ b/testdata/expected-tabular-markdown-custom-app-path.md @@ -32,10 +32,10 @@ $ /usr/local/bin [GLOBAL FLAGS] config [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Type | Default value | Environment variables | -|-----------------------------|--------------------|--------|:-------------:|:---------------------:| -| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | -| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* | +| Name | Description | Type | Default value | +|-----------------------------|--------------------|--------|:-------------:| +| `--flag="…"` (`--fl`, `-f`) | | string | +| `--another-flag` (`-b`) | another usage text | bool | `false` | ### `config sub-config` subcommand (aliases: `s`, `ss`) @@ -49,10 +49,10 @@ $ /usr/local/bin [GLOBAL FLAGS] config sub-config [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Type | Default value | Environment variables | -|-------------------------------------|-----------------|--------|:-------------:|:---------------------:| -| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string | | *none* | -| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* | +| Name | Description | Type | Default value | +|-------------------------------------|-----------------|--------|:-------------:| +| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string | +| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | ### `info` command (aliases: `i`, `in`) @@ -93,10 +93,10 @@ $ /usr/local/bin [GLOBAL FLAGS] usage [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Type | Default value | Environment variables | -|-----------------------------|--------------------|--------|:-------------:|:---------------------:| -| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | -| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* | +| Name | Description | Type | Default value | +|-----------------------------|--------------------|--------|:-------------:| +| `--flag="…"` (`--fl`, `-f`) | | string | +| `--another-flag` (`-b`) | another usage text | bool | `false` | ### `usage sub-usage` subcommand (aliases: `su`) @@ -112,6 +112,6 @@ $ /usr/local/bin [GLOBAL FLAGS] usage sub-usage [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Type | Default value | Environment variables | -|-----------------------------|-----------------|------|:-------------:|:---------------------:| -| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* | +| Name | Description | Type | Default value | +|-----------------------------|-----------------|------|:-------------:| +| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | diff --git a/testdata/expected-tabular-markdown-full.md b/testdata/expected-tabular-markdown-full.md index 5b210ec..165371e 100644 --- a/testdata/expected-tabular-markdown-full.md +++ b/testdata/expected-tabular-markdown-full.md @@ -32,10 +32,10 @@ $ app [GLOBAL FLAGS] config [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Type | Default value | Environment variables | -|-----------------------------|--------------------|--------|:-------------:|:---------------------:| -| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | -| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* | +| Name | Description | Type | Default value | +|-----------------------------|--------------------|--------|:-------------:| +| `--flag="…"` (`--fl`, `-f`) | | string | +| `--another-flag` (`-b`) | another usage text | bool | `false` | ### `config sub-config` subcommand (aliases: `s`, `ss`) @@ -49,10 +49,10 @@ $ app [GLOBAL FLAGS] config sub-config [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Type | Default value | Environment variables | -|-------------------------------------|-----------------|--------|:-------------:|:---------------------:| -| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string | | *none* | -| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* | +| Name | Description | Type | Default value | +|-------------------------------------|-----------------|--------|:-------------:| +| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string | +| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | ### `info` command (aliases: `i`, `in`) @@ -93,10 +93,10 @@ $ app [GLOBAL FLAGS] usage [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Type | Default value | Environment variables | -|-----------------------------|--------------------|--------|:-------------:|:---------------------:| -| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | -| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* | +| Name | Description | Type | Default value | +|-----------------------------|--------------------|--------|:-------------:| +| `--flag="…"` (`--fl`, `-f`) | | string | +| `--another-flag` (`-b`) | another usage text | bool | `false` | ### `usage sub-usage` subcommand (aliases: `su`) @@ -112,6 +112,6 @@ $ app [GLOBAL FLAGS] usage sub-usage [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Type | Default value | Environment variables | -|-----------------------------|-----------------|------|:-------------:|:---------------------:| -| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* | +| Name | Description | Type | Default value | +|-----------------------------|-----------------|------|:-------------:| +| `--sub-command-flag` (`-s`) | some usage text | bool | `false` |