Skip to content
Myr

New line indent relative to length of the prefix

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

When putting the arguments on the next line, indent them 4 spaces more than the "Usage: " prefix.

authored by Mark Thomas · committed by Mark Thomas · parent d8a7cea · Browse files · 2 files+9 added−8 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+9 added−8 removed

  • tests:+3 added−2 removed
  • other:+6 added−6 removed

2 files+9 added−8 removed

modified:click/formatting.py+6 added-6 removed
121 unmodified lines
122 :param prog: the program name.123 :param args: whitespace separated list of arguments.124 :param prefix: the prefix for the first line.125 """126 prefix = '%*s%s ' % (self.current_indent, prefix, prog)126 usage_prefix = '%*s%s ' % (self.current_indent, prefix, prog)127 text_width = self.width - self.current_indent128129 if text_width >= (term_len(prefix) + 20):129 if text_width >= (term_len(usage_prefix) + 20):130 # The arguments will fit to the right of the prefix.131 indent = ' ' * term_len(prefix)131 indent = ' ' * term_len(usage_prefix)132 self.write(wrap_text(args, text_width,133 initial_indent=prefix,133 initial_indent=usage_prefix,134 subsequent_indent=indent))135 else:136 # The prefix is too long, put the arguments on the next line.137 self.write(prefix)137 self.write(usage_prefix)138 self.write('\n')139 indent = ' ' * (self.current_indent + 12)139 indent = ' ' * (max(self.current_indent, term_len(prefix)) + 4)140 self.write(wrap_text(args, text_width,141 initial_indent=indent,142 subsequent_indent=indent))143
107 unmodified lines
modified:tests/test_formatting.py+3 added-2 removed
114 unmodified lines
115 terminal_width=54)116 assert not result.exception117 assert result.output.splitlines() == [118 'Usage: cli a_very_very_very_long command ',119 ' [OPTIONS] FIRST SECOND THIRD FOURTH FIFTH',120 ' SIXTH',119 ' [OPTIONS] FIRST SECOND THIRD FOURTH FIFTH',120 ' SIXTH',121 '',122 ' A command.',123 '',124 'Options:',125 ' --help Show this message and exit.',126 ]127128129def test_formatting_empty_help_lines(runner):130 @click.command()131 def cli():132 """Top level command
15 unmodified lines