Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow specify short width to address cmd formatting #1002

Merged
merged 1 commit into from
May 15, 2018
Merged
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
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