Skip to content
Closed
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
30 changes: 30 additions & 0 deletions docs/tutorial/commands/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ Commands:
delete-all Delete ALL users in the database.
init Initialize the users database.

### How Typer generates `--help` output

Typer builds command-line interfaces on top of
[Click](https://click.palletsprojects.com/), which means all `--help`
output is ultimately generated by Click.

Typer automatically:

- Converts function names into command names
- Converts function parameters into CLI options and arguments
- Uses type hints and default values to generate help text

For example:

```python
import typer

app = typer.Typer()

@app.command()
def greet(name: str, formal: bool = False):
"""
Say hello to a user.
"""
if formal:
typer.echo(f"Hello {name}.")
else:
typer.echo(f"Hi {name}!")


Copy link
Member

Choose a reason for hiding this comment

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

// Now the commands have inline help 🎉

// Check the help for create
Expand Down
18 changes: 18 additions & 0 deletions tests/test_help_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import typer
from typer.testing import CliRunner

runner = CliRunner()


def test_default_value_in_help():
app = typer.Typer()

@app.command()
def hello(name: str = "World"):
typer.echo(f"Hello {name}")

result = runner.invoke(app, ["--help"])

assert result.exit_code == 0
assert "World" in result.output