Click: Support extracting option help message from docstring.

Created on 11 Aug 2018  路  3Comments  路  Source: pallets/click

I thought, for the sake of consistency across my code-base project, it would be an interesting idea to annotate the help messages for the parameters in the docstring for the function instead of in each decorator. Example:

@click.command()
@click.option('--name', default=None)
@click.option('--age', type=int, default=None)
def my_cli(name, age):
    """
    Does cli-ish things

    :param name: The name of the user.
    :param age: The age of the user.
    """
    print(f"Hello {name if name is not None else "stranger"}, you were born {age if age is not None else "many"} years ago")

This presents some (small) issues. Docstring special keywords are not stripped from the help menu, for example.

I'd like to gauge people's interest in this before dedicating more time beyond the first prototype.

Most helpful comment

Docstring parsing can be provided by an existing docstring-parsing package, docstring_parser, supporting ReST-style and Google-style docstrings (with easy extensibility to other styles: see my PR for NumPy-style)

All 3 comments

I would love this feature. Just thought how brittle it is to copy and paste the same information from my docstrings to the help arguments in the decorators.

Docstring parsing can be provided by an existing docstring-parsing package, docstring_parser, supporting ReST-style and Google-style docstrings (with easy extensibility to other styles: see my PR for NumPy-style)

The docstring_parser looks interesting, but I don't want to start maintaining something similar to that in Click core. This seems like a good idea for an extension.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BeyondEvil picture BeyondEvil  路  3Comments

kshitij10496 picture kshitij10496  路  4Comments

joveice picture joveice  路  3Comments

ror6ax picture ror6ax  路  4Comments

arecker picture arecker  路  3Comments