From 1e398893280d4eea5c574c90c4b65d96ed6ff64f Mon Sep 17 00:00:00 2001 From: Alin Ciortea Date: Mon, 25 Aug 2025 09:43:37 +0300 Subject: [PATCH 1/2] Add support for referencing flag types --- docs.go | 2 + go.mod | 7 ++-- go.sum | 2 + markdown_tabular.md.gotmpl | 5 ++- ...pected-tabular-markdown-custom-app-path.md | 40 +++++++++---------- testdata/expected-tabular-markdown-full.md | 40 +++++++++---------- 6 files changed, 51 insertions(+), 45 deletions(-) diff --git a/docs.go b/docs.go index e5931261..2b560a39 100644 --- a/docs.go +++ b/docs.go @@ -355,6 +355,7 @@ type ( TakesValue bool Default string EnvVars []string + Type string } ) @@ -406,6 +407,7 @@ func (tt tabularTemplate) PrepareFlags(flags []cli.Flag) []cliTabularFlagTemplat EnvVars: flag.GetEnvVars(), TakesValue: flag.TakesValue(), Default: getFlagDefaultValue(flag), + Type: flag.TypeName(), } if boolFlag, isBool := appFlag.(*cli.BoolFlag); isBool { diff --git a/go.mod b/go.mod index 3faa2d20..3148d5f3 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,12 @@ module github.com/urfave/cli-docs/v3 -go 1.18 +go 1.24.4 + require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 - github.com/stretchr/testify v1.9.0 - github.com/urfave/cli/v3 v3.0.0-alpha9.2 + github.com/stretchr/testify v1.10.0 + github.com/urfave/cli/v3 v3.4.1 ) require ( diff --git a/go.sum b/go.sum index 1ffd8d4f..3726afd0 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,10 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/urfave/cli/v3 v3.0.0-alpha9.2 h1:CL8llQj3dGRLVQQzHxS+ZYRLanOuhyK1fXgLKD+qV+Y= github.com/urfave/cli/v3 v3.0.0-alpha9.2/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= +github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/markdown_tabular.md.gotmpl b/markdown_tabular.md.gotmpl index d70fbf87..f11bf924 100644 --- a/markdown_tabular.md.gotmpl +++ b/markdown_tabular.md.gotmpl @@ -1,9 +1,10 @@ {{ define "flags" }} -| Name | Description | Default value | Environment variables | -|------|-------------|:-------------:|:---------------------:| +| Name | Description | Type | Default value | Environment variables | +|------|-------------|------|:-------------:|:---------------------:| {{ 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 $flag.EnvVars }}`{{ join $flag.EnvVars "`, `" }}`{{ else }}*none*{{ end }} {{- /**/ -}} | diff --git a/testdata/expected-tabular-markdown-custom-app-path.md b/testdata/expected-tabular-markdown-custom-app-path.md index 5aad2dfb..70242cf6 100644 --- a/testdata/expected-tabular-markdown-custom-app-path.md +++ b/testdata/expected-tabular-markdown-custom-app-path.md @@ -14,11 +14,11 @@ $ /usr/local/bin [GLOBAL FLAGS] [COMMAND] [COMMAND FLAGS] [ARGUMENTS...] Global flags: -| Name | Description | Default value | Environment variables | -|-----------------------------|--------------------|:-------------:|:-----------------------:| -| `--socket="…"` (`-s`) | some 'usage' text | `value` | *none* | -| `--flag="…"` (`--fl`, `-f`) | | | *none* | -| `--another-flag` (`-b`) | another usage text | `false` | `EXAMPLE_VARIABLE_NAME` | +| Name | Description | Type | Default value | Environment variables | +|-----------------------------|--------------------|--------|:-------------:|:-----------------------:| +| `--socket="…"` (`-s`) | some 'usage' text | string | `value` | *none* | +| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | +| `--another-flag` (`-b`) | another usage text | bool | `false` | `EXAMPLE_VARIABLE_NAME` | ### `config` command (aliases: `c`) @@ -32,10 +32,10 @@ $ /usr/local/bin [GLOBAL FLAGS] config [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Default value | Environment variables | -|-----------------------------|--------------------|:-------------:|:---------------------:| -| `--flag="…"` (`--fl`, `-f`) | | | *none* | -| `--another-flag` (`-b`) | another usage text | `false` | *none* | +| Name | Description | Type | Default value | Environment variables | +|-----------------------------|--------------------|--------|:-------------:|:---------------------:| +| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | +| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* | ### `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 | Default value | Environment variables | -|-------------------------------------|-----------------|:-------------:|:---------------------:| -| `--sub-flag="…"` (`--sub-fl`, `-s`) | | | *none* | -| `--sub-command-flag` (`-s`) | some usage text | `false` | *none* | +| Name | Description | Type | Default value | Environment variables | +|-------------------------------------|-----------------|--------|:-------------:|:---------------------:| +| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string | | *none* | +| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* | ### `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 | Default value | Environment variables | -|-----------------------------|--------------------|:-------------:|:---------------------:| -| `--flag="…"` (`--fl`, `-f`) | | | *none* | -| `--another-flag` (`-b`) | another usage text | `false` | *none* | +| Name | Description | Type | Default value | Environment variables | +|-----------------------------|--------------------|--------|:-------------:|:---------------------:| +| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | +| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* | ### `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 | Default value | Environment variables | -|-----------------------------|-----------------|:-------------:|:---------------------:| -| `--sub-command-flag` (`-s`) | some usage text | `false` | *none* | +| Name | Description | Type | Default value | Environment variables | +|-----------------------------|-----------------|------|:-------------:|:---------------------:| +| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* | diff --git a/testdata/expected-tabular-markdown-full.md b/testdata/expected-tabular-markdown-full.md index 2828e846..5b210ec2 100644 --- a/testdata/expected-tabular-markdown-full.md +++ b/testdata/expected-tabular-markdown-full.md @@ -14,11 +14,11 @@ $ app [GLOBAL FLAGS] [COMMAND] [COMMAND FLAGS] [ARGUMENTS...] Global flags: -| Name | Description | Default value | Environment variables | -|-----------------------------|--------------------|:-------------:|:-----------------------:| -| `--socket="…"` (`-s`) | some 'usage' text | `value` | *none* | -| `--flag="…"` (`--fl`, `-f`) | | | *none* | -| `--another-flag` (`-b`) | another usage text | `false` | `EXAMPLE_VARIABLE_NAME` | +| Name | Description | Type | Default value | Environment variables | +|-----------------------------|--------------------|--------|:-------------:|:-----------------------:| +| `--socket="…"` (`-s`) | some 'usage' text | string | `value` | *none* | +| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | +| `--another-flag` (`-b`) | another usage text | bool | `false` | `EXAMPLE_VARIABLE_NAME` | ### `config` command (aliases: `c`) @@ -32,10 +32,10 @@ $ app [GLOBAL FLAGS] config [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Default value | Environment variables | -|-----------------------------|--------------------|:-------------:|:---------------------:| -| `--flag="…"` (`--fl`, `-f`) | | | *none* | -| `--another-flag` (`-b`) | another usage text | `false` | *none* | +| Name | Description | Type | Default value | Environment variables | +|-----------------------------|--------------------|--------|:-------------:|:---------------------:| +| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | +| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* | ### `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 | Default value | Environment variables | -|-------------------------------------|-----------------|:-------------:|:---------------------:| -| `--sub-flag="…"` (`--sub-fl`, `-s`) | | | *none* | -| `--sub-command-flag` (`-s`) | some usage text | `false` | *none* | +| Name | Description | Type | Default value | Environment variables | +|-------------------------------------|-----------------|--------|:-------------:|:---------------------:| +| `--sub-flag="…"` (`--sub-fl`, `-s`) | | string | | *none* | +| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* | ### `info` command (aliases: `i`, `in`) @@ -93,10 +93,10 @@ $ app [GLOBAL FLAGS] usage [COMMAND FLAGS] [ARGUMENTS...] The following flags are supported: -| Name | Description | Default value | Environment variables | -|-----------------------------|--------------------|:-------------:|:---------------------:| -| `--flag="…"` (`--fl`, `-f`) | | | *none* | -| `--another-flag` (`-b`) | another usage text | `false` | *none* | +| Name | Description | Type | Default value | Environment variables | +|-----------------------------|--------------------|--------|:-------------:|:---------------------:| +| `--flag="…"` (`--fl`, `-f`) | | string | | *none* | +| `--another-flag` (`-b`) | another usage text | bool | `false` | *none* | ### `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 | Default value | Environment variables | -|-----------------------------|-----------------|:-------------:|:---------------------:| -| `--sub-command-flag` (`-s`) | some usage text | `false` | *none* | +| Name | Description | Type | Default value | Environment variables | +|-----------------------------|-----------------|------|:-------------:|:---------------------:| +| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* | From abb8b4ac049327cbf3f01015a2f60dd6f1c0b393 Mon Sep 17 00:00:00 2001 From: Alin Ciortea Date: Tue, 26 Aug 2025 09:44:15 +0300 Subject: [PATCH 2/2] update go.sum --- go.mod | 1 - go.sum | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 3148d5f3..56f0087f 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,6 @@ module github.com/urfave/cli-docs/v3 go 1.24.4 - require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 github.com/stretchr/testify v1.10.0 diff --git a/go.sum b/go.sum index 3726afd0..c4bbf445 100644 --- a/go.sum +++ b/go.sum @@ -6,11 +6,9 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/urfave/cli/v3 v3.0.0-alpha9.2 h1:CL8llQj3dGRLVQQzHxS+ZYRLanOuhyK1fXgLKD+qV+Y= -github.com/urfave/cli/v3 v3.0.0-alpha9.2/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= +github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM= github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=