-
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
Simplify HelpPrinter and CustomHelpPrinter behaviors #912
Conversation
Codecov Report
@@ Coverage Diff @@
## master #912 +/- ##
==========================================
+ Coverage 71.38% 71.48% +0.09%
==========================================
Files 30 30
Lines 2394 2395 +1
==========================================
+ Hits 1709 1712 +3
+ Misses 578 577 -1
+ Partials 107 106 -1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a hard time understanding the practical impact of this change, can you write a test that helps display the new behavior?
Four new test cases added that should cover everything that's changed. I also updated the GoDoc comments and PR description to hopefully make this more intuitive in addition to the new test cases. There's now a TL;DR in the description that's a bit more direct than the wall of text above it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 looking good ✨
I'm a bit hesitant to merge this since we are currently trying to fast track the V2 work, but the PR is looking great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If the concern with merging now is just avoiding the merge conflicts for the v2 branch, I went ahead and resolved issues ahead of time on a separate branch: https://github.com/rliebz/cli/tree/help-printer-v2 (merge commit: b5bef8e). I don't have a good idea of what the migration path from v1 to v2 looks like, but I think there's value into getting fixes like this into v1. There are ways to work around the issue though, so if we end up not merging this in, that's alright. The current state of things is still manageable, just not ideal. |
🙏 ahhhh, this is hero behavior! thank you!!! 🙏 You can totally merge this now 😄 and then yea, you'll want to send a PR into the WIP v2 branch |
Awesome, thanks! I've opened up #913 to do just that. I don't have permission to merge, so please do so when you get the chance. |
Update v2 branch with #912
Currently, the structure of
HelpPrinter
andHelpPrinterCustom
make them extremely difficult to use correctly.As it stands:
HelpPrinter
will be used most of the time. For most applications, it will be used 100% of the time.CustomHelpTemplate
is set,HelpPrinterCustom
will be used. Any other time,HelpPrinter
will continue to be used.HelpPrinter
simply makes a call to the defaultHelpPrinterCustom
, it calls the private version of that function. This means ifHelpPrinterCustom
is overridden,HelpPrinter
must also be set in order to get consistent behavior across the application.As an example, in an application that needs no custom behavior other than passing one additional custom template function, the easiest way I could find to get a consistent print behavior was to first wrap the original custom help printer, then assign to both
HelpPrinter
andHelpPrinterCustom
:The fix in this PR does a few things that should make things more consistent and harder to misuse.
Since I don't think there's a good justification for the inconsistent calling of
HelpPrinterCustom
in one of the specific places where it happens to be used, I've replaced it with the higher-levelHelpPrinter
call, which by default will defer toHelpPrinterCustom
. In the one place where it was actually required, the logic has been updated to preferHelpPrinter
except in the exact case whichHelpPrinterCustom
was written to fulfill.As well, the default
PrintHelp
function now calls the public version ofPrintHelpCustom
, so if that is overridden, users don't also have to overridePrintHelp
for the change to propagate.Combining these changes means that you can override either
HelpPrinter
orHelpPrinterCustom
as necessary, and still get consistent behavior between printing app help, command help, and sub-command help, regardless of whether or not you're using a custom template. The default behavior is exactly the same as it was before.I think this is the correct fix, but I figured it would be easier to get code out for discussion rather than opening an issue. Happy to make changes if need be.
TL;DR:
HelpPrinter
andHelpPrinterCustom
were called interchangeably based on logic that didn't really make sense from a public interface perspective. Two changes:HelpPrinter
now directly callsHelpPrinterCustom
instead of just having the same implementation, so you don't have to override both if you overrideHelpPrinterCustom
.HelpPrinter
is just a wrapper aroundHelpPrinterCustom
, only callHelpPrinterCustom
directly in the one situation where we absolutely have to (see Add support for custom help templates. #586 for context)