Skip to content
Myr

include parent args in subcommand help synopsis

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

authored by Amy · committed by David Lord · parent 6c1eaba · Browse files · 3 files+47 added−1 removed
This commit

State

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

Diff stats

3 files+47 added−1 removed

  • tests:+41 added−0 removed
  • other:+6 added−1 removed

3 files+47 added−1 removed

modified:src/click/core.py+4 added-1 removed
506 unmodified lines
507 rv = ""508 if self.info_name is not None:509 rv = self.info_name510 if self.parent is not None:511 rv = f"{self.parent.command_path} {rv}"511 parent_command_path = [self.parent.command_path]512 for param in self.parent.command.get_params(self):513 parent_command_path.extend(param.get_usage_pieces(self))514 rv = f"{' '.join(parent_command_path)} {rv}"515 return rv.lstrip()516517 def find_root(self):518 """Finds the outermost context."""
1572 unmodified lines
modified:tests/test_arguments.py+41 added
326 unmodified lines
327328 result = runner.invoke(cmd)329 assert result.exit_code == code330 assert output in result.output331332333def test_subcommand_help(runner):334 @click.group()335 @click.argument("name")336 @click.argument("val")337 @click.option("--opt")338 @click.pass_context339 def cli(ctx, name, val, opt):340 ctx.obj = dict(name=name, val=val)341342 @cli.command()343 @click.pass_obj344 def cmd(obj):345 click.echo(f"CMD for {obj['name']} with value {obj['val']}")346347 result = runner.invoke(cli, ["foo", "bar", "cmd", "--help"])348 assert not result.exception349 assert "Usage: cli NAME VAL cmd [OPTIONS]" in result.output350351352def test_nested_subcommand_help(runner):353 @click.group()354 @click.argument("arg1")355 @click.option("--opt1")356 def cli(arg1, opt1):357 pass358359 @cli.group()360 @click.argument("arg2")361 @click.option("--opt2")362 def cmd(arg2, opt2):363 pass364365 @cmd.command()366 def subcmd():367 click.echo("subcommand")368369 result = runner.invoke(cli, ["arg1", "cmd", "arg2", "subcmd", "--help"])370 assert not result.exception371 assert "Usage: cli ARG1 cmd ARG2 subcmd [OPTIONS]" in result.output
modified:CHANGES.rst+2 added
33 unmodified lines
34- ``nargs == -1`` and ``nargs > 1`` is parsed and validated for35 values from environment variables and defaults. :issue:`729`36- Detect the program name when executing a module or package with37 ``python -m name``. :issue:`1603`38- Include required parent arguments in help synopsis of subcommands.39 :issue:`1475`404142Version 7.1.243-------------
635 unmodified lines