Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,8 @@ def __init__(self, name, context_settings=None, callback=None,
#: should show up in the help page and execute. Eager parameters
#: will automatically be handled before non eager ones.
self.params = params or []
if help and '\f' in help:

This comment was marked as off-topic.

help = help.split('\f', 1)[0]
self.help = help
self.epilog = epilog
self.options_metavar = options_metavar
Expand Down
34 changes: 34 additions & 0 deletions docs/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,40 @@ And what it looks like:
invoke(cli, args=['--help'])


Truncating Help Texts
---------------------

Click gets command help text from function docstrings. However if you
already use docstrings to document function arguments you may not want
to see :param: and :return: lines in your help text.

You can use the ``\f`` escape marker to have Click truncate the help text
after the marker.

Example:

.. click:example::

@click.command()
@click.pass_context
def cli(ctx):
"""First paragraph.

This is a very long second
paragraph and not correctly
wrapped but it will be rewrapped.
\f

:param click.core.Context ctx: Click context.
"""

And what it looks like:

.. click:run::

invoke(cli, args=['--help'])


Meta Variables
--------------

Expand Down
29 changes: 29 additions & 0 deletions tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,32 @@ def cmd(arg):
'',
'Error: Missing argument "arg".'
]


def test_truncating_docstring(runner):
@click.command()
@click.pass_context
def cli(ctx):
"""First paragraph.

This is a very long second
paragraph and not correctly
wrapped but it will be rewrapped.
\f

:param click.core.Context ctx: Click context.
"""

result = runner.invoke(cli, ['--help'], terminal_width=60)
assert not result.exception
assert result.output.splitlines() == [
'Usage: cli [OPTIONS]',
'',
' First paragraph.',
'',
' This is a very long second paragraph and not correctly',
' wrapped but it will be rewrapped.',
'',
'Options:',
' --help Show this message and exit.',
]