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

Make usage and help output configurable #201

Closed
wants to merge 1 commit into from

Conversation

daenney
Copy link
Contributor

@daenney daenney commented Oct 12, 2022

This is a first pass looking to gather feedback on solving #193, #163, #146 and hopefully also #139.

Essentially, this makes use of text/template to specify the output format. It introduces a buildUsageForSubcommand which uses a string builder to build up the usage string that's then interpolated into the Go template.

I haven't modified any of the tests and they still all pass, which at the very least suggest the behaviour is the same.

The idea is to then make the template settable through arg, like func (arg) UsageTemplate() *template.Template {}, and if no such template is provided then p.usageTemplate would use the const usageTemplate.

The code is a little rough right now, but it's the general direction I'm thinking of. Does this align with what you had in mind?

@daenney daenney marked this pull request as draft October 12, 2022 20:32
@codecov-commenter
Copy link

codecov-commenter commented Oct 12, 2022

Codecov Report

Base: 100.00% // Head: 99.71% // Decreases project coverage by -0.28% ⚠️

Coverage data is based on head (f55738a) compared to base (11f9b62).
Patch coverage: 95.23% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #201      +/-   ##
===========================================
- Coverage   100.00%   99.71%   -0.29%     
===========================================
  Files            5        5              
  Lines          688      699      +11     
===========================================
+ Hits           688      697       +9     
- Misses           0        1       +1     
- Partials         0        1       +1     
Impacted Files Coverage Δ
usage.go 98.91% <93.33%> (-1.09%) ⬇️
parse.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@daenney
Copy link
Contributor Author

daenney commented Oct 12, 2022

In case for anyone looking along, right now the proposed code only changes the usage generation. But if this is something @alexflint is comfortable with I'll rework it and add the code to customise the help output too.

This adds a text/template for the generation of the usage line.
@alexflint
Copy link
Owner

Thanks for putting this together @daenney. I'd like to do support this feature but I'd like to do it in a way where you can configure the organization of all the individual options and positional arguments, control how the long names, short names, descriptions, and default values are laid out, and so on. In order to do that we will need to finalize the layout of the struct that gets passed in to the template, and at that point it will be difficult to change because doing so will break backwards compatibility. Therefore I'd like to add this as a v2 feature, with a re-worked Command struct that is accessible to users of the library.

@alexflint alexflint closed this Oct 29, 2022
@daenney daenney deleted the format-usage-help branch October 29, 2022 16:36
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.

3 participants