Skip to content

Commit 21e00b6

Browse files
authored
Merge pull request #13 from Name-Alin/main
Add support for referencing flag types in documentation #12
2 parents 31c0a70 + abb8b4a commit 21e00b6

File tree

6 files changed

+52
-49
lines changed

6 files changed

+52
-49
lines changed

docs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ type (
355355
TakesValue bool
356356
Default string
357357
EnvVars []string
358+
Type string
358359
}
359360
)
360361

@@ -406,6 +407,7 @@ func (tt tabularTemplate) PrepareFlags(flags []cli.Flag) []cliTabularFlagTemplat
406407
EnvVars: flag.GetEnvVars(),
407408
TakesValue: flag.TakesValue(),
408409
Default: getFlagDefaultValue(flag),
410+
Type: flag.TypeName(),
409411
}
410412

411413
if boolFlag, isBool := appFlag.(*cli.BoolFlag); isBool {

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/urfave/cli-docs/v3
22

3-
go 1.18
3+
go 1.24.4
44

55
require (
66
github.com/cpuguy83/go-md2man/v2 v2.0.2
7-
github.com/stretchr/testify v1.9.0
8-
github.com/urfave/cli/v3 v3.0.0-alpha9.2
7+
github.com/stretchr/testify v1.10.0
8+
github.com/urfave/cli/v3 v3.4.1
99
)
1010

1111
require (

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
77
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
88
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
9-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
10-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
11-
github.com/urfave/cli/v3 v3.0.0-alpha9.2 h1:CL8llQj3dGRLVQQzHxS+ZYRLanOuhyK1fXgLKD+qV+Y=
12-
github.com/urfave/cli/v3 v3.0.0-alpha9.2/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
9+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
10+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
11+
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
12+
github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
1313
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1414
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1515
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

markdown_tabular.md.gotmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{{ define "flags" }}
2-
| Name | Description | Default value | Environment variables |
3-
|------|-------------|:-------------:|:---------------------:|
2+
| Name | Description | Type | Default value | Environment variables |
3+
|------|-------------|------|:-------------:|:---------------------:|
44
{{ range $flag := . -}}
55
{{- /**/ -}} | `{{ $flag.Name }}{{ if $flag.TakesValue }}="…"{{ end }}` {{ if $flag.Aliases }}(`{{ join $flag.Aliases "`, `" }}`) {{ end }}
66
{{- /**/ -}} | {{ $flag.Usage }}
7+
{{- /**/ -}} | {{ $flag.Type }}
78
{{- /**/ -}} | {{ if $flag.Default }}`{{ $flag.Default }}`{{ end }}
89
{{- /**/ -}} | {{ if $flag.EnvVars }}`{{ join $flag.EnvVars "`, `" }}`{{ else }}*none*{{ end }}
910
{{- /**/ -}} |

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ $ /usr/local/bin [GLOBAL FLAGS] [COMMAND] [COMMAND FLAGS] [ARGUMENTS...]
1414

1515
Global flags:
1616

17-
| Name | Description | Default value | Environment variables |
18-
|-----------------------------|--------------------|:-------------:|:-----------------------:|
19-
| `--socket="…"` (`-s`) | some 'usage' text | `value` | *none* |
20-
| `--flag="…"` (`--fl`, `-f`) | | | *none* |
21-
| `--another-flag` (`-b`) | another usage text | `false` | `EXAMPLE_VARIABLE_NAME` |
17+
| Name | Description | Type | Default value | Environment variables |
18+
|-----------------------------|--------------------|--------|:-------------:|:-----------------------:|
19+
| `--socket="…"` (`-s`) | some 'usage' text | string | `value` | *none* |
20+
| `--flag="…"` (`--fl`, `-f`) | | string | | *none* |
21+
| `--another-flag` (`-b`) | another usage text | bool | `false` | `EXAMPLE_VARIABLE_NAME` |
2222

2323
### `config` command (aliases: `c`)
2424

@@ -32,10 +32,10 @@ $ /usr/local/bin [GLOBAL FLAGS] config [COMMAND FLAGS] [ARGUMENTS...]
3232

3333
The following flags are supported:
3434

35-
| Name | Description | Default value | Environment variables |
36-
|-----------------------------|--------------------|:-------------:|:---------------------:|
37-
| `--flag="…"` (`--fl`, `-f`) | | | *none* |
38-
| `--another-flag` (`-b`) | another usage text | `false` | *none* |
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* |
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 | Default value | Environment variables |
53-
|-------------------------------------|-----------------|:-------------:|:---------------------:|
54-
| `--sub-flag="…"` (`--sub-fl`, `-s`) | | | *none* |
55-
| `--sub-command-flag` (`-s`) | some usage text | `false` | *none* |
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* |
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 | Default value | Environment variables |
97-
|-----------------------------|--------------------|:-------------:|:---------------------:|
98-
| `--flag="…"` (`--fl`, `-f`) | | | *none* |
99-
| `--another-flag` (`-b`) | another usage text | `false` | *none* |
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* |
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 | Default value | Environment variables |
116-
|-----------------------------|-----------------|:-------------:|:---------------------:|
117-
| `--sub-command-flag` (`-s`) | some usage text | `false` | *none* |
115+
| Name | Description | Type | Default value | Environment variables |
116+
|-----------------------------|-----------------|------|:-------------:|:---------------------:|
117+
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* |

testdata/expected-tabular-markdown-full.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ $ app [GLOBAL FLAGS] [COMMAND] [COMMAND FLAGS] [ARGUMENTS...]
1414

1515
Global flags:
1616

17-
| Name | Description | Default value | Environment variables |
18-
|-----------------------------|--------------------|:-------------:|:-----------------------:|
19-
| `--socket="…"` (`-s`) | some 'usage' text | `value` | *none* |
20-
| `--flag="…"` (`--fl`, `-f`) | | | *none* |
21-
| `--another-flag` (`-b`) | another usage text | `false` | `EXAMPLE_VARIABLE_NAME` |
17+
| Name | Description | Type | Default value | Environment variables |
18+
|-----------------------------|--------------------|--------|:-------------:|:-----------------------:|
19+
| `--socket="…"` (`-s`) | some 'usage' text | string | `value` | *none* |
20+
| `--flag="…"` (`--fl`, `-f`) | | string | | *none* |
21+
| `--another-flag` (`-b`) | another usage text | bool | `false` | `EXAMPLE_VARIABLE_NAME` |
2222

2323
### `config` command (aliases: `c`)
2424

@@ -32,10 +32,10 @@ $ app [GLOBAL FLAGS] config [COMMAND FLAGS] [ARGUMENTS...]
3232

3333
The following flags are supported:
3434

35-
| Name | Description | Default value | Environment variables |
36-
|-----------------------------|--------------------|:-------------:|:---------------------:|
37-
| `--flag="…"` (`--fl`, `-f`) | | | *none* |
38-
| `--another-flag` (`-b`) | another usage text | `false` | *none* |
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* |
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 | Default value | Environment variables |
53-
|-------------------------------------|-----------------|:-------------:|:---------------------:|
54-
| `--sub-flag="…"` (`--sub-fl`, `-s`) | | | *none* |
55-
| `--sub-command-flag` (`-s`) | some usage text | `false` | *none* |
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* |
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 | Default value | Environment variables |
97-
|-----------------------------|--------------------|:-------------:|:---------------------:|
98-
| `--flag="…"` (`--fl`, `-f`) | | | *none* |
99-
| `--another-flag` (`-b`) | another usage text | `false` | *none* |
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* |
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 | Default value | Environment variables |
116-
|-----------------------------|-----------------|:-------------:|:---------------------:|
117-
| `--sub-command-flag` (`-s`) | some usage text | `false` | *none* |
115+
| Name | Description | Type | Default value | Environment variables |
116+
|-----------------------------|-----------------|------|:-------------:|:---------------------:|
117+
| `--sub-command-flag` (`-s`) | some usage text | bool | `false` | *none* |

0 commit comments

Comments
 (0)