From 639daa4f43da2aa152c415a1bba35fa48aa87259 Mon Sep 17 00:00:00 2001 From: Fletcher Davis Date: Tue, 15 May 2018 06:48:00 -0700 Subject: [PATCH] allow specify short width to address cmd formatting try to address the too short short_help width as requested in https://github.com/pallets/click/issues/936 --- click/core.py | 7 ++++++- tests/test_commands.py | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/click/core.py b/click/core.py index 23a34c0b8..84a39413e 100644 --- a/click/core.py +++ b/click/core.py @@ -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 diff --git a/tests/test_commands.py b/tests/test_commands.py index e8a95351b..af58e7a7c 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -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