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

Rich Click breaks contract of Click's format_help and its callers #88

Closed
BrutalSimplicity opened this issue Sep 27, 2022 · 0 comments
Closed

Comments

@BrutalSimplicity
Copy link
Contributor

In Click, get_help calls the format_help method with a formatter that is expected to hold a buffer of the text that should be returned from the method as a string. Since rich_click does not write the terminal output to the buffer, but directly to the console, it breaks callers of get_help that expect to receive the console output.

def get_help(self, ctx: Context) -> str:
    """Formats the help into a string and returns it.

    Calls :meth:`format_help` internally.
    """
    formatter = ctx.make_formatter()
    self.format_help(ctx, formatter)
    return formatter.getvalue().rstrip("\n")

This may not be a problem for rich_click to solve, as I'm not sure the formatter interface would support all of the capabilities of Rich. But, it would be great if the API of Click could be maintained.

Is this a problem that can be fixed by the following:

  1. Pass a string buffer to Rich Console that writes help output.
  2. Create a stub formatter implementing the getvalue method that returns the string buffer, or, override the get_help method to call format_help without the formatter and return the string buffer directly from Rich.

Rich Reference:

BrutalSimplicity added a commit to BrutalSimplicity/rich-click that referenced this issue Oct 23, 2022
BrutalSimplicity added a commit to BrutalSimplicity/rich-click that referenced this issue Oct 23, 2022
… formatting

- Adhere to click `HelpFormatter` interface
- Add tests :D

See ewels#89 ewels#88 ewels#25 ewels#19
@ewels ewels closed this as completed Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants