Skip to content
Myr

🐛 Ensure an optional argument is shown in brackets, even when `metavar` is set (#1409)

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

authored by Sofie Van Landeghem · committed by GitHub · parent bc43a7a · Browse files · 6 files+10 added−9 removed
This commit

State

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

Diff stats

6 files+10 added−9 removed

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

6 files+10 added−9 removed

modified:docs/tutorial/arguments/help.md+2 added-2 removed
176 unmodified lines
177178```console179$ python main.py --help180181Usage: main.py [OPTIONS] ✨username✨181Usage: main.py [OPTIONS] [✨username✨]182183Arguments:184 ✨username✨ [default: World]184 [✨username✨] [default: World]185186Options:187 --help Show this message and exit.188```
105 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial005_an.py+1 added-1 removed
10 unmodified lines
1112def test_help():13 result = runner.invoke(app, ["--help"])14 assert result.exit_code == 015 assert "[OPTIONS] [NAME]" in result.output15 assert "Usage: main [OPTIONS] [NAME]" in result.output16 assert "Arguments" in result.output17 assert "Who to greet" in result.output18 assert "[default: (Deadpoolio the amazing's name)]" in result.output19
14 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial005.py+1 added-1 removed
10 unmodified lines
1112def test_help():13 result = runner.invoke(app, ["--help"])14 assert result.exit_code == 015 assert "[OPTIONS] [NAME]" in result.output15 assert "Usage: main [OPTIONS] [NAME]" in result.output16 assert "Arguments" in result.output17 assert "Who to greet" in result.output18 assert "[default: (Deadpoolio the amazing's name)]" in result.output19
14 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial006_an.py+1 added-2 removed
10 unmodified lines
1112def test_help():13 result = runner.invoke(app, ["--help"])14 assert result.exit_code == 015 assert "[OPTIONS] ✨username✨" in result.output15 assert "Usage: main [OPTIONS] [✨username✨]" in result.output16 assert "Arguments" in result.output17 assert "✨username✨" in result.output17 assert "[default: World]" in result.output181920def test_call_arg():
12 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial006.py+1 added-2 removed
10 unmodified lines
1112def test_help():13 result = runner.invoke(app, ["--help"])14 assert result.exit_code == 015 assert "[OPTIONS] ✨username✨" in result.output15 assert "Usage: main [OPTIONS] [✨username✨]" in result.output16 assert "Arguments" in result.output17 assert "✨username✨" in result.output17 assert "[default: World]" in result.output181920def test_call_arg():
12 unmodified lines
modified:typer/core.py+4 added-1 removed
381 unmodified lines
382 def make_metavar(self, ctx: Union[click.Context, None] = None) -> str:383 # Modified version of click.core.Argument.make_metavar()384 # to include Argument name385 if self.metavar is not None:386 return self.metavar386 var = self.metavar387 if not self.required and not var.startswith("["):388 var = f"[{var}]"389 return var390 var = (self.name or "").upper()391 if not self.required:392 var = f"[{var}]"393 # TODO: When deprecating Click < 8.2, remove this
440 unmodified lines