urfave / cli

A simple, fast, and fun package for building command line apps in Go
https://cli.urfave.org
MIT License
21.89k stars 1.69k forks source link

Allow omission of default text in help text #1925

Open drewfead opened 2 weeks ago

drewfead commented 2 weeks ago

Checklist

What problem does this solve?

In 3.0.0-alpha9, default text is always printed, irrespective of whether the field is required, etc.

This means that required numeric flags have help text that prints a default value of 0, for example. The current API supports bringing your own DefaultText, but if you set it to "", it doesn't get applied. See relevant code here and here.

Arguably this is a bug for implicit zero-valued default values. Certainly this is a bug for required flags with an implicit zero-valued default. Regardless of its status as a bug or expected behavior, it would be nice to be able to opt out of showing default text altogether on a flag-by-flag basis.

Solution description

I'd like for an OmitDefaultText boolean field to be added to flag base, or a similarly turn-key solution.

Describe alternatives you've considered

I think you could also make the DefaultText field a *string, and use the empty string to indicate that default text shouldn't be printed, and I think that would also be fine. I could also imagine at the flag level being able to specify the help template for that flag only, which would be slightly more cumbersome.

dearchap commented 2 days ago

@drewfead Yes this starts to get very very complicated. You have defaults, zeros, required, optional and empty strings and it is getting harder and harder to distinguish all of them. Would you like to submit a PR for me to review ?

Skeeve commented 15 hours ago

My proposal is: We already have "Hidden: true/false" in FlagBase.

Why not add "HideDefault: true/false"?

Also set HideDefault for the standard help and version command to true as this makes no sense at all:

GLOBAL OPTIONS:
   --help, -h     show help (default: false)
   --version, -v  print the version (default: false)

And, before you ask:I'm not able to provide a PR as I already tried to program it and failed. I simply can't get my head around all the abstract layers of types and interfaces :(

Or can I? #1937