Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/tutorial/arguments/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ Now the generated help text will have `✨username✨` instead of `NAME`:
```console
$ python main.py --help

Usage: main.py [OPTIONS] ✨username✨
Usage: main.py [OPTIONS] [✨username✨]

Arguments:
✨username✨ [default: World]
[✨username✨] [default: World]

Options:
--help Show this message and exit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "Usage: main [OPTIONS] [NAME]" in result.output
assert "Arguments" in result.output
assert "Who to greet" in result.output
assert "[default: (Deadpoolio the amazing's name)]" in result.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "Usage: main [OPTIONS] [NAME]" in result.output
assert "Arguments" in result.output
assert "Who to greet" in result.output
assert "[default: (Deadpoolio the amazing's name)]" in result.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] ✨username✨" in result.output
assert "Usage: main [OPTIONS] [✨username✨]" in result.output
assert "Arguments" in result.output
assert "✨username✨" in result.output
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this second assert was always redundant, as L18 would already fail if this wasn't the case.

assert "[default: World]" in result.output


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] ✨username✨" in result.output
assert "Usage: main [OPTIONS] [✨username✨]" in result.output
assert "Arguments" in result.output
assert "✨username✨" in result.output
assert "[default: World]" in result.output


Expand Down
5 changes: 4 additions & 1 deletion typer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ def make_metavar(self, ctx: Union[click.Context, None] = None) -> str:
# Modified version of click.core.Argument.make_metavar()
# to include Argument name
if self.metavar is not None:
return self.metavar
var = self.metavar
if not self.required and not var.startswith("["):
var = f"[{var}]"
return var
var = (self.name or "").upper()
if not self.required:
var = f"[{var}]"
Expand Down
Loading