-
Notifications
You must be signed in to change notification settings - Fork 671
feat(cli): add a custom help formatter #2121
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
feat(cli): add a custom help formatter #2121
Conversation
561c933
to
76e8b27
Compare
This is a proposal of how to fix #456 It isn't great - I had to copy a lot of the original code into the custom help formatter only to disable 2 lines of validation. It does seem to work well though. What do you think?
|
c6156e2
to
9916e22
Compare
319a41d
to
3b3bcce
Compare
Hey @weakcamel this is great (even if you had to hack argparse - we always knew argparse was never really made to handle bigger CLI apps). I like the idea here as we've kind of given up on argparse and were going to wait until switching to I took the liberty of playing around with this and made changes to make our CI pass. Here's a summary of changes I did on top of yours:
You can see a comparison of my changes on top of yours here: https://github.com/python-gitlab/python-gitlab/compare/a3802ba8fe493ea214805f9f2270a7d59a277d42..319a41d8cf9b272bd3485ea6cc8f34f1c04b6b52 I hope you're ok with me making these changes here, our linters can be quite difficult to get right sometimes. |
@JohnVillalovos assigning this over to you because I made some changes on top of it. I think it's not worth running some of our linters on top of it as this is stdlib. To test 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.
Would be nice to have a test which tests this is doing what it says it is.
Is that a reasonable thing to ask for or is it too difficult to test?
Was hoping to avoid spending time on argparse but added something basic here 😁 8491d4a Not the most robust test, but should do for now I hope |
So I created another way of doing this in #2191 |
@JohnVillalovos that seems to format differently from the current PR and adds more code other than the override, could you add your review here on why you don't like the current approach? :) |
8491d4a
to
ef10d37
Compare
@JohnVillalovos I like your idea, to avoid looking at 2 PRs I cherry-picked it here and squashed with co-authored trailers. I just changed the output to match the tests and to bring some variables & terminology back to that used natively in |
Add a custom argparse help formatter that overrides the output format to list items vertically. The formatter is derived from argparse.HelpFormatter with minimal changes. Co-authored-by: John Villalovos <john@sodarock.com> Co-authored-by: Nejc Habjan <nejc.habjan@siemens.com>
ef10d37
to
dc08093
Compare
IIRC I did the distinction because I noticed that for shorter lists, some outputs were misalligned somewhat so that was yet another temporary hack of the proof of concept. If it now works as expected with your changes - that's even better.
Absolutely! Thank you so much for doing all the facelifting; I'm not familiar much with python-gitlab's design and plans so you taking over and turning my proof-of-concept into the actual code which fits the rest is great. Edit: Actually, now that I caught up on the rest ot this PR, I can see that the code wasn't used in the end :D but that's just as well. As long as formatting is better now - I'm happy. |
Add a custom argparse help formatter which overrides output format
for long (over 10 elements) list of choices.
Formatter is derived from argparse.HelpFormatter with minimal necessary
changes.
Closes #456