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

Conversation

gmargaritis
Copy link
Contributor

Resolves #47

Updated 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.

@gmargaritis
Copy link
Contributor Author

@thaJeztah Let me know if we want to also display the Type of boolean flags regardless of their default value

@crazy-max
Copy link
Member

I think we want the same for yaml generation?

@crazy-max
Copy link
Member

Can we also have a test for this case?

@thaJeztah
Copy link
Member

@crazy-max I think we already unconditionally set the default value for YAML; at least looking at the fixture here, I see "false" as default;

- option: compress
value_type: bool
default_value: "false"
description: Compress the build context using gzip
deprecated: false

@crazy-max
Copy link
Member

@crazy-max I think we already unconditionally set the default value for YAML; at least looking at the fixture here, I see "false" as default;

- option: compress
value_type: bool
default_value: "false"
description: Compress the build context using gzip
deprecated: false

Ah ok looks good then 👍

@gmargaritis
Copy link
Contributor Author

gmargaritis commented Feb 12, 2024

That's correct! Do we want to make any changes here?

flags.VisitAll(func(flag *pflag.Flag) {
opt = cmdOption{
Option: flag.Name,
ValueType: flag.Value.Type(),
Deprecated: len(flag.Deprecated) > 0,
Hidden: flag.Hidden,
}
var defval string
if v, ok := flag.Annotations[annotation.DefaultValue]; ok && len(v) > 0 {
defval = v[0]
if cd, ok := flag.Annotations[annotation.CodeDelimiter]; ok {
defval = strings.ReplaceAll(defval, cd[0], "`")
} else if cd, ok := cmd.Annotations[annotation.CodeDelimiter]; ok {
defval = strings.ReplaceAll(defval, cd, "`")
}
} else {
defval = flag.DefValue
}
opt.DefaultValue = forceMultiLine(defval, defaultValueMaxWidth)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

we should probably look at some additional test-cases in a follow-up

} 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).

@thaJeztah
Copy link
Member

@crazy-max LGTY?

@crazy-max
Copy link
Member

Can we have a test in https://github.com/docker/cli-docs-tool/blob/main/clidocstool_test.go#L38? Just a dummy new flag like --detach that will default to true and update fixtures as well in https://github.com/docker/cli-docs-tool/tree/main/fixtures

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>
@gmargaritis gmargaritis force-pushed the 47-improve-boolean-flag-documentation branch from 4c6e97f to e795250 Compare February 12, 2024 14:55
@gmargaritis
Copy link
Contributor Author

@crazy-max Added the test case, we should be good to go!

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@crazy-max crazy-max merged commit 40b8303 into docker:main Feb 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve documentation for boolean flags with true as default value
3 participants