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

Documentation truncated when \f is present in the docstring #96

Closed
maxcmoi89 opened this issue Mar 28, 2022 · 2 comments
Closed

Documentation truncated when \f is present in the docstring #96

maxcmoi89 opened this issue Mar 28, 2022 · 2 comments

Comments

@maxcmoi89
Copy link

Click can truncate the docstring as help text. When inserting \f in the docstring all lines after this are hidden in help. Documentation : https://click.palletsprojects.com/en/8.0.x/documentation/#truncating-help-texts

For my documentation I wanted to have less information for the command --help than what would be present in the documentation. Naively I added a \f thinking that it would be hidden on the --help but present in the Sphinx documentation which was not the case. Sphinx-click gets the ctx.command.help of Click which is trunctated for the documentation. A quick fix could be :

def _format_description(ctx):
    """Format the description for a given `click.Command`.
    We parse this as reStructuredText, allowing users to embed rich
    information in their help messages if they so choose.
    """
    # Gets the ctx.command.__doc__ instead of ctx.command.help to avoid truncation by click class
    help_string = ctx.command.__doc__ or ctx.command.short_help
    if help_string:
        yield from _format_help(help_string)

Instead of :

def _format_description(ctx):
    """Format the description for a given `click.Command`.
    We parse this as reStructuredText, allowing users to embed rich
    information in their help messages if they so choose.
    """
    help_string = ctx.command.help or ctx.command.short_help
    if help_string:
        yield from _format_help(help_string)

Your toughts ?

If this seems good I will do a pull requests with the changes.

@maxcmoi89 maxcmoi89 changed the title Help text truncated when \f is present in the docstring Documentation truncated when \f is present in the docstring Mar 28, 2022
@maxcmoi89
Copy link
Author

It seems like Click \b does not prevent rewrapping anymore with this solution. I tweaked it a little with :

import inspect

def _format_description(ctx):
    """Format the description for a given `click.Command`.
    We parse this as reStructuredText, allowing users to embed rich
    information in their help messages if they so choose.
    """
    # Gets the ctx.command.__doc__ instead of ctx.command.help to avoid truncation by click class
    help_string = inspect.cleandoc(ctx.command.__doc__) or ctx.command.short_help

    if help_string:
        yield from _format_help(help_string)

which seems to be working. I will test it some more before doing a pull request.

@stephenfin
Copy link
Member

This is a duplicate of #56. Note that your proposed solution would only work if the user is defining their help strings using docstring as opposed to the Command.help argument. I think we'd be better off relying on pallets/click#2151 which was included in click 8.1.0 and means click now stores raw strings, allowing us to process this stuff manually.

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

No branches or pull requests

2 participants