Skip to content
Myr

fix newline wrapping in option help

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

authored by David Lord · committed by David Lord · parent 70c4493 · Browse files · 4 files+32 added−20 removed
This commit

State

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

Diff stats

4 files+32 added−20 removed

  • tests:+21 added−13 removed
  • other:+11 added−7 removed

4 files+32 added−20 removed

modified:click/core.py+1 added-2 removed
943 unmodified lines
944 opts = []945 for param in self.get_params(ctx):946 rv = param.get_help_record(ctx)947 if rv is not None:948 part_a, part_b = rv949 opts.append((part_a, part_b.replace('\n', ' ')))948 opts.append(rv)949950 if opts:951 with formatter.section('Options'):952 formatter.write_dl(opts)
943 unmodified lines
modified:click/formatting.py+7 added-5 removed
196 unmodified lines
197 self.write('\n')198 self.write(' ' * (first_col + self.current_indent))199200 text_width = max(self.width - first_col - 2, 10)201 lines = iter(wrap_text(second, text_width).splitlines())201 wrapped_text = wrap_text(second, text_width, preserve_paragraphs=True)202 lines = wrapped_text.splitlines()203204 if lines:203 self.write(next(lines) + '\n')204 for line in lines:205 self.write('%*s%s\n' % (206 first_col + self.current_indent, '', line))205 self.write(lines[0] + '\n')206207 for line in lines[1:]:208 self.write('%*s%s\n' % (first_col + self.current_indent, '', line))209 else:210 self.write('\n')211212 @contextmanager
46 unmodified lines
modified:tests/test_options.py+21 added-13 removed
406 unmodified lines
407 assert result.exit_code == 0408 assert result.output == 'Apple\n'409410411def test_multiline_help(runner):411def test_option_help_preserve_paragraphs(runner):412 @click.command()413 @click.option('--foo', help="""414 hello413 @click.option(414 "-C",415 "--config",416 type=click.Path(),417 help="""Configuration file to use.418 419 If not given, the environment variable CONFIG_FILE is consulted420 and used if set. If neither are given, a default configuration421 file is loaded.""",422 )423 def cmd(config):424 pass425416 i am417418 multiline419 """)420 def cmd(foo):421 click.echo(foo)422423 result = runner.invoke(cmd, ['--help'])426 result = runner.invoke(cmd, ['--help'], )427 assert result.exit_code == 0425 out = result.output.splitlines()426 assert ' --foo TEXT hello i am multiline' in out428 assert (429 " -C, --config PATH Configuration file to use.\n"430 "{i}\n"431 "{i}If not given, the environment variable CONFIG_FILE is\n"432 "{i}consulted and used if set. If neither are given, a default\n"433 "{i}configuration file is loaded.".format(i=" " * 21)434 ) in result.output435436def test_argument_custom_class(runner):437 class CustomArgument(click.Argument):438 def get_default(self, ctx):
118 unmodified lines
modified:CHANGES.rst+3 added
44 unmodified lines
45- Fix how default values for file-type options are shown during46 prompts. :issue:`914`47- Fix environment variable automatic generation for commands48 containing ``-``. :issue:`1253`49- Option help text replaces newlines with spaces when rewrapping, but50 preserves paragraph breaks, fixing multiline formatting.51 :issue:`834, 1066, 1397`525354Version 7.055-----------
540 unmodified lines