cli icon indicating copy to clipboard operation
cli copied to clipboard

feat: fields for VisibleFlags name/alias and Usage

Open midischwarz12 opened this issue 1 year ago • 6 comments

Checklist

  • [ ] Are you running the latest v3 release? The list of releases is here.
  • [x] Did you check the manual for your release? The v3 manual is here.
  • [x] Did you perform a search about this feature? Here's the GitHub guide about searching.

What problem does this solve?

When customizing the AppHelpTemplate, it would be preferable to change how the first and second column are formatted, ie - the description of the flag on a separate line, tabbed out, and restricted to a width of 80 characters. In the current state of .VisiableFlags, there is no way to separate the two columns beyond a slice of strings. Each flag has its name and description (.Usage) clumped together as a single string which is difficult or nearly impossible to parse using go's template actions.

Solution description

The two columns should be exposed as separate fields.

For the first column, .Name does not truly suffice as it both contains the long Name, Aliases, and has the input values marked by the respective name or alias. A fitting name for this could be .Names or .Flags.

For the second column, something equivalent to .Usage is sufficient.

Describe alternatives you've considered

I've tried to loop through .VisiableFlags and coerce each flag to its original type such as StingFlag and then create a custom template to load which would effectively recreate the first column. But this served to be very tedious, and admittedly, I'm not good enough in golang to do this with ease.

I also thought of potentially hand writing this part of the help template. But this deemed tedious as well and goes against the spirit of urfave/cli as it does not autogenerate based on the visible flags.

midischwarz12 avatar Nov 28 '24 00:11 midischwarz12

@midirhee12 you could cast the Flag to a DocGenerationFlag to extract further information if you'd like. Admittingly its not elegant but might work ?

dearchap avatar Nov 28 '24 02:11 dearchap

How would this be casted and used within the AppHelpTemplate?

midischwarz12 avatar Nov 28 '24 23:11 midischwarz12

@dearchap From what I know, you would have to map the function into the template before being evaluated. Is there a way this is being exposed?

midischwarz12 avatar Nov 29 '24 00:11 midischwarz12

Either way, even if it is possible, I think there should be a more straightforward and clean way to access this since formatting the templates could be quite frequent among users.

midischwarz12 avatar Nov 29 '24 21:11 midischwarz12

@dearchap Actually, on second thought. Is it possible to expose .VisibleFlagTemplate and such instead?

midischwarz12 avatar Dec 01 '24 00:12 midischwarz12

@midirhee12 yes. you want to make a PR ?

dearchap avatar Dec 01 '24 14:12 dearchap