Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve boolean flag documentation generation #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clidocstool_md.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) {
name += mdMakeLink("`--"+f.Name+"`", f.Name, f, isLink)

var ftype string
if f.Value.Type() != "bool" {
if f.Value.Type() != "bool" || (f.Value.Type() == "bool" && f.DefValue == "true") {
ftype = "`" + f.Value.Type() + "`"
}

Expand All @@ -253,7 +253,7 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) {
} else if cd, ok := cmd.Annotations[annotation.CodeDelimiter]; ok {
defval = strings.ReplaceAll(defval, cd, "`")
}
} else if f.DefValue != "" && (f.Value.Type() != "bool" && f.DefValue != "true") && f.DefValue != "[]" {
} else if f.DefValue != "" && ((f.Value.Type() != "bool" && f.DefValue != "true") || (f.Value.Type() == "bool" && f.DefValue == "true")) && f.DefValue != "[]" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a follow-up, we should probably look at splitting some of these up. Things start to become too complicated IMO (too many boolean conditions here, which makes it easy to introduce bugs).

defval = "`" + f.DefValue + "`"
}

Expand Down
2 changes: 2 additions & 0 deletions clidocstool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ format: "default|<id>[=<socket>|<key>[,<key>]]"`)

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

buildxBuildFlags.BoolVar(&ignoreBool, "detach", true, "Dummy flag that tests boolean flags with true as default")

// hidden flags
buildxBuildFlags.BoolVar(&ignoreBool, "compress", false, "Compress the build context using gzip")
buildxBuildFlags.MarkHidden("compress")
Expand Down
1 change: 1 addition & 0 deletions fixtures/buildx_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Start a build
| `--cache-from` | `stringArray` | | External cache sources (e.g., `user/app:cache`, `type=local,src=path/to/dir`) |
| `--cache-to` | `stringArray` | | Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`) |
| [`--cgroup-parent`](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent) | `string` | | Optional parent cgroup for the container |
| `--detach` | `bool` | `true` | Dummy flag that tests boolean flags with true as default |
| [`-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`) |
| `--iidfile` | `string` | | Write the image ID to the file |
| `--label` | `stringArray` | | Set metadata for an image |
Expand Down
10 changes: 10 additions & 0 deletions fixtures/docker_buildx_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ options:
experimentalcli: false
kubernetes: false
swarm: false
- option: detach
value_type: bool
default_value: "true"
description: Dummy flag that tests boolean flags with true as default
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: file
shorthand: f
value_type: string
Expand Down