-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
App.ToMan() and App.ToMarkdown() don't respect DefaultText #1689
Comments
This is a bigger issue than I anticipated. I tried the following which gets the expected output but reopens an issue, and as expected breaks markdown and man tests. Essentially reverting: #1206 // GetDefaultText returns the default text for this flag
func (f *StringFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
// Changed from
// if f.defaultValue == "" {
// return f.defaultValue
// }
// return fmt.Sprintf("%q", f.defaultValue)
return f.String()
} And // flagDetails returns a string containing the flags metadata
func flagDetails(flag DocGenerationFlag) string {
description := flag.GetUsage()
// Changed from
// value := flag.GetValue()
value := flag.GetDefaultText()
if value != "" {
description += " (default: " + value + ")"
}
return ": " + description
} |
@skelouse Yes. The help test/default text/values etc have been fine tuned over a long period to get the desired results. Its very tough to make changes without breaking something else. Do you want to work on it or else I can take a look |
Thanks for the offer, I'd rather not pick and pry at these! |
@dearchap have you had the time to investigate this issue? |
@alexg-axis Not yet. Does #1721 solve your problem ? |
No, unfortunately not. It makes use of the default value and not default text (if set). |
@alexg-axis Try this PR branch fix |
@dearchap Thanks, I think we're getting close. This did however also change the behavior of things such as If it's a "required side effect" of the fix, then I don't have too much against having to specify both |
@alexg-axis Here is the order of priority in display default
So which condition are you hitting ? |
Flag definition: &cli.IntFlag{
Name: "some-flag",
Usage: "Usage";
Value: 25,
} Previous output: **--some-flag**="": Usage (default: 25)
New output: **--some-flag**="": Usage (default: 0)
Here I would assume that I'm hitting the second item in your list - an initial value set in the field initializer. Thus I would expect the new output to match the old output here. |
Still not working Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Usage: "Route name",
Required: true,
Value: "foo",
DefaultText: "foo",
Action: s.Delete,
},
} NAME: USAGE: OPTIONS:
|
@alexg-axis Please try the PR fix. |
@dearchap seems to be working well! Thanks! |
My urfave/cli version is
v2.24.4
Checklist
Dependency Management
Describe the bug
When using
App.ToMan()
orApp.ToMarkdown()
, the generated text uses theValue
of a flag no matter ifDefaultText
is specified or not. This makes it inconsistent to the output of the help command.To reproduce
Include a flag like the following in your app:
Observed behavior
./main help
Expected behavior
Additional context
None.
Want to fix this yourself?
If confirmed, I'd be happy to fix it.
Run
go version
and paste its output hereRun
go env
and paste its output hereThe text was updated successfully, but these errors were encountered: