Skip to content
Myr

Merge pull request #1008 from zacbir/short-help

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

Recreate #446

authored by Zachery Bir · committed by GitHub · parents 895bb96, 7927546 · Browse files · 2 files+16 added−23 removed
This commit

State

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

Diff stats

2 files+16 added−23 removed

  • tests:+2 added−8 removed
  • other:+14 added−15 removed

2 files+16 added−23 removed

modified:click/core.py+14 added-15 removed
779 unmodified lines
780 self.params = params or []781 self.help = help782 self.epilog = epilog783 self.options_metavar = options_metavar784 if short_help is None and help:785 if (context_settings is not None and786 'short_help_width' in context_settings):787 short_width = context_settings.get('short_help_width')788 short_help = make_default_short_help(help, short_width)789 else:790 short_help = make_default_short_help(help)784 self.short_help = short_help785 self.add_help_option = add_help_option786 self.hidden = hidden787 self.deprecated = deprecated
235 unmodified lines
1023 def format_commands(self, ctx, formatter):1024 """Extra format methods for multi methods that adds all the commands1025 after the options.1026 """1034 rows = []1027 commands = []1028 for subcommand in self.list_commands(ctx):1029 cmd = self.get_command(ctx, subcommand)1030 # What is this, the tool lied about a command. Ignore it1031 if cmd is None:1032 continue1033 if cmd.hidden:1034 continue10351043 help = cmd.short_help or ''1044 if cmd.deprecated:1045 help += DEPRECATED_HELP_NOTICE1046 rows.append((subcommand, help))1036 commands.append((subcommand, cmd))10371048 if rows:1049 with formatter.section('Commands'):1050 formatter.write_dl(rows)1038 # allow for 3 times the default spacing1039 if len(commands):1040 limit = formatter.width - 6 - max(len(cmd[0]) for cmd in commands)10411042 rows = []1043 for subcommand, cmd in commands:1044 help = cmd.short_help or cmd.help and make_default_short_help(cmd.help, limit)1045 rows.append((subcommand, help or ''))10461047 if rows:1048 with formatter.section('Commands'):1049 formatter.write_dl(rows)10501051 def parse_args(self, ctx, args):1052 if not args and self.no_args_is_help and not ctx.resilient_parsing:1053 echo(ctx.get_help(), color=ctx.color)1054 ctx.exit()
772 unmodified lines
modified:tests/test_commands.py+2 added-8 removed
57 unmodified lines
58 def long():59 """This is a long text that is too long to show as short help60 and will be truncated instead."""6162 @cli.command(context_settings={'short_help_width': 20})63 def width():64 """This is a long text that is too long to show as short help65 and will be truncated instead."""6662 result = runner.invoke(cli, ['--help'])63 assert re.search(64 r'Commands:\n\s+'70 r'long\s+This is a long text that is too long to show\.\.\.\n\s+'65 r'long\s+This is a long text that is too long to show as short help\.\.\.\n\s+'66 r'short\s+This is a short text\.\n\s+'72 r'special-chars\s+Login and store the token in ~/.netrc\.\s+'73 r'width\s+This is a long text\.\.\.\n\s*',67 r'special-chars\s+Login and store the token in ~/.netrc\.\s*',68 result.output) is not None697071def test_default_maps(runner):
212 unmodified lines