Skip to content
Myr

Merge pull request #1091 from sirosen/truncate-help

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Rebase of #629; allow use of page break to split docstring-based helptext

authored by David Lord · committed by GitHub · parents fb3e9d2, f9e0dbe · Browse files · 3 files+67 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+67 added−0 removed

  • tests:+29 added−0 removed
  • other:+38 added−0 removed

3 files+67 added−0 removed

modified:click/core.py+4 added
776 unmodified lines
777 #: the list of parameters for this command in the order they778 #: should show up in the help page and execute. Eager parameters779 #: will automatically be handled before non eager ones.780 self.params = params or []781 # if a form feed (page break) is found in the help text, truncate help782 # text to the content preceding the first form feed783 if help and '\f' in help:784 help = help.split('\f', 1)[0]785 self.help = help786 self.epilog = epilog787 self.options_metavar = options_metavar788 self.short_help = short_help
1046 unmodified lines
modified:docs/documentation.rst+34 added
76 unmodified lines
77 invoke(cli, args=['--help'])7879.. _doc-meta-variables:8081Truncating Help Texts82---------------------8384Click gets command help text from function docstrings. However if you85already use docstrings to document function arguments you may not want86to see :param: and :return: lines in your help text.8788You can use the ``\f`` escape marker to have Click truncate the help text89after the marker.9091Example:9293.. click:example::9495 @click.command()96 @click.pass_context97 def cli(ctx):98 """First paragraph.99100 This is a very long second101 paragraph and not correctly102 wrapped but it will be rewrapped.103 \f104105 :param click.core.Context ctx: Click context.106 """107108And what it looks like:109110.. click:run::111112 invoke(cli, args=['--help'])113114115Meta Variables116--------------117118Options and parameters accept a ``metavar`` argument that can change the
79 unmodified lines
modified:tests/test_formatting.py+29 added
266 unmodified lines
267 '',268 'Options:',269 ' --help Show this message and exit.'270 ]271272273def test_truncating_docstring(runner):274 @click.command()275 @click.pass_context276 def cli(ctx):277 """First paragraph.278279 This is a very long second280 paragraph and not correctly281 wrapped but it will be rewrapped.282 \f283284 :param click.core.Context ctx: Click context.285 """286287 result = runner.invoke(cli, ['--help'], terminal_width=60)288 assert not result.exception289 assert result.output.splitlines() == [290 'Usage: cli [OPTIONS]',291 '',292 ' First paragraph.',293 '',294 ' This is a very long second paragraph and not correctly',295 ' wrapped but it will be rewrapped.',296 '',297 'Options:',298 ' --help Show this message and exit.',299 ]