Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b0538d8
updated tests for more consistent & clean metavar printing
svlandeg Jun 27, 2026
fc37d3a
remove upper
svlandeg Jun 27, 2026
a3e0136
unify type names to Python types
svlandeg Jun 27, 2026
121c307
choices with <>
svlandeg Jun 27, 2026
bb19693
add {} when argument is required
svlandeg Jun 27, 2026
d9c5943
add <> around the metavar type
svlandeg Jun 27, 2026
7186161
avoid lowercasing the parameters at declaration
svlandeg Jun 27, 2026
d59858a
avoid two types of brackets
svlandeg Jun 27, 2026
c0c90c9
fix arg display in help
svlandeg Jun 27, 2026
adf1967
Merge branch 'master' into feat/metavar
svlandeg Jul 7, 2026
9c8aaa7
change metavar display depending on being in usage line or not
svlandeg Jul 7, 2026
1524376
fix test
svlandeg Jul 7, 2026
80f5461
use human_readable_name for error hint
svlandeg Jul 7, 2026
6a4aef8
fix enum display
svlandeg Jul 7, 2026
43a8137
make ID uppercase var in the docs
svlandeg Jul 7, 2026
87a70d3
few more small fixes
svlandeg Jul 7, 2026
4daef8c
add test_param_type_help_metavar test
svlandeg Jul 8, 2026
7c19318
🎨 Auto format
pre-commit-ci-lite[bot] Jul 8, 2026
95d4ca4
fix coverage
svlandeg Jul 8, 2026
3e6c575
fix miminum example file from tutorial not showing [PATH_OR_MODULE]
svlandeg Jul 10, 2026
16988d7
fix coverage
svlandeg Jul 10, 2026
135187e
ensure Rich doesn't swallow a lowercased path_or_module annotation
svlandeg Jul 10, 2026
6340753
ensure Rich doesn't print <boolean> for flags
svlandeg Jul 10, 2026
72b8cd9
docs fixes (WIP)
svlandeg Jul 10, 2026
4e08df7
fix javascript to escape html
svlandeg Jul 10, 2026
780f111
final fixes first page of tutorial
svlandeg Jul 10, 2026
cbf3950
restore all the HTML we do want :-)
svlandeg Jul 10, 2026
33eb269
many more docs fixes (still WIP)
svlandeg Jul 10, 2026
2c31874
fix types vs HTML tags, continued
svlandeg Jul 10, 2026
df30ebc
update docstrings to be consistent
svlandeg Jul 10, 2026
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
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,29 @@ Run your application with the `typer` command:
// Run your application
$ typer main.py run

// You get a nice error, you are missing NAME
Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME
// You get a nice error, you are missing 'name'
Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}
Try 'typer [PATH_OR_MODULE] run --help' for help.
╭─ Error ───────────────────────────────────────────╮
│ Missing argument 'NAME'. │
│ Missing argument 'name'. │
╰───────────────────────────────────────────────────╯


// You get a --help for free
$ typer main.py run --help

Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME
Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}

Run the provided Typer app.

╭─ Arguments ───────────────────────────────────────╮
│ * name TEXT [default: None] [required] |
│ * name <str> [required]
╰───────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────╮
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────╯

// Now pass the NAME argument
// Now pass the 'name' argument
$ typer main.py run Camila

Hello Camila
Expand Down Expand Up @@ -138,27 +138,27 @@ Now you could run it with Python directly:
// Run your application
$ python main.py

// You get a nice error, you are missing NAME
Usage: main.py [OPTIONS] NAME
// You get a nice error, you are missing 'name'
Usage: main.py [OPTIONS] {name}
Try 'main.py --help' for help.
╭─ Error ───────────────────────────────────────────╮
│ Missing argument 'NAME'. │
│ Missing argument 'name'. │
╰───────────────────────────────────────────────────╯


// You get a --help for free
$ python main.py --help

Usage: main.py [OPTIONS] NAME
Usage: main.py [OPTIONS] {name}

╭─ Arguments ───────────────────────────────────────╮
│ * name TEXT [default: None] [required] |
│ * name <str> [required]
╰───────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────╮
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────╯

// Now pass the NAME argument
// Now pass the 'name' argument
$ python main.py Camila

Hello Camila
Expand Down Expand Up @@ -236,8 +236,8 @@ $ python main.py --help
│ and exit. │
╰───────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────╮
│ goodbye │
│ hello │
│ goodbye │
╰───────────────────────────────────────────────────╯

// When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion
Expand All @@ -254,10 +254,10 @@ Now check the help for the `hello` command:
```console
$ python main.py hello --help

Usage: main.py hello [OPTIONS] NAME
Usage: main.py hello [OPTIONS] {name}

╭─ Arguments ───────────────────────────────────────╮
│ * name TEXT [default: None] [required] │
│ * name <str> [required]
╰───────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────╮
│ --help Show this message and exit. │
Expand All @@ -273,10 +273,10 @@ And now check the help for the `goodbye` command:
```console
$ python main.py goodbye --help

Usage: main.py goodbye [OPTIONS] NAME
Usage: main.py goodbye [OPTIONS] {name}

╭─ Arguments ───────────────────────────────────────╮
│ * name TEXT [default: None] [required] │
│ * name <str> [required]
╰───────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────╮
│ --formal --no-formal [default: no-formal] │
Expand Down
34 changes: 17 additions & 17 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,29 @@ Run your application with the `typer` command:
// Run your application
$ typer main.py run

// You get a nice error, you are missing NAME
Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME
// You get a nice error, you are missing 'name'
Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}
Try 'typer [PATH_OR_MODULE] run --help' for help.
╭─ Error ───────────────────────────────────────────╮
│ Missing argument 'NAME'. │
│ Missing argument 'name'. │
╰───────────────────────────────────────────────────╯


// You get a --help for free
$ typer main.py run --help

Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME
Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}

Run the provided Typer app.

╭─ Arguments ───────────────────────────────────────╮
│ * name TEXT [default: None] [required] |
│ * name <str> [required]
╰───────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────╮
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────╯

// Now pass the NAME argument
// Now pass the 'name' argument
$ typer main.py run Camila

Hello Camila
Expand Down Expand Up @@ -146,27 +146,27 @@ Now you could run it with Python directly:
// Run your application
$ python main.py

// You get a nice error, you are missing NAME
Usage: main.py [OPTIONS] NAME
// You get a nice error, you are missing 'name'
Usage: main.py [OPTIONS] {name}
Try 'main.py --help' for help.
╭─ Error ───────────────────────────────────────────╮
│ Missing argument 'NAME'. │
│ Missing argument 'name'. │
╰───────────────────────────────────────────────────╯


// You get a --help for free
$ python main.py --help

Usage: main.py [OPTIONS] NAME
Usage: main.py [OPTIONS] {name}

╭─ Arguments ───────────────────────────────────────╮
│ * name TEXT [default: None] [required] |
│ * name <str> [required]
╰───────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────╮
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────╯

// Now pass the NAME argument
// Now pass the 'name' argument
$ python main.py Camila

Hello Camila
Expand Down Expand Up @@ -244,8 +244,8 @@ $ python main.py --help
│ and exit. │
╰───────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────╮
│ goodbye │
│ hello │
│ goodbye │
╰───────────────────────────────────────────────────╯

// When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion
Expand All @@ -262,10 +262,10 @@ Now check the help for the `hello` command:
```console
$ python main.py hello --help

Usage: main.py hello [OPTIONS] NAME
Usage: main.py hello [OPTIONS] {name}

╭─ Arguments ───────────────────────────────────────╮
│ * name TEXT [default: None] [required] │
│ * name <str> [required]
╰───────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────╮
│ --help Show this message and exit. │
Expand All @@ -281,10 +281,10 @@ And now check the help for the `goodbye` command:
```console
$ python main.py goodbye --help

Usage: main.py goodbye [OPTIONS] NAME
Usage: main.py goodbye [OPTIONS] {name}

╭─ Arguments ───────────────────────────────────────╮
│ * name TEXT [default: None] [required] │
│ * name <str> [required]
╰───────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────╮
│ --formal --no-formal [default: no-formal] │
Expand Down
21 changes: 20 additions & 1 deletion docs/js/custom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
function escapePlainCliLine(line) {
return line
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
}

function prepareTermynalLines(lines, isRichHtml) {
if (isRichHtml) {
return lines.join("<br>");
}
return lines.map(escapePlainCliLine).join("<br>");
}

function setupTermynal() {
document.querySelectorAll(".use-termynal").forEach(node => {
node.style.display = "block";
Expand All @@ -17,6 +31,11 @@ function setupTermynal() {
.forEach(node => {
const text = node.textContent;
const lines = text.split("\n");
// If it's a type in brackets like <str>, it doesn't have a space
// and won't have a closing tag, while Rich HTML tags do.
const hasOpeningTagWithSpace = /<[a-zA-Z0-9]+\s/.test(text);
const hasClosingTag = /<\/[a-zA-Z0-9]+>/.test(text);
const isRichHtml = hasOpeningTagWithSpace || hasClosingTag;
const useLines = [];
let buffer = [];
function saveBuffer() {
Expand All @@ -36,7 +55,7 @@ function setupTermynal() {
// so put an additional one
buffer.push("");
}
const bufferValue = buffer.join("<br>");
const bufferValue = prepareTermynalLines(buffer, isRichHtml);
dataValue["value"] = bufferValue;
useLines.push(dataValue);
buffer = [];
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorial/arguments/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Check it:
$ python main.py --help

// Notice the [default: Wade Wilson] ✨
Usage: main.py [OPTIONS] [NAME]
Usage: main.py [OPTIONS] [name]

Arguments:
[NAME] [default: Wade Wilson]
[name] [default: Wade Wilson]

Options:
--help Show this message and exit.
Expand Down Expand Up @@ -72,10 +72,10 @@ Check it:
// Check the help
$ python main.py --help

Usage: main.py [OPTIONS] [NAME]
Usage: main.py [OPTIONS] [name]

Arguments:
[NAME] [default: (dynamic)]
[name] [default: (dynamic)]

Options:
--help Show this message and exit.
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorial/arguments/envvar.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ In this case, the *CLI argument* `name` will have a default value of `"World"`,
// Check the help
$ python main.py --help

Usage: main.py [OPTIONS] [NAME]
Usage: main.py [OPTIONS] [name]

Arguments:
[NAME] [env var: AWESOME_NAME;default: World]
[name] [env var: AWESOME_NAME;default: World]

Options:
--help Show this message and exit.
Expand Down Expand Up @@ -65,10 +65,10 @@ Check it:
// Check the help
$ python main.py --help

Usage: main.py [OPTIONS] [NAME]
Usage: main.py [OPTIONS] [name]

Arguments:
[NAME] [env var: AWESOME_NAME, GOD_NAME;default: World]
[name] [env var: AWESOME_NAME, GOD_NAME;default: World]

Options:
--help Show this message and exit.
Expand Down Expand Up @@ -101,10 +101,10 @@ Check it:
$ python main.py --help

// It won't show the env var
Usage: main.py [OPTIONS] [NAME]
Usage: main.py [OPTIONS] [name]

Arguments:
[NAME] [default: World]
[name] [default: World]

Options:
--help Show this message and exit.
Expand Down
Loading
Loading