Skip to content

Commit

Permalink
Merge pull request #1002 from fdavis/customize_short_width
Browse files Browse the repository at this point in the history
allow specify short width to address cmd formatting
  • Loading branch information
Dan Sully committed May 15, 2018
2 parents bd59717 + 639daa4 commit b4d2d32
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
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
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 b4d2d32

Please sign in to comment.