Skip to content

Commit

Permalink
allow specify short width to address cmd formatting
Browse files Browse the repository at this point in the history
try to address the too short short_help width as requested in

pallets#936
  • Loading branch information
fdavis committed May 15, 2018
1 parent 1782e21 commit 639daa4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,12 @@ def __init__(self, name, context_settings=None, callback=None,
self.epilog = epilog
self.options_metavar = options_metavar
if short_help is None and help:
short_help = make_default_short_help(help)
if (context_settings is not None and
'short_help_width' in context_settings):
short_width = context_settings.get('short_help_width')
short_help = make_default_short_help(help, short_width)
else:
short_help = make_default_short_help(help)
self.short_help = short_help
self.add_help_option = add_help_option
self.hidden = hidden
Expand Down
8 changes: 7 additions & 1 deletion tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ def long():
"""This is a long text that is too long to show as short help
and will be truncated instead."""

@cli.command(context_settings={'short_help_width': 20})
def width():
"""This is a long text that is too long to show as short help
and will be truncated instead."""

result = runner.invoke(cli, ['--help'])
assert re.search(
r'Commands:\n\s+'
r'long\s+This is a long text that is too long to show\.\.\.\n\s+'
r'short\s+This is a short text\.\n\s+'
r'special-chars\s+Login and store the token in ~/.netrc\.\s*',
r'special-chars\s+Login and store the token in ~/.netrc\.\s+'
r'width\s+This is a long text\.\.\.\n\s*',
result.output) is not None


Expand Down

0 comments on commit 639daa4

Please sign in to comment.