-
Notifications
You must be signed in to change notification settings - Fork 39
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
Properly override click.HelpFormatter.getvalue
#230
base: main
Are you sure you want to change the base?
Conversation
Thanks. I played around and it shouldn't impact things. So we can do this. One note: I played around with the Click >>> from click.formatting import HelpFormatter
>>> hf = HelpFormatter()
>>> hf.write("foo")
>>> hf.write("bar")
>>> hf.getvalue()
'foobar'
>>> hf.getvalue()
'foobar' So I am thinking it may make more sense to return |
Good idea, thanks! I just pushed a commit that does that. |
Thanks. Upon further thinking (refer to the discussion in the linked issue), there may be some additional work that needs to be thought through. If we switch to something more compliant with the We may also want to consider adding a more explicit Sorry, need to sit on this for a bit. I am supportive of where you / we are headed here, but I want to make sure it is good for general purpose usage. I do understand your concerns are a little more narrow and you want to support your users of |
OK, so the objective here is to make rich-click more aligned with the base Click API in how it handles the HelpFormatter. Really happy we're taking this on, and you've given me a good starting point for how to think through it. It will require a decent amount of additional work, and it's not as simple as the PR here. You can take it on if you'd like. If not, I totally understand, and I can take a stab at it. Even if you do take this on, I am a little reluctant to release these refactors as a patch version release, as a warning; I would rather this be in a minor release, which I do have plans to do by the middle of this year. So think June or July for when this gets shipped (alongside a bunch of other stuff). If you do not want to take this on, please just add If you do want to take this on, we need to do the following:
|
https://click.palletsprojects.com/en/stable/api/#click.HelpFormatter.getvalue
If the class attribute
export_console_as
onRichContext
(or a subclass) is set to a value that is notNone
then getting the value of the buffer returns the raw text that was printed to the underlying console rather than returning an empty string from the parent class' method.I'm a maintainer of https://github.com/mkdocs/mkdocs-click and I noticed that users of
rich-click
commands were not rendering the usage properly because this line was returning nothing. The choice to return text here is both out of necessity because the current context is inaccessible to that method and also because we happen to desire text so that rendering does not contain any formatting: