Skip to content

Commit e795250

Browse files
committed
Improve boolean flag documentation generation
Update the documentation generation logic to include values in Type and Default columns for boolean flags that have true as a default value. This change addresses the need for users to differentiate between boolean flags that require explicit negation. Signed-off-by: George Margaritis <gmargaritis@protonmail.com>
1 parent f588677 commit e795250

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

clidocstool_md.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) {
241241
name += mdMakeLink("`--"+f.Name+"`", f.Name, f, isLink)
242242

243243
var ftype string
244-
if f.Value.Type() != "bool" {
244+
if f.Value.Type() != "bool" || (f.Value.Type() == "bool" && f.DefValue == "true") {
245245
ftype = "`" + f.Value.Type() + "`"
246246
}
247247

@@ -253,7 +253,7 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) {
253253
} else if cd, ok := cmd.Annotations[annotation.CodeDelimiter]; ok {
254254
defval = strings.ReplaceAll(defval, cd, "`")
255255
}
256-
} else if f.DefValue != "" && (f.Value.Type() != "bool" && f.DefValue != "true") && f.DefValue != "[]" {
256+
} else if f.DefValue != "" && ((f.Value.Type() != "bool" && f.DefValue != "true") || (f.Value.Type() == "bool" && f.DefValue == "true")) && f.DefValue != "[]" {
257257
defval = "`" + f.DefValue + "`"
258258
}
259259

clidocstool_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ format: "default|<id>[=<socket>|<key>[,<key>]]"`)
137137

138138
buildxBuildFlags.StringVar(&ignore, "ulimit", "", "Ulimit options")
139139

140+
buildxBuildFlags.BoolVar(&ignoreBool, "detach", true, "Dummy flag that tests boolean flags with true as default")
141+
140142
// hidden flags
141143
buildxBuildFlags.BoolVar(&ignoreBool, "compress", false, "Compress the build context using gzip")
142144
buildxBuildFlags.MarkHidden("compress")

fixtures/buildx_build.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Start a build
1818
| `--cache-from` | `stringArray` | | External cache sources (e.g., `user/app:cache`, `type=local,src=path/to/dir`) |
1919
| `--cache-to` | `stringArray` | | Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`) |
2020
| [`--cgroup-parent`](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent) | `string` | | Optional parent cgroup for the container |
21+
| `--detach` | `bool` | `true` | Dummy flag that tests boolean flags with true as default |
2122
| [`-f`](https://docs.docker.com/engine/reference/commandline/build/#specify-a-dockerfile--f), [`--file`](https://docs.docker.com/engine/reference/commandline/build/#specify-a-dockerfile--f) | `string` | | Name of the Dockerfile (default: `PATH/Dockerfile`) |
2223
| `--iidfile` | `string` | | Write the image ID to the file |
2324
| `--label` | `stringArray` | | Set metadata for an image |

fixtures/docker_buildx_build.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ options:
130130
experimentalcli: false
131131
kubernetes: false
132132
swarm: false
133+
- option: detach
134+
value_type: bool
135+
default_value: "true"
136+
description: Dummy flag that tests boolean flags with true as default
137+
deprecated: false
138+
hidden: false
139+
experimental: false
140+
experimentalcli: false
141+
kubernetes: false
142+
swarm: false
133143
- option: file
134144
shorthand: f
135145
value_type: string

0 commit comments

Comments
 (0)