Skip to content
Myr

💥 Update metavar printing (#1863)

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 3a3bd0f · Browse files · 133 files+685 added−454 removed
This commit

State

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

Trailers

  • Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>

Diff stats

133 files+685 added−454 removed

  • tests:+316 added−136 removed
  • other:+369 added−318 removed

133 files+685 added−454 removed

modified:docs/js/custom.js+25 added-2 removed
modified:docs/tutorial/arguments/default.md+4 added-4 removed
25 unmodified lines
26// Check the help27$ python main.py --help2829// Notice the [default: Wade Wilson] ✨30Usage: main.py [OPTIONS] [NAME]30Usage: main.py [OPTIONS] [name]3132Arguments:33 [NAME] [default: Wade Wilson]33 name [default: Wade Wilson]3435Options:36 --help Show this message and exit.37
33 unmodified lines
71```console72// Check the help73$ python main.py --help7475Usage: main.py [OPTIONS] [NAME]75Usage: main.py [OPTIONS] [name]7677Arguments:78 [NAME] [default: (dynamic)]78 name [default: (dynamic)]7980Options:81 --help Show this message and exit.82
20 unmodified lines
modified:docs/tutorial/arguments/envvar.md+6 added-6 removed
18 unmodified lines
19```console20// Check the help21$ python main.py --help2223Usage: main.py [OPTIONS] [NAME]23Usage: main.py [OPTIONS] [name]2425Arguments:26 [NAME] [env var: AWESOME_NAME;default: World]26 name [env var: AWESOME_NAME; default: World]2728Options:29 --help Show this message and exit.30
33 unmodified lines
64```console65// Check the help66$ python main.py --help6768Usage: main.py [OPTIONS] [NAME]68Usage: main.py [OPTIONS] [name]6970Arguments:71 [NAME] [env var: AWESOME_NAME, GOD_NAME;default: World]71 name [env var: AWESOME_NAME, GOD_NAME; default: World]7273Options:74 --help Show this message and exit.75
24 unmodified lines
100//Check the help101$ python main.py --help102103// It won't show the env var104Usage: main.py [OPTIONS] [NAME]104Usage: main.py [OPTIONS] [name]105106Arguments:107 [NAME] [default: World]107 name [default: World]108109Options:110 --help Show this message and exit.111
7 unmodified lines
modified:docs/tutorial/arguments/help.md+25 added-25 removed
20 unmodified lines
21```console22$ python main.py --help2324// Check the section with Arguments below 🚀25Usage: main.py [OPTIONS] NAME25Usage: main.py [OPTIONS] {name}2627Arguments:28 NAME The name of the user to greet [required]28 name The name of the user to greet [required]2930Options:31 --help Show this message and exit.32```
13 unmodified lines
46```console47$ python main.py --help4849// Notice that we have the help text from the docstring and also the Arguments 📝50Usage: main.py [OPTIONS] NAME50Usage: main.py [OPTIONS] {name}5152 Say hi to NAME very gently, like Dirk.52 Say hi to 'name' very gently, like Dirk.5354Arguments:55 NAME The name of the user to greet [required]55 name The name of the user to greet [required]5657Options:58 --help Show this message and exit.59```
13 unmodified lines
73```console74$ python main.py --help7576// Notice the [default: World] 🔍77Usage: main.py [OPTIONS] [NAME]77Usage: main.py [OPTIONS] [name]7879 Say hi to NAME very gently, like Dirk.79 Say hi to 'name' very gently, like Dirk.8081Arguments:82 [NAME] Who to greet [default: World]82 name Who to greet [default: World]8384Options:85 --help Show this message and exit.86```
11 unmodified lines
98```console99$ python main.py --help100101// Notice the there's no [default: World] now 🔥102Usage: main.py [OPTIONS] [NAME]102Usage: main.py [OPTIONS] [name]103104 Say hi to NAME very gently, like Dirk.104 Say hi to 'name' very gently, like Dirk.105106Arguments:107 [NAME] Who to greet107 name Who to greet108109Options:110 --help Show this message and exit.111```
12 unmodified lines
124125```console126$ python main.py --help127128Usage: main.py [OPTIONS] [NAME]128Usage: main.py [OPTIONS] [name]129130Arguments:131 [NAME] Who to greet [default: (Deadpoolio the amazing's name)]131 name Who to greet [default: (Deadpoolio the amazing's name)]132133134Options:135 --help Show this message and exit.
6 unmodified lines
142## Custom help name (`metavar`)143144You can also customize the text used in the generated help text to represent a *CLI argument*.145146By default, it will be the same name you declared, in uppercase letters.146By default, it will be the same name you declared, with casing preserved.147148So, if you declare it as:149150```Python
2 unmodified lines
153154It will be shown as:155156```157NAME157name158```159160But you can customize it with the `metavar` parameter for `typer.Argument()`.161162For example, let's say you don't want to have the default of `NAME`, you want to have `username`, in lowercase, and you really want ✨ emojis ✨ everywhere:162For example, let's say you don't want to have the default of `name`, you want to have `username`, and you really want ✨ emojis ✨ everywhere:163164{* docs_src/arguments/help/tutorial006_an_py310.py hl[9] *}165166Now the generated help text will have `✨username✨` instead of `NAME`:166Now the generated help text will have `✨username✨` instead of `name`:167168<div class="termy">169170```console
1 unmodified line
172173Usage: main.py [OPTIONS] [✨username✨]174175Arguments:176 [✨username✨] [default: World]176 ✨username✨ [default: World]177178Options:179 --help Show this message and exit.180```
16 unmodified lines
197198```console199$ python main.py --help200201<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] NAME [LASTNAME] [AGE] </b>201<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] {name} [lastname] [age] </b>202<b> </b>203 Say hi to NAME very gently, like Dirk.203 Say hi to 'name' very gently, like Dirk.204205<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>206<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> Who to greet [default: None] <font color="#A6194C">[required]</font> │206<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>str</b></font> Who to greet [default: None] <font color="#A6194C">[required]</font> │207<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>208<font color="#A5A5A1">╭─ Secondary Arguments ─────────────────────────────────────────────╮</font>209<font color="#A5A5A1">│ lastname </font><font color="#A37F4E"><b>[LASTNAME]</b></font> The last name │210<font color="#A5A5A1">│ age </font><font color="#A37F4E"><b>[AGE] </b></font> The user&apos;s age │209<font color="#A5A5A1">│ lastname </font><font color="#A37F4E"><b>lastname</b></font> The last name │210<font color="#A5A5A1">│ age </font><font color="#A37F4E"><b>age </b></font> The user&apos;s age │211<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>212<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>213<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message and exit. │214<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>
24 unmodified lines
239```console240$ python main.py --help241242// Notice there's no Arguments section at all 🔥243Usage: main.py [OPTIONS] [NAME]243Usage: main.py [OPTIONS] [name]244245 Say hi to NAME very gently, like Dirk.245 Say hi to 'name' very gently, like Dirk.246247Options:248 --help Show this message and exit.249```
18 unmodified lines
modified:docs/tutorial/arguments/optional.md+6 added-6 removed
82 unmodified lines
8384```console85$ python main.py8687Usage: main.py [OPTIONS] NAME87Usage: main.py [OPTIONS] {name}88Try "main.py --help" for help.8990Error: Missing argument 'NAME'.90Error: Missing argument 'name'.91```9293</div>94
36 unmodified lines
131```console132// First check the help133$ python main.py --help134135Usage: main.py [OPTIONS] [NAME]135Usage: main.py [OPTIONS] [name]136137Arguments:138 [NAME]138 name [default: World]139140Options:141 --help Show this message and exit.142```
1 unmodified line
144</div>145146/// tip147148Notice that `NAME` is still a *CLI argument*, it's shown up there in the "`Usage: main.py` ...".148Notice that `name` is still a *CLI argument*, it's shown up there in the "`Usage: main.py` ...".149150Also notice that now `[NAME]` has brackets ("`[`" and "`]`") around (before it was just `NAME`) to denote that it's **optional**, not **required**.150Also notice that now `[name]` has rectangular brackets ("`[`" and "`]`") around it to denote that it's **optional**, not **required**. If it would have been required, curly brackets ("`{`" and "`}`") would be used instead.151152///153154Now run it and test it:
84 unmodified lines
modified:docs/tutorial/commands/arguments.md+4 added-1 removed
8 unmodified lines
9```console10// Check the help for create11$ python main.py create --help1213Usage: main.py create [OPTIONS] USERNAME13Usage: main.py create [OPTIONS] {username}1415Arguments:16 username [required]1718Options:19 --help Show this message and exit.2021// Call it with a CLI argument
27 unmodified lines
modified:docs/tutorial/commands/callback.md+3 added-3 removed
38 unmodified lines
3940 Manage users in the awesome CLI app.4142Options:43 --verbose / --no-verbose [default: False]43 --verbose / --no-verbose [default: no-verbose]44 --install-completion Install completion for the current shell.45 --show-completion Show completion for the current shell, to copy it or customize the installation.46 --help Show this message and exit.47
18 unmodified lines
6667// Notice that --verbose belongs to the callback, it has to go before create or delete ⛔️68$ python main.py create --verbose Camila6970Usage: main.py create [OPTIONS] USERNAME70Usage: main.py create [OPTIONS] {username}71Try "main.py create --help" for help.7273Error: No such option: --verbose74```
66 unmodified lines
141 Manage users CLI app.142143 Use it with the create command.144145 A new user with the given NAME will be created.145 A new user with the given 'name' will be created.146147Options:148 --install-completion Install completion for the current shell.149 --show-completion Show completion for the current shell, to copy it or customize the installation.
12 unmodified lines
modified:docs/tutorial/commands/help.md+37 added-37 removed
22 unmodified lines
23 --show-completion Show completion for the current shell, to copy it or customize the installation.24 --help Show this message and exit.2526Commands:27 create Create a new user with USERNAME.28 delete Delete a user with USERNAME.27 create Create a new user with username.28 delete Delete a user with username.29 delete-all Delete ALL users in the database.30 init Initialize the users database.3132// Now the commands have inline help 🎉3334// Check the help for create35$ python main.py create --help3637Usage: main.py create [OPTIONS] USERNAME37Usage: main.py create [OPTIONS] {username}3839 Create a new user with USERNAME.39 Create a new user with username.4041Arguments:42 username [required]4344Options:45 --help Show this message and exit.4647// Check the help for delete48$ python main.py delete --help4947Usage: main.py delete [OPTIONS] USERNAME50Usage: main.py delete [OPTIONS] {username}5149 Delete a user with USERNAME.52 Delete a user with username.5354 If --force is not used, will ask for confirmation.5556Arguments:57 username [required]5859Options:60 --force / --no-force Force deletion without confirmation. [required]61 --help Show this message and exit.62
54 unmodified lines
117 it or customize the installation.118 --help Show this message and exit.119120Commands:115 create Create a new user with USERNAME.116 delete Delete a user with USERNAME.121 create Create a new user with username.122 delete Delete a user with username.123118// It uses "Create a new user with USERNAME." instead of "Some internal utility function to create."124// It uses "Create a new user with username." instead of "Some internal utility function to create."125```126127</div>128
36 unmodified lines
165166```console167$ python main.py delete --help168163<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py delete [OPTIONS] USERNAME </b>169<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py delete [OPTIONS] {username} </b>170<b> </b>171 <font color="#F92672">(deprecated) </font>172 Delete a user.173 This is deprecated and will stop being supported soon.174175<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>170<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │176<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>&lt;str&gt;</b></font> <font color="#A6194C">[required]</font> │177<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>178<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>179<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message and exit. │180<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>
56 unmodified lines
237238```console239$ python main.py create --help240235<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py create [OPTIONS] USERNAME </b>241<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py create [OPTIONS] {username} </b>242<b> </b>243 <font color="#A6E22E"><b>Create</b></font> a new <i>shiny</i> user. ✨244 This requires a <font color="#A5A5A1"><u style="text-decoration-style:single">username</u></font><font color="#A5A5A1">. </font>245246<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>241<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>TEXT</b></font> The username to be <font color="#A6E22E">created</font> │242<font color="#A5A5A1">│ [default: None] │</font>247<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>&lt;str&gt;</b></font> The username to be <font color="#A6E22E">created</font> │248<font color="#A5A5A1">│ </font><font color="#A6194C">[required] </font> │249<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>250<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>251<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message and exit. │
8 unmodified lines
260261```console262$ python main.py delete --help263259<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py delete [OPTIONS] USERNAME </b>264<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py delete [OPTIONS] {username} </b>265<b> </b>261 <font color="#F92672"><b>Delete</b></font> a user with <i>USERNAME</i>.266 <font color="#F92672"><b>Delete</b></font> a user with <i>username</i>.267268<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>264<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>TEXT</b></font> The username to be <font color="#F92672">deleted</font> │265<font color="#A5A5A1">│ [default: None] │</font>269<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>&lt;str&gt;</b></font> The username to be <font color="#F92672">deleted</font> │270<font color="#A5A5A1">│ </font><font color="#A6194C">[required] </font> │271<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>272<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>273<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--force</b></font> <font color="#AE81FF"><b>--no-force</b></font> Force the <font color="#F92672"><b>deletion</b></font> 💥 │
20 unmodified lines
294295```console296$ python main.py create --help297294<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py create [OPTIONS] USERNAME </b>298<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py create [OPTIONS] {username} </b>299<b> </b>300 <b>Create</b> a new <i>shiny</i> user. ✨301302 <font color="#F4BF75"><b> • </b></font><font color="#A5A5A1">Create a username </font>
2 unmodified lines
305 <font color="#F4BF75">───────────────────────────────────────────────────────────────────</font>306 Learn more at the <font color="#44919F">Typer docs website</font>307308<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>305<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>TEXT</b></font> The username to be <b>created</b> │306<font color="#A5A5A1">│ [default: None] │</font>309<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>&lt;str&gt;</b></font> The username to be <b>created</b> │310<font color="#A5A5A1">│ </font><font color="#A6194C">[required] </font> │311<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>312<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>313<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message and exit. │
8 unmodified lines
322323```console324$ python main.py delete --help325323<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py delete [OPTIONS] USERNAME </b>326<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py delete [OPTIONS] {username} </b>327<b> </b>325 <b>Delete</b> a user with <i>USERNAME</i>.328 <b>Delete</b> a user with <i>username</i>.329330<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>328<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>TEXT</b></font> The username to be <b>deleted</b> │329<font color="#A5A5A1">│ [default: None] │</font>331<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>&lt;str&gt;</b></font> The username to be <b>deleted</b> │332<font color="#A5A5A1">│ </font><font color="#A6194C">[required] </font> │333<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>334<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>335<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--force</b></font> <font color="#AE81FF"><b>--no-force</b></font> Force the <b>deletion</b> 💥 │
43 unmodified lines
379<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>create </b></font> <font color="#A6E22E">Create</font> a new user. ✨ │380<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>delete </b></font> <font color="#F92672">Delete</font> a user. ❌ │381<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>382<font color="#A5A5A1">╭─ Utils and Configs ───────────────────────────────────────────────╮</font>381<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>config </b></font> <font color="#66D9EF">Configure</font> the system. ⚙ │382<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>sync </b></font> <font color="#66D9EF">Synchronize</font> the system or something fancy like that. ♻ │383<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>config </b></font> <font color="#66D9EF">Configure</font> the system. ⚙ │384<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>sync </b></font> <font color="#66D9EF">Synchronize</font> the system or something fancy like that. ♻ │385<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>386<font color="#A5A5A1">╭─ Help and Others ─────────────────────────────────────────────────╮</font>387<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>help </b></font> Get <font color="#F4BF75">help</font> with the system. ❓ │388<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>report </b></font> <font color="#F4BF75">Report</font> an issue. ❗ │
23 unmodified lines
412413```console414$ python main.py create --help415414<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py create [OPTIONS] USERNAME [LASTNAME] </b>416<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py create [OPTIONS] {username} [lastname] </b>417<b> </b>418 <font color="#A6E22E">Create</font> a new user. ✨419420<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>419<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>TEXT</b></font> The username to create [default: None] │421<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>&lt;str&gt;</b></font> The username to create │422<font color="#A5A5A1">│ </font><font color="#A6194C">[required] </font> │423<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>424<font color="#A5A5A1">╭─ Secondary Arguments ─────────────────────────────────────────────╮</font>423<font color="#A5A5A1">│ lastname </font><font color="#A37F4E"><b>[LASTNAME]</b></font> The last name of the new user │425<font color="#A5A5A1">│ lastname </font><font color="#A37F4E"><b>lastname</b></font> The last name of the new user │426<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>427<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>428<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--force</b></font> <font color="#AE81FF"><b>--no-force</b></font> Force the creation of the user │429<font color="#A5A5A1">│ [default: no-force] │</font>430<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message and exit. │431<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>432<font color="#A5A5A1">╭─ Additional Data ─────────────────────────────────────────────────╮</font>431<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--age</b></font> <font color="#F4BF75"><b>INTEGER</b></font> The age of the new user │432<font color="#A5A5A1">│ [default: None] │</font>433<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--favorite-color</b></font> <font color="#F4BF75"><b>TEXT </b></font> The favorite color of the new │433<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--age</b></font> <font color="#F4BF75"><b>&lt;int&gt; </b></font> The age of the new user │434<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--favorite-color</b></font> <font color="#F4BF75"><b>&lt;str&gt; </b></font> The favorite color of the new │435<font color="#A5A5A1">│ user │</font>435<font color="#A5A5A1">│ [default: None] │</font>436<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>437```438439</div>
20 unmodified lines
460<font color="#A5A5A1">╭─ Commands ────────────────────────────────────────────────────────╮</font>461<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>create </b></font> <font color="#A6E22E">Create</font> a new user. ✨ │462<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>463<font color="#A5A5A1">╭─ Utils and Configs ───────────────────────────────────────────────╮</font>464<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>config </b></font> <font color="#66D9EF">Configure</font> the system. ⚙ │464<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>config </b></font> <font color="#66D9EF">Configure</font> the system. ⚙ │465<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>466```467468</div>
12 unmodified lines
481482```console483$ python main.py --help484485<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] USERNAME </b>485<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] {username} </b>486<b> </b>487 <font color="#A6E22E">Create</font> a new user. ✨488489<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>490<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │490<font color="#A5A5A1">│ </font><font color="#F92672">*</font> username <font color="#F4BF75"><b>&lt;str&gt;</b></font> <font color="#A6194C">[required]</font> │491<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>492<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>493<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--install-completion</b></font> Install completion for the current │494<font color="#A5A5A1">│ shell. │</font>
10 unmodified lines
modified:docs/tutorial/commands/one-or-multiple.md+5 added-5 removed
10 unmodified lines
11```console12// Without a CLI argument13$ python main.py1415Usage: main.py [OPTIONS] NAME15Usage: main.py [OPTIONS] {name}16Try "main.py --help" for help.1718Error: Missing argument 'NAME'.18Error: Missing argument 'name'.1920// With the NAME CLI argument20// With the 'name' CLI argument21$ python main.py Camila2223Hello Camila2425// Asking for help26$ python main.py26$ python main.py --help2728Usage: main.py [OPTIONS] NAME28Usage: main.py [OPTIONS] {name}2930Options:31 --install-completion Install completion for the current shell.32 --show-completion Show completion for the current shell, to copy it or customize the installation.
116 unmodified lines
modified:docs/tutorial/multiple-values/arguments-with-multiple-values.md+2 added-2 removed
45 unmodified lines
46```console47// Check the help48$ python main.py --help4950Usage: main.py [OPTIONS] [NAMES]...50Usage: main.py [OPTIONS] [names]...5152Arguments:53 [NAMES]... Select 3 characters to play with [default: Harry, Hermione, Ron]53 names... Select 3 characters to play with [default: Harry, Hermione, Ron]5455Options:56 --help Show this message and exit.57
21 unmodified lines
modified:docs/tutorial/multiple-values/options-with-multiple-values.md+3 added-3 removed
56 unmodified lines
57```console58// check the help59$ python main.py --help6061// Notice the &lt;TEXT INTEGER BOOLEAN&gt;61// Notice the <str int boolean>62Usage: main.py [OPTIONS]6364Options:65 --user &lt;TEXT INTEGER BOOLEAN&gt;...66 --help Show this message and exit.65 --user <str int boolean>...66 --help Show this message and exit.6768// Now try it69$ python main.py --user Camila 50 yes70
15 unmodified lines
modified:docs/tutorial/options/callback-and-context.md+2 added-2 removed
59 unmodified lines
60// Then try with "run" and --help61$ typer ./main.py run --help6263// You get a help text with your CLI options as you normally would64Usage: typer run [OPTIONS]64Usage: typer [PATH_OR_MODULE] run [OPTIONS]6566 Run the provided Typer app.6768Options:69 --name TEXT [required]69 --name <str>70 --help Show this message and exit.7172// Then try completion with your program73$ typer ./main.py run --[TAB][TAB]
132 unmodified lines
modified:docs/tutorial/options/help.md+11 added-11 removed
29 unmodified lines
3031```console32$ python main.py --help3334Usage: main.py [OPTIONS] NAME34Usage: main.py [OPTIONS] {name}3536 Say hi to NAME, optionally with a --lastname.36 Say hi to 'name', optionally with a --lastname.3738 If --formal is used, say hi very formally.3940Arguments:41 NAME [required]41 name [required]4243Options:44 --lastname TEXT Last name of person to greet. [default: ]45 --formal / --no-formal Say hi formally. [default: False]44 --lastname <str> Last name of person to greet.45 --formal / --no-formal Say hi formally. [default: no-formal]46 --help Show this message and exit.4748// Now you have a help text for the --lastname and --formal CLI options 🎉49```
16 unmodified lines
6667```console68$ python main.py --help6970<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] NAME </b>70<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] {name} </b>71<b> </b>72 Say hi to NAME, optionally with a <font color="#A1EFE4"><b>--lastname</b></font>.72 Say hi to 'name', optionally with a <font color="#A1EFE4"><b>--lastname</b></font>.73 If <font color="#6B9F98"><b>--formal</b></font><font color="#A5A5A1"> is used, say hi very formally. </font>7475<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>76<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │76<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>&lt;str&gt;</b></font> <font color="#A6194C">[required]</font> │77<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>78<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>79<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--lastname</b></font> <font color="#F4BF75"><b>TEXT</b></font> Last name of person to greet. │79<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--lastname</b></font> <font color="#F4BF75"><b>&lt;str&gt;</b></font> Last name of person to greet. │80<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> <font color="#F4BF75"><b> </b></font> Show this message and exit. │81<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>82<font color="#A5A5A1">╭─ Customization and Utils ─────────────────────────────────────────╮</font>83<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--formal</b></font> <font color="#AE81FF"><b>--no-formal</b></font> Say hi formally. │
34 unmodified lines
118119Usage: main.py [OPTIONS]120121Options:122 --fullname TEXT122 --fullname <str>123 --help Show this message and exit.124125// Notice there's no [default: Wade Wilson] 🔥126```
20 unmodified lines
147148Usage: main.py [OPTIONS]149150Options:151 --fullname TEXT [default: (Deadpoolio the amazing's name)]151 --fullname <str> [default: (Deadpoolio the amazing's name)]152 --help Show this message and exit.153154// Notice how it shows "(Deadpoolio the amazing's name)" instead of the actual default of "Wade Wilson"155```
2 unmodified lines
modified:docs/tutorial/options/name.md+5 added-5 removed
51 unmodified lines
52// Notice the --name instead of --user-name53Usage: main.py [OPTIONS]5455Options:56 --name TEXT [required]56 --name <str> [required]57 --help Show this message and exit.5859// Try it60$ python main.py --name Camila
139 unmodified lines
200// Notice the two CLI option names -n and --name201Usage: main.py [OPTIONS]202203Options:204 -n, --name TEXT [required]204 -n, --name <str> [required]205 --help Show this message and exit.206207// Try the short version208$ python main.py -n Camila
19 unmodified lines
228// Notice there's no --name nor --user-name, only -n229Usage: main.py [OPTIONS]230231Options:232 -n TEXT [required]232 -n <str> [required]233 --help Show this message and exit.234235// Try it236$ python main.py -n Camila
20 unmodified lines
257// and we also have the short version -n258Usage: main.py [OPTIONS]259260Options:261 -n, --user-name TEXT [required]261 -n, --user-name <str> [required]262 --help Show this message and exit.263264// Try it265$ python main.py --user-name Camila
31 unmodified lines
297// And also long versions --name and --formal298Usage: main.py [OPTIONS]299300Options:301 -n, --name TEXT [required]301 -n, --name <str> [required]302 -f, --formal303 --help Show this message and exit.304305// Try the short versions
12 unmodified lines
modified:docs/tutorial/options/prompt.md+2 added-2 removed
7 unmodified lines
89<div class="termy">1011```console12// Call it with the NAME CLI argument12// Call it with the 'name' CLI argument13$ python main.py Camila1415// It asks for the missing CLI option --lastname16# Lastname: $ Gutiérrez
13 unmodified lines
3031<div class="termy">3233```console34// Call it with the NAME CLI argument34// Call it with the 'name' CLI argument35$ python main.py Camila3637// It uses the custom prompt38# Please tell me your last name: $ Gutiérrez
46 unmodified lines
modified:docs/tutorial/options/required.md+7 added-4 removed
40 unmodified lines
4142<div class="termy">4344```console45// Pass the NAME CLI argument45// Pass the 'name' CLI argument46$ python main.py Camila4748// We didn't pass the now required --lastname CLI option49Usage: main.py [OPTIONS] NAME49Usage: main.py [OPTIONS] {name}50Try "main.py --help" for help.5152Error: Missing option '--lastname'.53
4 unmodified lines
5859// And if you check the help60$ python main.py --help6162Usage: main.py [OPTIONS] NAME62Usage: main.py [OPTIONS] {name}6364Arguments:65 name [required]6667Options:65 --lastname TEXT [required]68 --lastname <str> [required]69 --help Show this message and exit.7071// It now tells you that --lastname is required 🎉72```
2 unmodified lines
modified:docs/tutorial/options/version.md+1 added-1 removed
32 unmodified lines
33Usage: main.py [OPTIONS]3435Options:36 --version37 --name TEXT37 --name <str> [default: World]38 --help Show this message and exit.394041// We can call it normally
71 unmodified lines
modified:docs/tutorial/parameter-types/bool.md+2 added-2 removed
22 unmodified lines
23// Notice there's only --force, we no longer have --no-force24Usage: main.py [OPTIONS]2526Options:27 --force [default: False]27 --force28 --help Show this message and exit.2930// Try it:31$ python main.py
80 unmodified lines
112// Notice the -f, --force / -F, --no-force113Usage: main.py [OPTIONS]114115Options:116 -f, --force / -F, --no-force [default: False]116 -f, --force / -F, --no-force [default: no-force]117 --help Show this message and exit.118119// Try with the short name -f120$ python main.py -f
59 unmodified lines
modified:docs/tutorial/parameter-types/datetime.md+5 added-4 removed
17 unmodified lines
1819```console20$ python main.py --help2122Usage: main.py [OPTIONS] BIRTH:[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]22Usage: main.py [OPTIONS] {birth}:<%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S>2324Arguments:25 BIRTH:[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S][required]25 birth:<%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S> [required]2627Options:28 --help Show this message and exit.29
5 unmodified lines
3536// An invalid date37$ python main.py july-19-19893839Usage: main.py [OPTIONS] [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d%H:%M:%S]39Usage: main.py [OPTIONS] {birth}:<%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S>40Try 'main.py --help' for help.4141Error: Invalid value for 'BIRTH:[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]': 'july-19-1989' does not match the formats '%Y-%m-%d', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S'.42Error: Invalid value for 'birth': 'july-19-1989' does not match the formats '%Y-%m-%d', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S'.43```4445</div>46
40 unmodified lines
modified:docs/tutorial/parameter-types/enum.md+6 added-6 removed
17 unmodified lines
1819```console20$ python main.py --help2122// Notice the predefined values [simple|conv|lstm]22// Notice the predefined values <simple|conv|lstm>23Usage: main.py [OPTIONS]2425Options:26 --network [simple|conv|lstm] [default: simple]26 --network <simple|conv|lstm> [default: simple]27 --help Show this message and exit.2829// Try it30$ python main.py --network conv
59 unmodified lines
90// Notice the default values being shown91Usage: main.py [OPTIONS]9293Options:94 --groceries [Eggs|Bacon|Cheese] [default: Eggs, Cheese]95 --help Show this message and exit.94 --groceries <Eggs|Bacon|Cheese> [default: Eggs, Cheese]95 --help Show this message and exit.9697// Try it with the default values98$ python main.py99
22 unmodified lines
122123```console124$ python main.py --help125126// Notice the predefined values [simple|conv|lstm]126// Notice the predefined values <simple|conv|lstm>127Usage: main.py [OPTIONS]128129Options:130 --network [simple|conv|lstm] [default: simple]130 --network <simple|conv|lstm> [default: simple]131 --help Show this message and exit.132133// Try it134$ python main.py --network conv
13 unmodified lines
modified:docs/tutorial/parameter-types/index.md+12 added-12 removed
8 unmodified lines
9For example:1011{* docs_src/parameter_types/index/tutorial001_py310.py hl[7] *}1213In this example, the value received for the *CLI argument* `NAME` will be treated as `str`.13In this example, the value received for the *CLI argument* `name` will be treated as `str`.1415The value for the *CLI option* `--age` will be converted to an `int` and `--height-meters` will be converted to a `float`.1617And as `female` is a `bool` *CLI option*, **Typer** will convert it to a "flag" `--female` and the counterpart `--no-female`.
4 unmodified lines
2223```console24$ python main.py --help2526// Notice how --age is an INTEGER and --height-meters is a FLOAT27Usage: main.py [OPTIONS] NAME26// Notice how --age is an 'int' (integer) and --height-meters is a 'float'27Usage: main.py [OPTIONS] {name}2829Arguments:30 NAME [required]30 name [required]3132Options:33 --age INTEGER [default: 20]34 --height-meters FLOAT [default: 1.89]35 --female / --no-female [default: True]36 --help Show this message and exit.33 --age <int> [default: 20]34 --height-meters <float> [default: 1.89]35 --female / --no-female [default: female]36 --help Show this message and exit.3738// Call it with CLI parameters39$ python main.py Camila --age 15 --height-meters 1.70 --female4041// All the data has the correct Python type42NAME is Camila, of type: class 'str'42name is Camila, of type: class 'str'43--age is 15, of type: class 'int'44--height-meters is 1.7, of type: class 'float'45--female is True, of type: class 'bool'4647// And if you pass an incorrect type48$ python main.py Camila --age 15.34950Usage: main.py [OPTIONS] NAME50Usage: main.py [OPTIONS] {name}51Try "main.py --help" for help.5253Error: Invalid value for '--age': '15.3' is not a valid integer53Error: Invalid value for '--age': '15.3' is not a valid int.5455// Because 15.3 is not an INTEGER (it's a float)55// Because 15.3 is not an integer (it's a float)56```5758</div>59
3 unmodified lines
modified:docs/tutorial/parameter-types/number.md+9 added-9 removed
13 unmodified lines
1415```console16$ python main.py --help1718// Notice the extra RANGE in the help text for --age and --score19Usage: main.py [OPTIONS] ID18// Notice the extra range information in the help text for --age and --score19Usage: main.py [OPTIONS] {ID}2021Arguments:22 ID [required]2324Options:25 --age INTEGER RANGE [default: 20]26 --score FLOAT RANGE [default: 0]27 --help Show this message and exit.25 --age <int range> [default: 20; x>=18]26 --score <float range> [default: 0; x<=100]27 --help Show this message and exit.2829// Pass all the CLI parameters30$ python main.py 5 --age 20 --score 9031
3 unmodified lines
3536// Pass an invalid ID37$ python main.py 10023839Usage: main.py [OPTIONS] ID39Usage: main.py [OPTIONS] {ID}40Try "main.py --help" for help.4142Error: Invalid value for 'ID': 1002 is not in the range 0<=x<=1000.4344// Pass an invalid age45$ python main.py 5 --age 154647Usage: main.py [OPTIONS] ID47Usage: main.py [OPTIONS] {ID}48Try "main.py --help" for help.4950Error: Invalid value for '--age': 15 is not in the range x>=18.5152// Pass an invalid score53$ python main.py 5 --age 20 --score 100.55455Usage: main.py [OPTIONS] ID55Usage: main.py [OPTIONS] {ID}56Try "main.py --help" for help.5758Error: Invalid value for '--score': 100.5 is not in the range x<=100.59
22 unmodified lines
82```console83// ID doesn't have clamp, so it shows an error84$ python main.py 10028586Usage: main.py [OPTIONS] ID86Usage: main.py [OPTIONS] {ID}87Try "main.py --help" for help.8889Error: Invalid value for 'ID': 1002 is not in the range 0<=x<=1000.90
55 unmodified lines
modified:docs/tutorial/parameter-types/path.md+1 added-1 removed
14 unmodified lines
15```console16// No config17$ python main.py1819Aborted.20No config file20Aborted!2122// Pass a config that doesn't exist23$ python main.py --config config.txt24
82 unmodified lines
modified:docs/tutorial/parameter-types/uuid.md+3 added-3 removed
32 unmodified lines
33```console34// Pass a valid UUID v435$ python main.py d48edaa6-871a-4082-a196-4daab372d4a13637USER_ID is d48edaa6-871a-4082-a196-4daab372d4a137User ID is d48edaa6-871a-4082-a196-4daab372d4a138UUID version is: 43940// An invalid value41$ python main.py 7479706572-72756c65734243Usage: main.py [OPTIONS] USER_ID43Usage: main.py [OPTIONS] {user_id}44Try "main.py --help" for help.4546Error: Invalid value for 'USER_ID': 7479706572-72756c6573 is not a valid UUID.46Error: Invalid value for 'user_id': 7479706572-72756c6573 is not a valid UUID.47```4849</div>
modified:docs/tutorial/subcommands/add-typer.md+1 added-1 removed
82 unmodified lines
83 --show-completion Show completion for the current shell, to copy it or customize the installation.84 --help Show this message and exit.8586Commands:87 items87 users88 items89```9091</div>92
76 unmodified lines
modified:docs/tutorial/subcommands/nested-subcommands.md+3 added-3 removed
65 unmodified lines
66 --show-completion Show completion for the current shell, to copy it or customize the installation.67 --help Show this message and exit.6869Commands:70 burn70 found71 burn7273// Try it74$ python towns.py found "New Asgard"75
53 unmodified lines
129Options:130 --help Show this message and exit.131132Commands:133 burn133 found134 burn135```136137</div>138
65 unmodified lines
204 --show-completion Show completion for the current shell, to copy it or customize the installation.205 --help Show this message and exit.206207Commands:208 users209 items210 lands210 users211212// Try some users commands213$ python main.py users create Camila214
69 unmodified lines
modified:docs/tutorial/first-steps.md+25 added-28 removed
68 unmodified lines
6970$ python main.py7172// If you run it without the argument, it shows a nice error73<font color="#F4BF75">Usage: </font>main.py [OPTIONS] NAME73<font color="#F4BF75">Usage: </font>main.py [OPTIONS] {name}74<font color="#A5A5A1">Try </font><font color="#44919F">&apos;main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">&apos;</font><font color="#A5A5A1"> for help.</font>75<font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>76<font color="#F92672">│</font> Missing argument &apos;NAME&apos;. <font color="#F92672">│</font>76<font color="#F92672">│</font> Missing argument &apos;name&apos;. <font color="#F92672">│</font>77<font color="#F92672">╰───────────────────────────────────────────────────╯</font>7879// Now pass that NAME CLI argument79// Now pass that 'name' CLI argument80$ python main.py Camila8182Hello Camila83
26 unmodified lines
110```console111// Check the main --help112$ python main.py --help113114<font color="#F4BF75">Usage: </font>main.py [OPTIONS] NAME115<font color="#A5A5A1">Try </font><font color="#44919F">&apos;main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">&apos;</font><font color="#A5A5A1"> for help.</font>116<font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>117<font color="#F92672">│</font> Missing argument &apos;NAME&apos;. <font color="#F92672">│</font>118<font color="#F92672">╰───────────────────────────────────────────────────╯</font>114<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] {name} {lastname} </b>115<b> </b>116<font color="#A5A5A1">╭─ Arguments ─────────────────────────────────────────────────────╮</font>117<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>&lt;str&gt;</b></font> <font color="#A6194C">[required]</font> │118<font color="#A5A5A1">│ </font><font color="#F92672">*</font> lastname <font color="#F4BF75"><b>&lt;str&gt;</b></font> <font color="#A6194C">[required]</font> │119<font color="#A5A5A1">╰─────────────────────────────────────────────────────────────────╯</font>120<font color="#A5A5A1">╭─ Options ───────────────────────────────────────────────────────╮</font>121<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message and │122<font color="#A5A5A1">│ exit. │</font>123<font color="#A5A5A1">╰─────────────────────────────────────────────────────────────────╯</font>124120<font color="#A1EFE4"><b>typer</b></font> on <font color="#AE81FF"><b> richify</b></font> <font color="#F92672"><b>[»!?] </b></font>via <font color="#F4BF75"><b>🐍 v3.7.5 (env3.7)</b></font>121<font color="#F92672"><b>❯</b></font> <font color="#A6E22E">python</font> <u style="text-decoration-style:single">main.py</u>122<font color="#F4BF75">Usage: </font>main.py [OPTIONS] NAME LASTNAME123<font color="#A5A5A1">Try </font><font color="#44919F">&apos;main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">&apos;</font><font color="#A5A5A1"> for help.</font>124<font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>125<font color="#F92672">│</font> Missing argument &apos;NAME&apos;. <font color="#F92672">│</font>126<font color="#F92672">╰───────────────────────────────────────────────────╯</font>127125// There are now 2 CLI arguments, name and lastname126127// Now pass a single name argument128$ python main.py Camila129133<font color="#F4BF75">Usage: </font>main.py [OPTIONS] NAME LASTNAME130<font color="#F4BF75">Usage: </font>main.py [OPTIONS] {name} {lastname}131<font color="#A5A5A1">Try </font><font color="#44919F">&apos;main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">&apos;</font><font color="#A5A5A1"> for help.</font>132<font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>136<font color="#F92672">│</font> Missing argument &apos;LASTNAME&apos;. <font color="#F92672">│</font>133<font color="#F92672">│</font> Missing argument &apos;lastname&apos;. <font color="#F92672">│</font>134<font color="#F92672">╰───────────────────────────────────────────────────╯</font>135136// These 2 arguments are required, so, pass both:137$ python main.py Camila Gutiérrez
96 unmodified lines
234```console235// Get the help236$ python main.py --help237241<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] NAME LASTNAME </b>238<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] {name} {lastname} </b>239<b> </b>240<font color="#A5A5A1">╭─ Arguments ─────────────────────────────────────────────────────╮</font>244<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │245<font color="#A5A5A1">│ </font><font color="#F92672">*</font> lastname <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │241<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>&lt;str&gt;</b></font> <font color="#A6194C">[required]</font> │242<font color="#A5A5A1">│ </font><font color="#F92672">*</font> lastname <font color="#F4BF75"><b>&lt;str&gt;</b></font> <font color="#A6194C">[required]</font> │243<font color="#A5A5A1">╰─────────────────────────────────────────────────────────────────╯</font>244<font color="#A5A5A1">╭─ Options ───────────────────────────────────────────────────────╮</font>245<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--formal</b></font> <font color="#AE81FF"><b>--no-formal</b></font> [default: no-formal] │246<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> Show this message and │
47 unmodified lines
294295```console296$ python main.py --help297301<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] NAME </b>298<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] {name} </b>299<b> </b>300<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>304<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │301<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>&lt;str&gt;</b></font> <font color="#A6194C">[required]</font> │302<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>303<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>307<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--lastname</b></font> <font color="#F4BF75"><b>TEXT</b></font> │304<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--lastname</b></font> <font color="#F4BF75"><b>&lt;str&gt;</b></font> │305<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--formal</b></font> <font color="#AE81FF"><b>--no-formal</b></font> <font color="#F4BF75"><b> </b></font> [default: no-formal] │306<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> <font color="#F4BF75"><b> </b></font> Show this message │307<font color="#A5A5A1">│ and exit. │</font>308<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>
56 unmodified lines
365366```console367$ python main.py --help368372<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] NAME </b>369<b> </b><font color="#F4BF75"><b>Usage: </b></font><b>main.py [OPTIONS] {name} </b>370<b> </b>374 Say hi to NAME, optionally with a <font color="#A1EFE4"><b>--lastname</b></font>.371 Say hi to 'name', optionally with a <font color="#A1EFE4"><b>--lastname</b></font>.372 If <font color="#6B9F98"><b>--formal</b></font><font color="#A5A5A1"> is used, say hi very formally. </font>373374<font color="#A5A5A1">╭─ Arguments ───────────────────────────────────────────────────────╮</font>378<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>TEXT</b></font> [default: None] <font color="#A6194C">[required]</font> │375<font color="#A5A5A1">│ </font><font color="#F92672">*</font> name <font color="#F4BF75"><b>&lt;str&gt;</b></font> <font color="#A6194C">[required]</font> │376<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>377<font color="#A5A5A1">╭─ Options ─────────────────────────────────────────────────────────╮</font>381<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--lastname</b></font> <font color="#F4BF75"><b>TEXT</b></font> │378<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--lastname</b></font> <font color="#F4BF75"><b>&lt;str&gt;</b></font> │379<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--formal</b></font> <font color="#AE81FF"><b>--no-formal</b></font> <font color="#F4BF75"><b> </b></font> [default: no-formal] │380<font color="#A5A5A1">│ </font><font color="#A1EFE4"><b>--help</b></font> <font color="#F4BF75"><b> </b></font> Show this message │381<font color="#A5A5A1">│ and exit. │</font>382<font color="#A5A5A1">╰───────────────────────────────────────────────────────────────────╯</font>
124 unmodified lines
modified:docs/tutorial/one-file-per-command.md+2 added-2 removed
5 unmodified lines
67We will create a simple CLI with the following commands:89- `version`10- `users add NAME`11- `users delete NAME`10- `users add 'name'`11- `users delete 'name'`1213## CLI structure1415Here is the structure we'll be working with:
129 unmodified lines
modified:docs/tutorial/typer-app.md+7 added-4 removed
49 unmodified lines
50```console51// Without a CLI argument52$ python main.py5354Usage: main.py [OPTIONS] NAME54Usage: main.py [OPTIONS] {name}55Try "main.py --help" for help.5657Error: Missing argument 'NAME'.57Error: Missing argument 'name'.5859// With the NAME CLI argument59// With the 'name' CLI argument60$ python main.py Camila6162Hello Camila6364// Asking for help65$ python main.py --help6667Usage: main.py [OPTIONS] NAME67Usage: main.py [OPTIONS] {name}6869Arguments:70 name [required]7172Options:73 --install-completion Install completion for the current shell.74 --show-completion Show completion for the current shell, to copy it or customize the installation.75 --help Show this message and exit.
46 unmodified lines
modified:docs/tutorial/typer-command.md+14 added-14 removed
167 unmodified lines
168<div class="termy">169170```console171$ typer main.py run --help172Usage: typer run [OPTIONS]172Usage: typer [PATH_OR_MODULE] run [OPTIONS]173174 Say hi to someone, by default to the World.175176Options:177 --name TEXT178 --help Show this message and exit.177 --name <str> [default: World]178 --help Show this message and exit.179180$ typer main.py run --name Camila181182Hello Camila
12 unmodified lines
195<div class="termy">196197```console198$ typer my_package.main run --help199Usage: typer run [OPTIONS]199Usage: typer [PATH_OR_MODULE] run [OPTIONS]200201Options:202 --name TEXT202 --name <str>203 --help Show this message and exit.204205$ typer my_package.main run --name Camila206
57 unmodified lines
264///265266**Options**:267268* `--name TEXT`: The name of the CLI program to use in docs.269* `--output FILE`: An output file to write docs to, like README.md.270* `--title TEXT`: A title to use in the docs, by default the name of the command.268* `--name <str>`: The name of the CLI program to use in docs.269* `--output <file>`: An output file to write docs to, like README.md.270* `--title <str>`: A title to use in the docs, by default the name of the command.271272For example:273274<div class="termy">
29 unmodified lines
304* `--help`: Show this message and exit.305306**Commands**:307308* `create`: Create a new user with USERNAME.309* `delete`: Delete a user with USERNAME.308* `create`: Create a new user with username.309* `delete`: Delete a user with username.310* `delete-all`: Delete ALL users in the database.311* `init`: Initialize the users database.312313## `awesome-cli create`314315Create a new user with USERNAME.315Create a new user with username.316317**Usage**:318319```console320$ awesome-cli create [OPTIONS] USERNAME320$ awesome-cli create [OPTIONS] {username}321```322323**Options**:324325* `--help`: Show this message and exit.326327## `awesome-cli delete`328329Delete a user with USERNAME.329Delete a user with 'username'.330331If --force is not used, will ask for confirmation.332333**Usage**:334335```console336$ awesome-cli delete [OPTIONS] USERNAME336$ awesome-cli delete [OPTIONS] {username}337```338339**Options**:340
33 unmodified lines
modified:docs/index.md+18 added-18 removed
84 unmodified lines
85```console86// Run your application87$ typer main.py run8889// You get a nice error, you are missing NAME90Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME89// You get a nice error, you are missing 'name'90Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}91Try 'typer [PATH_OR_MODULE] run --help' for help.92╭─ Error ───────────────────────────────────────────╮93│ Missing argument 'NAME'. │93│ Missing argument 'name'. │94╰───────────────────────────────────────────────────╯959697// You get a --help for free98$ typer main.py run --help99100Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME100Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}101102Run the provided Typer app.103104╭─ Arguments ───────────────────────────────────────╮105│ * name TEXT [default: None] [required] |105│ * name <str> [required] │106╰───────────────────────────────────────────────────╯107╭─ Options ─────────────────────────────────────────╮108│ --help Show this message and exit. │109╰───────────────────────────────────────────────────╯110111// Now pass the NAME argument111// Now pass the 'name' argument112$ typer main.py run Camila113114Hello Camila115
29 unmodified lines
145```console146// Run your application147$ python main.py148149// You get a nice error, you are missing NAME150Usage: main.py [OPTIONS] NAME149// You get a nice error, you are missing 'name'150Usage: main.py [OPTIONS] {name}151Try 'main.py --help' for help.152╭─ Error ───────────────────────────────────────────╮153│ Missing argument 'NAME'. │153│ Missing argument 'name'. │154╰───────────────────────────────────────────────────╯155156157// You get a --help for free158$ python main.py --help159160Usage: main.py [OPTIONS] NAME160Usage: main.py [OPTIONS] {name}161162╭─ Arguments ───────────────────────────────────────╮163│ * name TEXT [default: None] [required] |163│ * name <str> [required] │164╰───────────────────────────────────────────────────╯165╭─ Options ─────────────────────────────────────────╮166│ --help Show this message and exit. │167╰───────────────────────────────────────────────────╯168169// Now pass the NAME argument169// Now pass the 'name' argument170$ python main.py Camila171172Hello Camila173
69 unmodified lines
243│ --help Show this message │244│ and exit. │245╰───────────────────────────────────────────────────╯246╭─ Commands ────────────────────────────────────────╮247│ goodbye │247│ hello │248│ goodbye │249╰───────────────────────────────────────────────────╯250251// When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion252253// You have 2 subcommands (the 2 functions): goodbye and hello253// You have 2 subcommands (the 2 functions): hello and goodbye254```255256</div>257
3 unmodified lines
261262```console263$ python main.py hello --help264265 Usage: main.py hello [OPTIONS] NAME265 Usage: main.py hello [OPTIONS] {name}266267╭─ Arguments ───────────────────────────────────────╮268│ * name TEXT [default: None] [required] │268│ * name <str> [required] │269╰───────────────────────────────────────────────────╯270╭─ Options ─────────────────────────────────────────╮271│ --help Show this message and exit. │272╰───────────────────────────────────────────────────╯
7 unmodified lines
280281```console282$ python main.py goodbye --help283284 Usage: main.py goodbye [OPTIONS] NAME284 Usage: main.py goodbye [OPTIONS] {name}285286╭─ Arguments ───────────────────────────────────────╮287│ * name TEXT [default: None] [required] │287│ * name <str> [required] │288╰───────────────────────────────────────────────────╯289╭─ Options ─────────────────────────────────────────╮290│ --formal --no-formal [default: no-formal] │291│ --help Show this message │
94 unmodified lines
modified:docs_src/arguments/help/tutorial002_an_py310.py+1 added-1 removed
6 unmodified lines
78@app.command()9def main(name: Annotated[str, typer.Argument(help="The name of the user to greet")]):10 """11 Say hi to NAME very gently, like Dirk.11 Say hi to 'name' very gently, like Dirk.12 """13 print(f"Hello {name}")1415
2 unmodified lines
modified:docs_src/arguments/help/tutorial002_py310.py+1 added-1 removed
4 unmodified lines
56@app.command()7def main(name: str = typer.Argument(..., help="The name of the user to greet")):8 """9 Say hi to NAME very gently, like Dirk.9 Say hi to 'name' very gently, like Dirk.10 """11 print(f"Hello {name}")1213
2 unmodified lines
modified:docs_src/arguments/help/tutorial003_an_py310.py+1 added-1 removed
6 unmodified lines
78@app.command()9def main(name: Annotated[str, typer.Argument(help="Who to greet")] = "World"):10 """11 Say hi to NAME very gently, like Dirk.11 Say hi to 'name' very gently, like Dirk.12 """13 print(f"Hello {name}")1415
2 unmodified lines
modified:docs_src/arguments/help/tutorial003_py310.py+1 added-1 removed
4 unmodified lines
56@app.command()7def main(name: str = typer.Argument("World", help="Who to greet")):8 """9 Say hi to NAME very gently, like Dirk.9 Say hi to 'name' very gently, like Dirk.10 """11 print(f"Hello {name}")1213
2 unmodified lines
modified:docs_src/arguments/help/tutorial004_an_py310.py+1 added-1 removed
10 unmodified lines
11 str, typer.Argument(help="Who to greet", show_default=False)12 ] = "World",13):14 """15 Say hi to NAME very gently, like Dirk.15 Say hi to 'name' very gently, like Dirk.16 """17 print(f"Hello {name}")1819
2 unmodified lines
modified:docs_src/arguments/help/tutorial004_py310.py+1 added-1 removed
4 unmodified lines
56@app.command()7def main(name: str = typer.Argument("World", help="Who to greet", show_default=False)):8 """9 Say hi to NAME very gently, like Dirk.9 Say hi to 'name' very gently, like Dirk.10 """11 print(f"Hello {name}")1213
2 unmodified lines
modified:docs_src/arguments/help/tutorial007_an_py310.py+1 added-1 removed
15 unmodified lines
16 typer.Argument(help="The user's age", rich_help_panel="Secondary Arguments"),17 ] = "",18):19 """20 Say hi to NAME very gently, like Dirk.20 Say hi to 'name' very gently, like Dirk.21 """22 print(f"Hello {name}")2324
2 unmodified lines
modified:docs_src/arguments/help/tutorial007_py310.py+1 added-1 removed
12 unmodified lines
13 "", help="The user's age", rich_help_panel="Secondary Arguments"14 ),15):16 """17 Say hi to NAME very gently, like Dirk.17 Say hi to 'name' very gently, like Dirk.18 """19 print(f"Hello {name}")2021
2 unmodified lines
modified:docs_src/arguments/help/tutorial008_an_py310.py+1 added-1 removed
6 unmodified lines
78@app.command()9def main(name: Annotated[str, typer.Argument(hidden=True)] = "World"):10 """11 Say hi to NAME very gently, like Dirk.11 Say hi to 'name' very gently, like Dirk.12 """13 print(f"Hello {name}")1415
2 unmodified lines
modified:docs_src/arguments/help/tutorial008_py310.py+1 added-1 removed
4 unmodified lines
56@app.command()7def main(name: str = typer.Argument("World", hidden=True)):8 """9 Say hi to NAME very gently, like Dirk.9 Say hi to 'name' very gently, like Dirk.10 """11 print(f"Hello {name}")1213
2 unmodified lines
modified:docs_src/commands/help/tutorial001_an_py310.py+2 added-2 removed
6 unmodified lines
78@app.command()9def create(username: str):10 """11 Create a new user with USERNAME.11 Create a new user with username.12 """13 print(f"Creating user: {username}")1415
8 unmodified lines
24 ),25 ],26):27 """28 Delete a user with USERNAME.28 Delete a user with username.2930 If --force is not used, will ask for confirmation.31 """32 if force:
36 unmodified lines
modified:docs_src/commands/help/tutorial001_py310.py+2 added-2 removed
4 unmodified lines
56@app.command()7def create(username: str):8 """9 Create a new user with USERNAME.9 Create a new user with username.10 """11 print(f"Creating user: {username}")1213
6 unmodified lines
20 help="Force deletion without confirmation.",21 ),22):23 """24 Delete a user with USERNAME.24 Delete a user with username.2526 If --force is not used, will ask for confirmation.27 """28 if force:
34 unmodified lines
modified:docs_src/commands/help/tutorial002_py310.py+2 added-2 removed
1 unmodified line
23app = typer.Typer()456@app.command(help="Create a new user with USERNAME.")6@app.command(help="Create a new user with username.")7def create(username: str):8 """9 Some internal utility function to create.10 """11 print(f"Creating user: {username}")121314@app.command(help="Delete a user with USERNAME.")14@app.command(help="Delete a user with username.")15def delete(username: str):16 """17 Some internal utility function to delete.18 """
5 unmodified lines
modified:docs_src/commands/help/tutorial004_an_py310.py+1 added-1 removed
17 unmodified lines
18 """19 print(f"Creating user: {username}")202122@app.command(help="[bold red]Delete[/bold red] a user with [italic]USERNAME[/italic].")22@app.command(help="[bold red]Delete[/bold red] a user with [italic]username[/italic].")23def delete(24 username: Annotated[25 str, typer.Argument(help="The username to be [red]deleted[/red]")26 ],
12 unmodified lines
modified:docs_src/commands/help/tutorial004_py310.py+1 added-1 removed
15 unmodified lines
16 """17 print(f"Creating user: {username}")181920@app.command(help="[bold red]Delete[/bold red] a user with [italic]USERNAME[/italic].")20@app.command(help="[bold red]Delete[/bold red] a user with [italic]username[/italic].")21def delete(22 username: str = typer.Argument(..., help="The username to be [red]deleted[/red]"),23 force: bool = typer.Option(24 False, help="Force the [bold red]deletion[/bold red] :boom:"
10 unmodified lines
modified:docs_src/commands/help/tutorial005_an_py310.py+1 added-1 removed
21 unmodified lines
22 """23 print(f"Creating user: {username}")242526@app.command(help="**Delete** a user with *USERNAME*.")26@app.command(help="**Delete** a user with *username*.")27def delete(28 username: Annotated[str, typer.Argument(help="The username to be **deleted**")],29 force: Annotated[bool, typer.Option(help="Force the **deletion** :boom:")] = False,30):
8 unmodified lines
modified:docs_src/commands/help/tutorial005_py310.py+1 added-1 removed
17 unmodified lines
18 """19 print(f"Creating user: {username}")202122@app.command(help="**Delete** a user with *USERNAME*.")22@app.command(help="**Delete** a user with *username*.")23def delete(24 username: str = typer.Argument(..., help="The username to be **deleted**"),25 force: bool = typer.Option(False, help="Force the **deletion** :boom:"),26):
8 unmodified lines
modified:docs_src/first_steps/tutorial006_py310.py+1 added-1 removed
1 unmodified line
234def main(name: str, lastname: str = "", formal: bool = False):5 """6 Say hi to NAME, optionally with a --lastname.6 Say hi to 'name', optionally with a --lastname.78 If --formal is used, say hi very formally.9 """10 if formal:
7 unmodified lines
modified:docs_src/options/help/tutorial001_an_py310.py+1 added-1 removed
10 unmodified lines
11 lastname: Annotated[str, typer.Option(help="Last name of person to greet.")] = "",12 formal: Annotated[bool, typer.Option(help="Say hi formally.")] = False,13):14 """15 Say hi to NAME, optionally with a --lastname.15 Say hi to 'name', optionally with a --lastname.1617 If --formal is used, say hi very formally.18 """19 if formal:
7 unmodified lines
modified:docs_src/options/help/tutorial001_py310.py+1 added-1 removed
8 unmodified lines
9 lastname: str = typer.Option("", help="Last name of person to greet."),10 formal: bool = typer.Option(False, help="Say hi formally."),11):12 """13 Say hi to NAME, optionally with a --lastname.13 Say hi to 'name', optionally with a --lastname.1415 If --formal is used, say hi very formally.16 """17 if formal:
7 unmodified lines
modified:docs_src/options/help/tutorial002_an_py310.py+1 added-1 removed
21 unmodified lines
22 ),23 ] = False,24):25 """26 Say hi to NAME, optionally with a --lastname.26 Say hi to 'name', optionally with a --lastname.2728 If --formal is used, say hi very formally.29 """30 if formal:
7 unmodified lines
modified:docs_src/options/help/tutorial002_py310.py+1 added-1 removed
13 unmodified lines
14 False, help="Enable debugging.", rich_help_panel="Customization and Utils"15 ),16):17 """18 Say hi to NAME, optionally with a --lastname.18 Say hi to 'name', optionally with a --lastname.1920 If --formal is used, say hi very formally.21 """22 if formal:
7 unmodified lines
modified:docs_src/parameter_types/number/tutorial001_an_py310.py+2 added-2 removed
5 unmodified lines
678@app.command()9def main(10 id: Annotated[int, typer.Argument(min=0, max=1000)],10 ID: Annotated[int, typer.Argument(min=0, max=1000)],11 age: Annotated[int, typer.Option(min=18)] = 20,12 score: Annotated[float, typer.Option(max=100)] = 0,13):14 print(f"ID is {id}")14 print(f"ID is {ID}")15 print(f"--age is {age}")16 print(f"--score is {score}")1718
2 unmodified lines
modified:docs_src/parameter_types/number/tutorial001_py310.py+2 added-2 removed
3 unmodified lines
456@app.command()7def main(8 id: int = typer.Argument(..., min=0, max=1000),8 ID: int = typer.Argument(..., min=0, max=1000),9 age: int = typer.Option(20, min=18),10 score: float = typer.Option(0, max=100),11):12 print(f"ID is {id}")12 print(f"ID is {ID}")13 print(f"--age is {age}")14 print(f"--score is {score}")1516
2 unmodified lines
modified:docs_src/parameter_types/number/tutorial002_an_py310.py+2 added-2 removed
5 unmodified lines
678@app.command()9def main(10 id: Annotated[int, typer.Argument(min=0, max=1000)],10 ID: Annotated[int, typer.Argument(min=0, max=1000)],11 rank: Annotated[int, typer.Option(max=10, clamp=True)] = 0,12 score: Annotated[float, typer.Option(min=0, max=100, clamp=True)] = 0,13):14 print(f"ID is {id}")14 print(f"ID is {ID}")15 print(f"--rank is {rank}")16 print(f"--score is {score}")1718
2 unmodified lines
modified:docs_src/parameter_types/number/tutorial002_py310.py+2 added-2 removed
3 unmodified lines
456@app.command()7def main(8 id: int = typer.Argument(..., min=0, max=1000),8 ID: int = typer.Argument(..., min=0, max=1000),9 rank: int = typer.Option(0, max=10, clamp=True),10 score: float = typer.Option(0, min=0, max=100, clamp=True),11):12 print(f"ID is {id}")12 print(f"ID is {ID}")13 print(f"--rank is {rank}")14 print(f"--score is {score}")1516
2 unmodified lines
modified:docs_src/parameter_types/uuid/tutorial001_py310.py+1 added-1 removed
5 unmodified lines
678@app.command()9def main(user_id: UUID):10 print(f"USER_ID is {user_id}")10 print(f"User ID is {user_id}")11 print(f"UUID version is: {user_id.version}")121314if __name__ == "__main__":
1 unmodified line
added:tests/assets/cli/minimum_main.py+8 added
1import typer23app = typer.Typer()456@app.callback()7def main(name: str) -> None:8 pass # pragma: no cover
modified:tests/assets/cli/multiapp-docs-title.md+4 added-4 removed
63 unmodified lines
64```6566**Options**:6768* `--name TEXT`: [default: World]69* `--age INTEGER`: The age of the user [default: 0]68* `--name <str>`: [default: World]69* `--age <int>`: The age of the user [default: 0]70* `--help`: Show this message and exit.7172### `multiapp sub hi`73
1 unmodified line
7576**Usage**:7778```console79$ multiapp sub hi [OPTIONS] [USER]79$ multiapp sub hi [OPTIONS] [user]80```8182**Arguments**:8384* `[USER]`: The name of the user to greet [default: World]84* `user`: The name of the user to greet [default: World]8586**Options**:8788* `--help`: Show this message and exit.
14 unmodified lines
modified:tests/assets/cli/multiapp-docs.md+4 added-4 removed
63 unmodified lines
64```6566**Options**:6768* `--name TEXT`: [default: World]69* `--age INTEGER`: The age of the user [default: 0]68* `--name <str>`: [default: World]69* `--age <int>`: The age of the user [default: 0]70* `--help`: Show this message and exit.7172### `multiapp sub hi`73
1 unmodified line
7576**Usage**:7778```console79$ multiapp sub hi [OPTIONS] [USER]79$ multiapp sub hi [OPTIONS] [user]80```8182**Arguments**:8384* `[USER]`: The name of the user to greet [default: World]84* `user`: The name of the user to greet [default: World]8586**Options**:8788* `--help`: Show this message and exit.
14 unmodified lines
modified:tests/assets/cli/richformattedapp-docs.md+3 added-3 removed
3 unmodified lines
45**Usage**:67```console8$ hello [OPTIONS] USER_1 [USER_2]8$ hello [OPTIONS] {user_1} [user_2]9```1011**Arguments**:1213* `USER_1`: The <span style="font-weight: bold">cool</span> name of the <span style="color: #008000; text-decoration-color: #008000">user</span> [required]14* `[USER_2]`: The world [default: The World]13* `user_1`: The <span style="font-weight: bold">cool</span> name of the <span style="color: #008000; text-decoration-color: #008000">user</span> [required]14* `user_2`: The world [default: The World]1516**Options**:1718* `--force / --no-force`: Force the welcome <span style="color: #800000; text-decoration-color: #800000">message</span> [default: no-force]
3 unmodified lines
modified:tests/test_cli/test_help.py+16 added-1 removed
119 unmodified lines
120121 output_lines = result.output.splitlines()122 usage_idx = output_lines.index("Usage: very-long-program-name-that-forces-wrap ")123 args_line = output_lines[usage_idx + 1]124 assert args_line.lstrip() == "[OPTIONS] VALUE"124 assert args_line.lstrip() == "[OPTIONS] {value}"125 assert args_line.startswith(" ")126127128def test_format_long_help_option() -> None:
27 unmodified lines
156 assert (157 "Description is rendered in the next line for long option labels."158 in continuation_block159 )160161162def test_typer_run_usage() -> None:163 from typer.cli import app as typer_cli_app164165 result = runner.invoke(166 typer_cli_app,167 ["tests/assets/cli/minimum_main.py", "run"],168 prog_name="typer",169 )170171 assert result.exit_code == 2172 usage_line = result.output.splitlines()[0]173 assert usage_line.startswith("Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}")174 assert "Try 'typer [PATH_OR_MODULE] run --help' for help." in result.output
modified:tests/test_completion/example_rich_tags.py+2 added-2 removed
4 unmodified lines
56@app.command()7def create(username: str):8 """9 Create a [green]new[green/] user with USERNAME.9 Create a [green]new[green/] user with username.10 """11 print(f"Creating user: {username}")121314@app.command()15def delete(username: str):16 """17 Delete a user with [bold]USERNAME[/].17 Delete a user with [bold]username[/].18 """19 print(f"Deleting user: {username}")2021
10 unmodified lines
modified:tests/test_completion/test_completion_complete_rich.py+4 added-4 removed
56 unmodified lines
57 "_TYPER_COMPLETE_ARGS": "example_rich_tags.py del",58 },59 )60 assert (61 """_arguments '*: :(("delete":"Delete a user with USERNAME."\n"""61 """_arguments '*: :(("delete":"Delete a user with username."\n"""62 """\"delete-all":"Delete ALL users in the database."))'"""63 ) in result.stdout6465
9 unmodified lines
75 "_TYPER_COMPLETE_FISH_ACTION": "get-args",76 },77 )78 assert (79 "delete\tDelete a user with USERNAME.\ndelete-all\tDelete ALL users in the database."79 "delete\tDelete a user with username.\ndelete-all\tDelete ALL users in the database."80 in result.stdout81 )8283
8 unmodified lines
92 "_TYPER_COMPLETE_ARGS": "example_rich_tags.py del",93 },94 )95 assert (96 "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database."96 "delete:::Delete a user with username.\ndelete-all:::Delete ALL users in the database."97 ) in result.stdout9899100def test_completion_complete_subcommand_pwsh():
7 unmodified lines
108 "_TYPER_COMPLETE_ARGS": "example_rich_tags.py del",109 },110 )111 assert (112 "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database."112 "delete:::Delete a user with username.\ndelete-all:::Delete ALL users in the database."113 ) in result.stdout
modified:tests/test_completion/test_completion_complete.py+4 added-4 removed
65 unmodified lines
66 "_TYPER_COMPLETE_ARGS": f"{file_name} del",67 },68 )69 assert (70 """_arguments '*: :(("delete":"Delete a user with USERNAME."\n"""70 """_arguments '*: :(("delete":"Delete a user with username."\n"""71 """\"delete-all":"Delete ALL users in the database."))'"""72 ) in result.stdout7374
25 unmodified lines
100 "_TYPER_COMPLETE_FISH_ACTION": "get-args",101 },102 )103 assert (104 "delete\tDelete a user with USERNAME.\ndelete-all\tDelete ALL users in the database."104 "delete\tDelete a user with username.\ndelete-all\tDelete ALL users in the database."105 in result.stdout106 )107108
41 unmodified lines
150 "_TYPER_COMPLETE_ARGS": f"{file_name} del",151 },152 )153 assert (154 "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database."154 "delete:::Delete a user with username.\ndelete-all:::Delete ALL users in the database."155 ) in result.stdout156157158def test_completion_complete_subcommand_pwsh(mod: ModuleType):
8 unmodified lines
167 "_TYPER_COMPLETE_ARGS": f"{file_name} del",168 },169 )170 assert (171 "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database."171 "delete:::Delete a user with username.\ndelete-all:::Delete ALL users in the database."172 ) in result.stdout173174175def test_completion_complete_subcommand_noshell(mod: ModuleType):
12 unmodified lines
modified:tests/test_tutorial/test_arguments/test_default/test_tutorial001.py+1 added-1 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "[OPTIONS] [NAME]" in result.output28 assert "[OPTIONS] [name]" in result.output29 assert "Arguments" in result.output30 assert "[default: Wade Wilson]" in result.output3132
19 unmodified lines
modified:tests/test_tutorial/test_arguments/test_default/test_tutorial002.py+1 added-1 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "[OPTIONS] [NAME]" in result.output28 assert "[OPTIONS] [name]" in result.output29 assert "Arguments" in result.output30 assert "[default: (dynamic)]" in result.output3132
21 unmodified lines
modified:tests/test_tutorial/test_arguments/test_envvar/test_tutorial001.py+2 added-2 removed
25 unmodified lines
2627def test_help(mod: ModuleType):28 result = runner.invoke(mod.app, ["--help"])29 assert result.exit_code == 030 assert "[OPTIONS] [NAME]" in result.output30 assert "[OPTIONS] [name]" in result.output31 assert "Arguments" in result.output32 assert "env var: AWESOME_NAME" in result.output33 assert "default: World" in result.output34
1 unmodified line
36def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType):37 monkeypatch.setattr(typer.core, "HAS_RICH", False)38 result = runner.invoke(mod.app, ["--help"])39 assert result.exit_code == 040 assert "[OPTIONS] [NAME]" in result.output40 assert "[OPTIONS] [name]" in result.output41 assert "Arguments" in result.output42 assert "env var: AWESOME_NAME" in result.output43 assert "default: World" in result.output44
26 unmodified lines
modified:tests/test_tutorial/test_arguments/test_envvar/test_tutorial002.py+1 added-1 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "[OPTIONS] [NAME]" in result.output28 assert "[OPTIONS] [name]" in result.output29 assert "Arguments" in result.output30 assert "env var: AWESOME_NAME, GOD_NAME" in result.output31 assert "default: World" in result.output32
26 unmodified lines
modified:tests/test_tutorial/test_arguments/test_envvar/test_tutorial003.py+1 added-1 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "[OPTIONS] [NAME]" in result.output28 assert "[OPTIONS] [name]" in result.output29 assert "Arguments" in result.output30 assert "env var: AWESOME_NAME" not in result.output31 assert "default: World" in result.output32
26 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial001.py+4 added-4 removed
24 unmodified lines
2526def test_help(mod: ModuleType):27 result = runner.invoke(mod.app, ["--help"])28 assert result.exit_code == 029 assert "[OPTIONS] NAME" in result.output29 assert "[OPTIONS] {name}" in result.output30 assert "Arguments" in result.output31 assert "NAME" in result.output31 assert "{name}" in result.output32 assert "The name of the user to greet" in result.output33 assert "[required]" in result.output343536def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType):37 monkeypatch.setattr(typer.core, "HAS_RICH", False)38 result = runner.invoke(mod.app, ["--help"])39 assert result.exit_code == 040 assert "[OPTIONS] NAME" in result.output40 assert "[OPTIONS] {name}" in result.output41 assert "Arguments" in result.output42 assert "NAME" in result.output42 assert "{name}" in result.output43 assert "The name of the user to greet" in result.output44 assert "[required]" in result.output4546
13 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial002.py+3 added-3 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "[OPTIONS] NAME" in result.output29 assert "Say hi to NAME very gently, like Dirk." in result.output28 assert "[OPTIONS] {name}" in result.output29 assert "Say hi to 'name' very gently, like Dirk." in result.output30 assert "Arguments" in result.output31 assert "NAME" in result.output31 assert "{name}" in result.output32 assert "The name of the user to greet" in result.output33 assert "[required]" in result.output3435
13 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial003.py+3 added-3 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "[OPTIONS] [NAME]" in result.output29 assert "Say hi to NAME very gently, like Dirk." in result.output28 assert "[OPTIONS] [name]" in result.output29 assert "Say hi to 'name' very gently, like Dirk." in result.output30 assert "Arguments" in result.output31 assert "NAME" in result.output31 assert "[name]" in result.output32 assert "Who to greet" in result.output33 assert "[default: World]" in result.output3435
13 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial004.py+3 added-3 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "[OPTIONS] [NAME]" in result.output29 assert "Say hi to NAME very gently, like Dirk." in result.output28 assert "[OPTIONS] [name]" in result.output29 assert "Say hi to 'name' very gently, like Dirk." in result.output30 assert "Arguments" in result.output31 assert "NAME" in result.output31 assert "[name]" in result.output32 assert "Who to greet" in result.output33 assert "[default: World]" not in result.output3435
13 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial005.py+1 added-1 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "Usage: main [OPTIONS] [NAME]" in result.output28 assert "Usage: main [OPTIONS] [name]" in result.output29 assert "Arguments" in result.output30 assert "Who to greet" in result.output31 assert "[default: (Deadpoolio the amazing's name)]" in result.output32
14 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial007.py+1 added-1 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "Say hi to NAME very gently, like Dirk." in result.output28 assert "Say hi to 'name' very gently, like Dirk." in result.output29 assert "Arguments" in result.output30 assert "Secondary Arguments" in result.output3132
13 unmodified lines
modified:tests/test_tutorial/test_arguments/test_help/test_tutorial008.py+4 added-4 removed
24 unmodified lines
2526def test_help(mod: ModuleType):27 result = runner.invoke(mod.app, ["--help"])28 assert result.exit_code == 029 assert "[OPTIONS] [NAME]" in result.output30 assert "Say hi to NAME very gently, like Dirk." in result.output29 assert "[OPTIONS] [name]" in result.output30 assert "Say hi to 'name' very gently, like Dirk." in result.output31 assert "Arguments" not in result.output32 assert "[default: World]" not in result.output333435def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType):36 monkeypatch.setattr(typer.core, "HAS_RICH", False)37 result = runner.invoke(mod.app, ["--help"])38 assert result.exit_code == 039 assert "[OPTIONS] [NAME]" in result.output40 assert "Say hi to NAME very gently, like Dirk." in result.output39 assert "[OPTIONS] [name]" in result.output40 assert "Say hi to 'name' very gently, like Dirk." in result.output41 assert "Arguments" not in result.output42 assert "[default: World]" not in result.output4344
13 unmodified lines
modified:tests/test_tutorial/test_arguments/test_optional/test_tutorial000.py+1 added-1 removed
37 unmodified lines
3839def test_cli_missing_argument(app: typer.Typer):40 result = runner.invoke(app)41 assert result.exit_code == 242 assert "Missing argument 'NAME'" in result.output42 assert "Missing argument 'name'" in result.output434445def test_script(mod: ModuleType):46 result = subprocess.run(
5 unmodified lines
modified:tests/test_tutorial/test_arguments/test_optional/test_tutorial001.py+2 added-2 removed
24 unmodified lines
2526def test_call_no_arg(mod: ModuleType):27 result = runner.invoke(mod.app)28 assert result.exit_code != 029 assert "Missing argument 'NAME'." in result.output29 assert "Missing argument 'name'." in result.output303132def test_call_no_arg_standalone(mod: ModuleType):33 # Mainly for coverage
5 unmodified lines
39 # Mainly for coverage40 monkeypatch.setattr(typer.core, "HAS_RICH", False)41 result = runner.invoke(mod.app)42 assert result.exit_code != 043 assert "Error: Missing argument 'NAME'" in result.output43 assert "Error: Missing argument 'name'" in result.output444546def test_call_arg(mod: ModuleType):47 result = runner.invoke(mod.app, ["Camila"])
11 unmodified lines
modified:tests/test_tutorial/test_arguments/test_optional/test_tutorial002.py+1 added-1 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "[OPTIONS] [NAME]" in result.output28 assert "[OPTIONS] [name]" in result.output293031def test_call_no_arg(mod: ModuleType):32 result = runner.invoke(mod.app)
17 unmodified lines
modified:tests/test_tutorial/test_arguments/test_optional/test_tutorial003.py+2 added-2 removed
13 unmodified lines
1415def test_call_no_arg():16 result = runner.invoke(app)17 assert result.exit_code != 018 assert "Missing argument 'NAME'." in result.output18 assert "Missing argument 'name'." in result.output192021def test_call_no_arg_standalone():22 # Mainly for coverage
5 unmodified lines
28 # Mainly for coverage29 monkeypatch.setattr(typer.core, "HAS_RICH", False)30 result = runner.invoke(app)31 assert result.exit_code != 032 assert "Error: Missing argument 'NAME'" in result.output32 assert "Error: Missing argument 'name'" in result.output333435def test_call_arg():36 result = runner.invoke(app, ["Camila"])
11 unmodified lines
modified:tests/test_tutorial/test_commands/test_arguments/test_tutorial001.py+2 added-2 removed
11 unmodified lines
1213def test_help_create():14 result = runner.invoke(app, ["create", "--help"])15 assert result.exit_code == 016 assert "create [OPTIONS] USERNAME" in result.output16 assert "create [OPTIONS] {username}" in result.output171819def test_help_delete():20 result = runner.invoke(app, ["delete", "--help"])21 assert result.exit_code == 022 assert "delete [OPTIONS] USERNAME" in result.output22 assert "delete [OPTIONS] {username}" in result.output232425def test_create():26 result = runner.invoke(app, ["create", "Camila"])
17 unmodified lines
modified:tests/test_tutorial/test_commands/test_help/test_tutorial001.py+6 added-6 removed
25 unmodified lines
26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "Awesome CLI user manager." in result.output29 assert "create" in result.output30 assert "Create a new user with USERNAME." in result.output30 assert "Create a new user with username." in result.output31 assert "delete" in result.output32 assert "Delete a user with USERNAME." in result.output32 assert "Delete a user with username." in result.output33 assert "delete-all" in result.output34 assert "Delete ALL users in the database." in result.output35 assert "init" in result.output36 assert "Initialize the users database." in result.output
1 unmodified line
3839def test_help_create(mod: ModuleType):40 result = runner.invoke(mod.app, ["create", "--help"])41 assert result.exit_code == 042 assert "create [OPTIONS] USERNAME" in result.output43 assert "Create a new user with USERNAME." in result.output42 assert "create [OPTIONS] {username}" in result.output43 assert "Create a new user with username." in result.output444546def test_help_delete(mod: ModuleType):47 result = runner.invoke(mod.app, ["delete", "--help"])48 assert result.exit_code == 049 assert "delete [OPTIONS] USERNAME" in result.output50 assert "Delete a user with USERNAME." in result.output49 assert "delete [OPTIONS] {username}" in result.output50 assert "Delete a user with username." in result.output51 assert "--force" in result.output52 assert "--no-force" in result.output53 assert "Force deletion without confirmation." in result.output54
67 unmodified lines
modified:tests/test_tutorial/test_commands/test_help/test_tutorial002.py+4 added-4 removed
12 unmodified lines
13def test_help():14 result = runner.invoke(app, ["--help"])15 assert result.exit_code == 016 assert "create" in result.output17 assert "Create a new user with USERNAME." in result.output17 assert "Create a new user with username." in result.output18 assert "delete" in result.output19 assert "Delete a user with USERNAME." in result.output19 assert "Delete a user with username." in result.output20 assert "Some internal utility function to create." not in result.output21 assert "Some internal utility function to delete." not in result.output222324def test_help_create():25 result = runner.invoke(app, ["create", "--help"])26 assert result.exit_code == 027 assert "Create a new user with USERNAME." in result.output27 assert "Create a new user with username." in result.output28 assert "Some internal utility function to create." not in result.output293031def test_help_delete():32 result = runner.invoke(app, ["delete", "--help"])33 assert result.exit_code == 034 assert "Delete a user with USERNAME." in result.output34 assert "Delete a user with username." in result.output35 assert "Some internal utility function to delete." not in result.output363738def test_create():
18 unmodified lines
modified:tests/test_tutorial/test_commands/test_help/test_tutorial004.py+2 added-2 removed
27 unmodified lines
28 assert result.exit_code == 029 assert "create" in result.output30 assert "Create a new shiny user. ✨" in result.output31 assert "delete" in result.output32 assert "Delete a user with USERNAME." in result.output32 assert "Delete a user with username." in result.output33 assert "Some internal utility function to create." not in result.output34 assert "Some internal utility function to delete." not in result.output3536
7 unmodified lines
4445def test_help_delete(mod: ModuleType):46 result = runner.invoke(mod.app, ["delete", "--help"])47 assert result.exit_code == 048 assert "Delete a user with USERNAME." in result.output48 assert "Delete a user with username." in result.output49 assert "The username to be deleted" in result.output50 assert "Force the deletion 💥" in result.output51 assert "Some internal utility function to delete." not in result.output52
21 unmodified lines
modified:tests/test_tutorial/test_commands/test_help/test_tutorial005.py+2 added-2 removed
27 unmodified lines
28 assert result.exit_code == 029 assert "create" in result.output30 assert "Create a new shiny user. ✨" in result.output31 assert "delete" in result.output32 assert "Delete a user with USERNAME." in result.output32 assert "Delete a user with username." in result.output33 assert "Some internal utility function to create." not in result.output34 assert "Some internal utility function to delete." not in result.output3536
8 unmodified lines
4546def test_help_delete(mod: ModuleType):47 result = runner.invoke(mod.app, ["delete", "--help"])48 assert result.exit_code == 049 assert "Delete a user with USERNAME." in result.output49 assert "Delete a user with username." in result.output50 assert "The username to be deleted" in result.output51 assert "Force the deletion 💥" in result.output52 assert "Some internal utility function to delete." not in result.output53
21 unmodified lines
modified:tests/test_tutorial/test_commands/test_help/test_tutorial007.py+1 added-1 removed
34 unmodified lines
3536def test_create_help(mod: ModuleType):37 result = runner.invoke(mod.app, ["create", "--help"])38 assert result.exit_code == 039 assert "create [OPTIONS] USERNAME [LASTNAME]" in result.output39 assert "create [OPTIONS] {username} [lastname]" in result.output40 assert "username" in result.output41 assert "The username to create" in result.output42 assert "Secondary Arguments" in result.output43 assert "lastname" in result.output
27 unmodified lines
modified:tests/test_tutorial/test_first_steps/test_tutorial002.py+1 added-1 removed
13 unmodified lines
1415def test_1():16 result = runner.invoke(app, [])17 assert result.exit_code != 018 assert "Missing argument 'NAME'" in result.output18 assert "Missing argument 'name'" in result.output192021def test_2():22 result = runner.invoke(app, ["Camila"])
11 unmodified lines
modified:tests/test_tutorial/test_first_steps/test_tutorial003.py+1 added-1 removed
13 unmodified lines
1415def test_1():16 result = runner.invoke(app, ["Camila"])17 assert result.exit_code != 018 assert "Missing argument 'LASTNAME'" in result.output18 assert "Missing argument 'lastname'" in result.output192021def test_2():22 result = runner.invoke(app, ["Camila", "Gutiérrez"])
11 unmodified lines
modified:tests/test_tutorial/test_first_steps/test_tutorial004.py+2 added-2 removed
14 unmodified lines
15def test_help():16 result = runner.invoke(app, ["--help"])17 assert result.exit_code == 018 assert "Arguments" in result.output19 assert "NAME" in result.output19 assert "{name}" in result.output20 assert "[required]" in result.output21 assert "LASTNAME" in result.output21 assert "{lastname}" in result.output22 assert "[required]" in result.output23 assert "--formal" in result.output24 assert "--no-formal" in result.output25
32 unmodified lines
modified:tests/test_tutorial/test_first_steps/test_tutorial005.py+2 added-2 removed
14 unmodified lines
15def test_help():16 result = runner.invoke(app, ["--help"])17 assert result.exit_code == 018 assert "Arguments" in result.output19 assert "NAME" in result.output19 assert "{name}" in result.output20 assert "[required]" in result.output21 assert "--lastname" in result.output22 assert "TEXT" in result.output22 assert "<str>" in result.output23 assert "--formal" in result.output24 assert "--no-formal" in result.output2526
31 unmodified lines
modified:tests/test_tutorial/test_first_steps/test_tutorial006.py+1 added-1 removed
13 unmodified lines
1415def test_help():16 result = runner.invoke(app, ["--help"])17 assert result.exit_code == 018 assert "Say hi to NAME, optionally with a --lastname." in result.output18 assert "Say hi to 'name', optionally with a --lastname." in result.output19 assert "If --formal is used, say hi very formally." in result.output202122def test_1():
30 unmodified lines
modified:tests/test_tutorial/test_multiple_values/test_arguments_with_multiple_values/test_tutorial002.py+1 added-1 removed
25 unmodified lines
2627def test_help(mod: ModuleType):28 result = runner.invoke(mod.app, ["--help"])29 assert result.exit_code == 030 assert "[OPTIONS] [NAMES]..." in result.output30 assert "[OPTIONS] [names]..." in result.output31 assert "Arguments" in result.output32 assert "[default: Harry, Hermione, Ron]" in result.output3334
29 unmodified lines
modified:tests/test_tutorial/test_multiple_values/test_options_with_multiple_values/test_tutorial001.py+3 added
56 unmodified lines
57 capture_output=True,58 encoding="utf-8",59 )60 assert "Usage" in result.stdout6162 # ensure that also tuple of None's isn't displayed63 assert "[default: None, None, None]" not in result.stdout
modified:tests/test_tutorial/test_options/test_help/test_tutorial001.py+1 added-1 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "Say hi to NAME, optionally with a --lastname." in result.output28 assert "Say hi to 'name', optionally with a --lastname." in result.output29 assert "If --formal is used, say hi very formally." in result.output30 assert "Last name of person to greet." in result.output31 assert "Say hi formally." in result.output32
26 unmodified lines
modified:tests/test_tutorial/test_options/test_help/test_tutorial003.py+1 added-1 removed
30 unmodified lines
31def test_help(mod: ModuleType):32 result = runner.invoke(mod.app, ["--help"])33 assert result.exit_code == 034 assert "--fullname" in result.output35 assert "TEXT" in result.output35 assert "<str>" in result.output36 assert "[default: Wade Wilson]" not in result.output373839def test_script(mod: ModuleType):
6 unmodified lines
modified:tests/test_tutorial/test_options/test_help/test_tutorial004.py+1 added-1 removed
32 unmodified lines
33 monkeypatch.setenv("COLUMNS", "200")34 result = runner.invoke(mod.app, ["--help"])35 assert result.exit_code == 036 assert "--fullname" in result.output37 assert "TEXT" in result.output37 assert "<str>" in result.output38 assert "[default: (Deadpoolio the amazing's name)]" in result.output394041def test_script(mod: ModuleType):
6 unmodified lines
modified:tests/test_tutorial/test_options/test_name/test_tutorial001.py+1 added-1 removed
24 unmodified lines
25def test_option_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "--name" in result.output29 assert "TEXT" in result.output29 assert "<str>" in result.output30 assert "--user-name" not in result.output313233def test_call(mod: ModuleType):
18 unmodified lines
modified:tests/test_tutorial/test_options/test_name/test_tutorial002.py+1 added-1 removed
25 unmodified lines
26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "-n" in result.output29 assert "--name" in result.output30 assert "TEXT" in result.output30 assert "<str>" in result.output31 assert "--user-name" not in result.output323334def test_call(mod: ModuleType):
18 unmodified lines
modified:tests/test_tutorial/test_options/test_name/test_tutorial003.py+1 added-1 removed
24 unmodified lines
25def test_option_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "-n" in result.output29 assert "TEXT" in result.output29 assert "<str>" in result.output30 assert "--user-name" not in result.output31 assert "--name" not in result.output3233
13 unmodified lines
modified:tests/test_tutorial/test_options/test_name/test_tutorial004.py+1 added-1 removed
25 unmodified lines
26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "-n" in result.output29 assert "--user-name" in result.output30 assert "TEXT" in result.output30 assert "<str>" in result.output31 assert "--name" not in result.output323334def test_call(mod: ModuleType):
18 unmodified lines
modified:tests/test_tutorial/test_options/test_name/test_tutorial005.py+1 added-1 removed
25 unmodified lines
26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "-n" in result.output29 assert "--name" in result.output30 assert "TEXT" in result.output30 assert "<str>" in result.output31 assert "-f" in result.output32 assert "--formal" in result.output3334
30 unmodified lines
modified:tests/test_tutorial/test_options/test_password/test_tutorial001.py+1 added-1 removed
42 unmodified lines
43def test_help(mod: ModuleType):44 result = runner.invoke(mod.app, ["--help"])45 assert result.exit_code == 046 output_without_double_spaces = strip_double_spaces(result.output)47 assert "--email TEXT [required]" in output_without_double_spaces47 assert "--email <str> [required]" in output_without_double_spaces484950def test_script(mod: ModuleType):51 result = subprocess.run(
5 unmodified lines
modified:tests/test_tutorial/test_options/test_password/test_tutorial002.py+1 added-1 removed
46 unmodified lines
47def test_help(mod: ModuleType):48 result = runner.invoke(mod.app, ["--help"])49 assert result.exit_code == 050 output_without_double_spaces = strip_double_spaces(result.output)51 assert "--password TEXT [required]" in output_without_double_spaces51 assert "--password <str> [required]" in output_without_double_spaces525354def test_script(mod: ModuleType):55 result = subprocess.run(
5 unmodified lines
modified:tests/test_tutorial/test_options/test_prompt/test_tutorial001.py+1 added-1 removed
37 unmodified lines
38def test_help(mod: ModuleType):39 result = runner.invoke(mod.app, ["--help"])40 assert result.exit_code == 041 assert "--lastname" in result.output42 assert "TEXT" in result.output42 assert "<str>" in result.output43 assert "[required]" in result.output444546def test_script(mod: ModuleType):
6 unmodified lines
modified:tests/test_tutorial/test_options/test_prompt/test_tutorial002.py+1 added-1 removed
37 unmodified lines
38def test_help(mod: ModuleType):39 result = runner.invoke(mod.app, ["--help"])40 assert result.exit_code == 041 assert "--lastname" in result.output42 assert "TEXT" in result.output42 assert "<str>" in result.output43 assert "[required]" in result.output444546def test_script(mod: ModuleType):
6 unmodified lines
modified:tests/test_tutorial/test_options/test_prompt/test_tutorial003.py+1 added-1 removed
46 unmodified lines
47def test_help(mod: ModuleType):48 result = runner.invoke(mod.app, ["--help"])49 assert result.exit_code == 050 assert "--project-name" in result.output51 assert "TEXT" in result.output51 assert "<str>" in result.output52 assert "[required]" in result.output535455def test_script(mod: ModuleType):
6 unmodified lines
modified:tests/test_tutorial/test_options/test_required/test_tutorial001_tutorial002.py+2 added-2 removed
39 unmodified lines
40def test_help(mod: ModuleType):41 result = runner.invoke(mod.app, ["--help"])42 assert result.exit_code == 043 assert "--lastname" in result.output44 assert "TEXT" in result.output44 assert "<str>" in result.output45 assert "[required]" in result.output464748def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType):49 monkeypatch.setattr(typer.core, "HAS_RICH", False)50 result = runner.invoke(mod.app, ["--help"])51 assert result.exit_code == 052 assert "--lastname" in result.output53 assert "TEXT" in result.output53 assert "<str>" in result.output54 assert "[required]" in result.output555657def test_script(mod: ModuleType):
6 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_datetime/test_tutorial001.py+2 added-5 removed
18 unmodified lines
1920def test_help():21 result = runner.invoke(app, ["--help"])22 assert result.exit_code == 023 assert "[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output23 assert "<%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S>" in result.output242526def test_main():27 result = runner.invoke(app, ["1956-01-31T10:00:00"])
13 unmodified lines
4142def test_invalid():43 result = runner.invoke(app, ["july-19-1989"])44 assert result.exit_code != 045 assert (46 "Invalid value for 'BIRTH:[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]':"47 in result.output48 )45 assert "Invalid value for 'birth'" in result.output46 assert "'july-19-1989' does not match the formats" in result.output47 assert "%Y-%m-%d" in result.output48 assert "%Y-%m-%dT%H:%M:%S" in result.output49 assert "%Y-%m-%d %H:%M:%S" in result.output
9 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py+1 added-1 removed
11 unmodified lines
12def test_help():13 result = runner.invoke(app, ["--help"])14 assert result.exit_code == 015 assert "--network" in result.output16 assert "[simple|conv|lstm]" in result.output16 assert "<simple|conv|lstm>" in result.output17 assert "default: simple" in result.output181920def test_main():
38 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_enum/test_tutorial003.py+1 added-1 removed
24 unmodified lines
25def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "--groceries" in result.output29 assert "[Eggs|Bacon|Cheese]" in result.output29 assert "<Eggs|Bacon|Cheese>" in result.output30 assert "default: Eggs, Cheese" in result.output313233def test_call_no_arg(mod: ModuleType):
24 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_enum/test_tutorial004.py+1 added-1 removed
23 unmodified lines
2425def test_help(mod: ModuleType):26 result = runner.invoke(mod.app, ["--help"])27 assert result.exit_code == 028 assert "--network [simple|conv|lstm]" in result.output.replace(" ", "")28 assert "--network <simple|conv|lstm>" in result.output.replace(" ", "")293031def test_main(mod):32 result = runner.invoke(mod.app, ["--network", "conv"])
24 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_index/test_tutorial001.py+3 added-3 removed
22 unmodified lines
23def test_help():24 result = runner.invoke(app, ["--help"])25 assert result.exit_code == 026 assert "--age" in result.output27 assert "INTEGER" in result.output27 assert "<int>" in result.output28 assert "--height-meters" in result.output29 assert "FLOAT" in result.output29 assert "<float>" in result.output303132def test_params():33 result = runner.invoke(
9 unmodified lines
43def test_invalid():44 result = runner.invoke(app, ["Camila", "--age", "15.3"])45 assert result.exit_code != 046 assert "Invalid value for '--age'" in result.output47 assert "'15.3' is not a valid integer" in result.output47 assert "'15.3' is not a valid int." in result.output484950def test_script():51 result = subprocess.run(
5 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_number/test_tutorial001.py+5 added-5 removed
25 unmodified lines
2627def test_type_repr(mod: ModuleType):28 command = typer.main.get_command(mod.app)2930 id_param = next(param for param in command.params if param.name == "id")30 id_param = next(param for param in command.params if param.name == "ID")31 assert repr(id_param.type) == "<IntRange 0<=x<=1000>"3233 age_param = next(param for param in command.params if param.name == "age")34 assert repr(age_param.type) == "<IntRange x>=18>"
5 unmodified lines
40def test_help(mod: ModuleType):41 result = runner.invoke(mod.app, ["--help"])42 assert result.exit_code == 043 assert "--age" in result.output44 assert "INTEGER RANGE" in result.output44 assert "int range" in result.output45 assert "--score" in result.output46 assert "FLOAT RANGE" in result.output46 assert "float range" in result.output474849def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType):50 monkeypatch.setattr(typer.core, "HAS_RICH", False)51 result = runner.invoke(mod.app, ["--help"])52 assert result.exit_code == 053 assert "--age" in result.output54 assert "INTEGER RANGE" in result.output54 assert "int range" in result.output55 assert "--score" in result.output56 assert "FLOAT RANGE" in result.output56 assert "float range" in result.output575859def test_params(mod: ModuleType):60 result = runner.invoke(mod.app, ["5", "--age", "20", "--score", "90"])
44 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_uuid/test_tutorial001.py+4 added-6 removed
18 unmodified lines
1920def test_main():21 result = runner.invoke(app, ["d48edaa6-871a-4082-a196-4daab372d4a1"])22 assert result.exit_code == 023 assert "USER_ID is d48edaa6-871a-4082-a196-4daab372d4a1" in result.output23 assert "User ID is d48edaa6-871a-4082-a196-4daab372d4a1" in result.output24 assert "UUID version is: 4" in result.output252627def test_main_with_uuid_object():28 user_id = uuid.UUID("d48edaa6-871a-4082-a196-4daab372d4a1")29 result = runner.invoke(app, [], default_map={"user_id": user_id})30 assert result.exit_code == 031 assert "USER_ID is d48edaa6-871a-4082-a196-4daab372d4a1" in result.output31 assert "User ID is d48edaa6-871a-4082-a196-4daab372d4a1" in result.output32 assert "UUID version is: 4" in result.output333435def test_invalid_uuid():36 result = runner.invoke(app, ["7479706572-72756c6573"])37 assert result.exit_code != 038 assert (39 "Invalid value for 'USER_ID': '7479706572-72756c6573' is not a valid UUID"40 in result.output41 )38 assert "Invalid value for 'user_id'" in result.output39 assert "not a valid UUID" in result.output404142def test_script():43 result = subprocess.run(
5 unmodified lines
modified:tests/test_tutorial/test_typer_app/test_tutorial001.py+1 added-1 removed
11 unmodified lines
1213def test_no_arg():14 result = runner.invoke(app)15 assert result.exit_code != 016 assert "Missing argument 'NAME'." in result.output16 assert "Missing argument 'name'." in result.output171819def test_arg():20 result = runner.invoke(app, ["Camila"])
11 unmodified lines
modified:tests/test_core.py+61 added-1 removed
23 unmodified lines
2425 command = typer.main.get_command(app)26 params = {param.name: param for param in command.params}2728 assert params["my_arg_1"].human_readable_name == "MY_ARG_1"28 assert params["my_arg_1"].human_readable_name == "my_arg_1"29 assert params["my_arg_2"].human_readable_name == "META_ARG"30 assert params["my_opt"].human_readable_name == "my_opt"3132
343 unmodified lines
376377 result = runner.invoke(app, [], default_map={"names": "not-a-list"})378 assert result.exit_code == 2379 assert "Invalid value" in result.output380381382def test_parameter_name_casing():383 app = typer.Typer()384385 @app.command()386 def main(387 arg1: int,388 arg2: int = 42,389 arg3: int = typer.Argument(...),390 ARG4: int = typer.Argument(42),391 ARG5: int = typer.Option(...),392 arg6: int = typer.Option(42),393 arg7: int = typer.Argument(42, metavar="meta7"),394 arg8: int = typer.Argument(metavar="ARG8"),395 arg9: int = typer.Option(metavar="ARG9"),396 ):397 print(398 f"arg1={arg1} arg2={arg2} arg3={arg3} ARG4={ARG4} ARG5={ARG5} "399 f"arg6={arg6} arg7={arg7} arg8={arg8} arg9={arg9}"400 )401402 result = runner.invoke(403 app,404 [405 "1",406 "3",407 "4",408 "7",409 "8",410 "--arg2",411 "2",412 "--ARG5",413 "5",414 "--arg6",415 "6",416 "--ARG9",417 "9",418 ],419 )420 assert result.exit_code == 0421 assert (422 "arg1=1 arg2=2 arg3=3 ARG4=4 ARG5=5 arg6=6 arg7=7 arg8=8 arg9=9"423 in result.output424 )425426 result = runner.invoke(app, ["1", "3", "4", "7", "8", "--ARG5", "5", "--ARG9", "9"])427 assert result.exit_code == 0428 assert (429 "arg1=1 arg2=42 arg3=3 ARG4=4 ARG5=5 arg6=42 arg7=7 arg8=8 arg9=9"430 in result.output431 )432433 result = runner.invoke(app, ["1", "3", "4", "7", "8", "--arg5", "5", "--ARG9", "9"])434 assert result.exit_code != 0435 assert "No such option: --arg5" in result.output436437 result = runner.invoke(app, ["1", "3", "4", "7", "8", "--ARG5", "5", "--arg9", "9"])438 assert result.exit_code != 0439 assert "No such option: --arg9" in result.output
modified:tests/test_others.py+2 added-1 removed
448 unmodified lines
449 print(f"arg5: {type(arg5)} {arg5}")450451 result = runner.invoke(app, ["Hello", "2", "invalid"])452453 assert "Invalid value for 'ARG3': 'invalid' is not a valid integer" in result.output453 assert "Invalid value for 'arg3'" in result.output454 assert "'invalid' is not a valid int" in result.output455 result = runner.invoke(app, ["Hello", "2", "3", "--arg4", "--arg5"])456 assert (457 "arg1: <class 'str'> Hello\narg2: <class 'int'> 2\narg3: <class 'int'> 3\narg4: <class 'bool'> True\narg5: <class 'bool'> True\n"458 in result.stdout
30 unmodified lines
modified:tests/test_prog_name.py+1 added-1 removed
8 unmodified lines
9 [sys.executable, "-m", "coverage", "run", str(file_path), "--help"],10 capture_output=True,11 encoding="utf-8",12 )13 assert "Usage: custom-name [OPTIONS] I" in result.stdout13 assert "Usage: custom-name [OPTIONS] {i}" in result.stdout
modified:tests/test_rich_markup_mode.py+1 added-1 removed
23 unmodified lines
24 result = runner.invoke(app, ["World"])25 assert "Hello World" in result.stdout2627 result = runner.invoke(app, ["--help"])28 assert "ARG [required]" in result.stdout28 assert "arg [required]" in result.stdout29 assert all(c not in result.stdout for c in rounded)303132def test_rich_markup_mode_rich():
300 unmodified lines
modified:tests/test_rich_utils.py+48 added-13 removed
99 unmodified lines
100 pass # pragma: no cover101102 result = runner.invoke(app, ["--help"])103 assert "Usage" in result.stdout104 assert "BAR" in result.stdout104 assert "{bar}" in result.stdout105106107@needs_rich108@pytest.mark.parametrize("input_text", ["[ARGS]", "[ARGS]..."])
114 unmodified lines
223 f"Right boundaries not aligned: A={pos_a}, B={pos_b}, C={pos_c}"224 )225226227def test_rich_help_no_boolean_type() -> None:228 app = typer.Typer(rich_markup_mode="rich")229230 @app.command()231 def main(name: str) -> None:232 pass # pragma: no cover233234 result = runner.invoke(app, ["--help"])235 assert result.exit_code == 0236 assert "<boolean>" not in result.output237238239def test_rich_help_metavar():240 app = typer.Typer(rich_markup_mode="rich")241242 @app.command()
1 unmodified line
244 *,245 arg1: int,246 arg2: int = 42,247 arg3: int = typer.Argument(...),236 arg4: int = typer.Argument(42),237 arg5: int = typer.Option(...),248 ARG4: int = typer.Argument(42),249 ARG5: int = typer.Option(...),250 arg6: int = typer.Option(42),251 arg7: int = typer.Argument(42, metavar="meta7"),252 arg8: int = typer.Argument(metavar="ARG8"),253 arg9: int = typer.Argument(metavar="arg9"),254 ):255 pass # pragma: no cover256257 result = runner.invoke(app, ["--help"])246 assert "Usage: main [OPTIONS] ARG1 ARG3 [ARG4] [meta7] ARG8 arg9" in result.stdout258 assert (259 "Usage: main [OPTIONS] {arg1} {arg3} [ARG4] [meta7] {ARG8} {arg9}"260 in result.stdout261 )262263 out_nospace = result.stdout.replace(" ", "")264265 # arguments251 assert "arg1INTEGER" in out_nospace252 assert "arg3INTEGER" in out_nospace253 assert "[arg4]INTEGER" in out_nospace254 assert "[meta7]INTEGER" in out_nospace255 assert "ARG8INTEGER" in out_nospace256 assert "arg9INTEGER" in out_nospace266 assert "arg1<int>" in out_nospace267 assert "arg3<int>" in out_nospace268 assert "ARG4<int>" in out_nospace269 assert "meta7<int>" in out_nospace270 assert "ARG8<int>" in out_nospace271 assert "arg9<int>" in out_nospace272273 assert "arg7" not in result.stdout.lower()274 assert "arg8" not in result.stdout275 assert "ARG9" not in result.stdout276277 # options263 assert "arg2INTEGER" in out_nospace264 assert "arg5INTEGER" in out_nospace265 assert "arg6INTEGER" in out_nospace278 assert "--arg2<int>" in out_nospace279 assert "--ARG5<int>" in out_nospace280 assert "--arg6<int>" in out_nospace281282283def test_rich_lowercase_bracketed_metavar() -> None:284 # Make sure Rich doesn't "swallow" a lowercased [path] (thinking it's a Rich annotation)285 app = typer.Typer(rich_markup_mode="rich")286287 @app.callback()288 def main(path_or_module: str = typer.Argument(None)) -> None:289 pass # pragma: no cover290291 @app.command()292 def run(name: str) -> None:293 pass # pragma: no cover294295 result = runner.invoke(app, ["my-module.py", "run"], prog_name="typer")296297 assert result.exit_code == 2298 usage_line = result.output.splitlines()[0]299 assert usage_line.startswith("Usage: typer [path_or_module] run [OPTIONS] {name}")300 assert "Try 'typer [path_or_module] run --help' for help." in result.output
modified:tests/test_type_conversion.py+64 added-1 removed
1import os2from datetime import datetime3from enum import Enum4from pathlib import Path4from typing import Any5from typing import Annotated, Any, Literal67import pytest8import typer9from typer import _click, models
388 unmodified lines
398 monkeypatch.setattr(sys, "getfilesystemencoding", lambda: filesystem_encoding)399400 converted = _click.types.STRING.convert(b"\xff", None, None)401 assert converted == "ÿ"402403404@pytest.mark.parametrize(405 ("parameter", "expected_metavar"),406 [407 pytest.param(Annotated[str, typer.Option(...)], "<str>"),408 pytest.param(Annotated[str, typer.Argument(...)], "<str>"),409 pytest.param(Annotated[int, typer.Option(...)], "<int>"),410 pytest.param(Annotated[int, typer.Argument(...)], "<int>"),411 pytest.param(Annotated[float, typer.Option(...)], "<float>"),412 pytest.param(413 Annotated[float, typer.Option(..., min=0.666, max=3.42)], "<float range>"414 ),415 pytest.param(Annotated[tuple[str, int], typer.Option(...)], "<str int>..."),416 pytest.param(Annotated[tuple[Path, str], typer.Option(...)], "<path str>..."),417 pytest.param(Annotated[str, typer.Option(..., resolve_path=True)], "<str>"),418 pytest.param(Annotated[Path, typer.Option(...)], "<path>"),419 pytest.param(Annotated[Path, typer.Option(..., dir_okay=False)], "<file>"),420 pytest.param(421 Annotated[Path, typer.Option(..., file_okay=False)], "<directory>"422 ),423 pytest.param(Annotated[SomeEnum, typer.Option(...)], "<one|two|three>"),424 pytest.param(Annotated[SomeEnum, typer.Argument()], "<one|two|three>"),425 pytest.param(Annotated[Literal["x", "y"], typer.Option(...)], "<x|y>"),426 pytest.param(427 Annotated[datetime, typer.Option(..., formats=["%Y-%m-%d", "%d/%m/%Y"])],428 "<%Y-%m-%d|%d/%m/%Y>",429 ),430 ],431)432def test_param_type_help_metavar(parameter: Any, expected_metavar: str) -> None:433 app = typer.Typer()434435 @app.command()436 # TODO: type-specific default437 def with_default(value: parameter = "my_default"):438 pass # pragma: no cover439440 @app.command()441 def without_default(value: parameter):442 pass # pragma: no cover443444 result = runner.invoke(app, ["with-default", "--help"])445 assert result.exit_code == 0446 assert expected_metavar in result.output447448 result = runner.invoke(app, ["without-default", "--help"])449 assert result.exit_code == 0450 assert expected_metavar in result.output451452453def test_metavar_preformatted_square_brackets() -> None:454 app = typer.Typer()455456 @app.command()457 def main(value: Annotated[str, typer.Argument(metavar="[VALUE]")]):458 pass # pragma: no cover459460 result = runner.invoke(app, ["--help"])461 assert result.exit_code == 0462 assert "[VALUE]" in result.output463 assert "[[VALUE]]" not in result.output
modified:tests/test_types.py+2 added-2 removed
91 unmodified lines
9293def test_enum_choice_help() -> None:94 result = runner.invoke(app, ["hello-argument", "--help"])95 assert result.exit_code == 096 assert "{rick|morty}" in result.output96 assert "<rick|morty>" in result.output9798 result = runner.invoke(app, ["hello-option", "--help"])99 assert result.exit_code == 0100 assert "[rick|morty]" in result.output100 assert "<rick|morty>" in result.output101102 result = runner.invoke(app, ["hello-no-choices", "--help"])103 assert result.exit_code == 0104 assert "--name" in result.output
61 unmodified lines
modified:typer/_click/core.py+5 added-1 removed
883 unmodified lines
884885 metavar = self.type.get_metavar(param=self, ctx=ctx)886887 if metavar is None:888 metavar = self.type.name.upper()888 type_name = self.type.name889 if type_name.startswith("<") and type_name.endswith(">"):890 metavar = type_name891 else:892 metavar = f"<{type_name}>"893894 if self.nargs != 1:895 metavar += "..."896
219 unmodified lines
modified:typer/_click/types.py+4 added-4 removed
140 unmodified lines
141 self.fail(value, param, ctx)142143144class StringParamType(ParamType):145 name = "text"145 name = "str"146147 def convert(148 self, value: Any, param: Union["Parameter", None], ctx: Union["Context", None]149 ) -> Any:
42 unmodified lines
192 "%Y-%m-%d %H:%M:%S",193 ]194195 def get_metavar(self, param: "Parameter", ctx: "Context") -> str | None:196 return f"[{'|'.join(self.formats)}]"196 return f"<{'|'.join(self.formats)}>"197198 def _try_to_convert_date(self, value: Any, format: str) -> datetime | None:199 try:200 return datetime.strptime(value, format)
108 unmodified lines
309 return f"<{type(self).__name__} {self._describe_range()}{clamp}>"310311312class IntParamType(_NumberParamTypeBase):313 name = "integer"313 name = "int"314 _number_class = int315316 def __repr__(self) -> str:317 return "INT"
9 unmodified lines
327 If ``clamp`` is enabled, a value outside the range is clamped to the328 boundary instead of failing.329 """330331 name = "integer range"331 name = "int range"332333 def _clamp( # type: ignore334 self, bound: int, dir: Literal[1, -1], open: bool335 ) -> int:
360 unmodified lines
modified:typer/.agents/skills/typer/SKILL.md+2 added-2 removed
238 unmodified lines
239 """240 print(f"Creating user: {username}")241242243@app.command(help="[bold red]Delete[/bold red] a user with [italic]USERNAME[/italic].")243@app.command(help="[bold red]Delete[/bold red] a user with [italic]username[/italic].")244def delete(245 username: Annotated[246 str, typer.Argument(help="The username to be [red]deleted[/red]")247 ],
20 unmodified lines
268import typer269270app = typer.Typer(rich_markup_mode="markdown")271272@app.command(help="**Delete** a user with *USERNAME*.")272@app.command(help="**Delete** a user with *username*.")273def delete(274 username: Annotated[str, typer.Argument(help="The username to be **deleted** :boom:")]275):276 print(f"Deleting user: {username}")
12 unmodified lines
modified:typer/_types.py+3 added-7 removed
48 unmodified lines
4950 def get_metavar(self, param: _click.Parameter, ctx: _click.Context) -> str | None:51 if param.param_type_name == "option" and not param.show_choices: # type: ignore52 choice_metavars = [53 types.convert_type(type(choice)).name.upper() for choice in self.choices53 types.convert_type(type(choice)).name for choice in self.choices54 ]55 choices_str = "|".join([*dict.fromkeys(choice_metavars)])56 else:57 choices_str = "|".join(58 [str(i) for i in self._normalized_mapping(ctx=ctx).values()]59 )6061 # Use curly braces to indicate a required argument.62 if param.required and param.param_type_name == "argument":63 return f"{{{choices_str}}}"61 # Use square braces as it's a type.62 return f"<{choices_str}>"6365 # Use square braces to indicate an option or optional argument.66 return f"[{choices_str}]"6764 def get_missing_message(65 self, param: _click.Parameter, ctx: _click.Context | None66 ) -> str:67 """Message shown when no choice is passed."""
49 unmodified lines
modified:typer/cli.py+1 added-1 removed
159 unmodified lines
160@app.callback(cls=TyperCLIGroup, no_args_is_help=True)161def callback(162 ctx: typer.Context,163 *,164 path_or_module: str = typer.Argument(None),164 path_or_module: str = typer.Argument(None, metavar="PATH_OR_MODULE"),165 app: str = typer.Option(None, help="The typer app object/variable to use."),166 func: str = typer.Option(None, help="The function to convert to Typer."),167 version: bool = typer.Option(168 False,
149 unmodified lines
modified:typer/core.py+23 added-13 removed
91 unmodified lines
92 # rich_utils avoiding RegEx hacks93 if show_default_is_str:94 default_string = f"({obj.show_default})"95 elif isinstance(default_value, (list, tuple)):96 default_string = ", ".join(96 parts = [97 _get_default_string(98 obj, ctx=ctx, show_default_is_str=show_default_is_str, default_value=d99 )100 for d in default_value101 )101 ]102 if all(not part for part in parts):103 default_string = ""104 else:105 default_string = ", ".join(parts)106 elif isinstance(default_value, Enum):107 default_string = str(default_value.value)108 elif inspect.isfunction(default_value):109 default_string = _("(dynamic)")
18 unmodified lines
128 and not obj.secondary_opts129 and not default_value130 ):131 default_string = ""132 elif default_value is None:133 default_string = ""134 else:135 default_string = str(default_value)136 return default_string137
170 unmodified lines
308 def human_readable_name(self) -> str:309 if self.metavar is not None:310 return self.metavar311 assert self.name is not None, "self.name or self.metavar should be set"306 return self.name.upper()312 return self.name313314 def _get_default_string(315 self,316 *,
68 unmodified lines
385386 help = f"{help} {extra_str}" if help else f"{extra_str}"387 return name, help388383 def make_metavar(self, ctx: _click.Context) -> str:389 def make_metavar(self, ctx: _click.Context, *, usage: bool = False) -> str:390 # Modified version of _click.core.Argument.make_metavar()391 # to include Argument name392 if self.metavar is not None:393 var = self.metavar388 if not self.required and not var.startswith("["):389 var = f"[{var}]"390 return var391 var = (self.name or "").upper()392 if not self.required:394 if var.startswith("[") or not usage:395 return var396 if not self.required:397 return f"[{var}]"398 return f"{{{var}}}"399 var = self.name or ""400 if usage and not self.required:401 var = f"[{var}]"402 elif usage and self.required:403 var = f"{{{var}}}"404 type_var = self.type.get_metavar(self, ctx=ctx)405 if type_var:406 var += f":{type_var}"407 if self.nargs != 1:
11 unmodified lines
419 return None, [], []420 raise TypeError("Argument is marked as exposed, but does not have a name.")421 if len(decls) == 1:422 name = arg = decls[0]413 name = name.replace("-", "_").lower()423 name = name.replace("-", "_")424 else:425 raise TypeError(426 "Arguments take exactly one parameter declaration, got"427 f" {len(decls)}: {decls}."428 )429 return name, [arg], []430431 def get_usage_pieces(self, ctx: _click.Context) -> list[str]:422 return [self.make_metavar(ctx)]432 return [self.make_metavar(ctx, usage=True)]433434 def get_error_hint(self, ctx: _click.Context) -> str:425 return f"'{self.make_metavar(ctx)}'"435 return f"'{self.human_readable_name}'"436437 def add_to_parser(self, parser: _OptionParser, ctx: _click.Context) -> None:438 parser.add_argument(dest=self.name, nargs=self.nargs, obj=self)439
144 unmodified lines
584 opts.append(decl)585586 if name is None and possible_names:587 possible_names.sort(key=lambda x: -len(x[0])) # group long options first578 name = possible_names[0][1].replace("-", "_").lower()588 name = possible_names[0][1].replace("-", "_")589 if not name.isidentifier():590 name = None591592 return name, opts, secondary_opts
635 unmodified lines
modified:typer/main.py+12 added-1 removed
1359 unmodified lines
1360def get_command_name(name: str) -> str:1361 return name.lower().replace("_", "-")136213631364def get_default_option_flag_name(name: str, metavar: str | None) -> str:1365 flag_name = name.replace("_", "-")1366 if metavar is not None:1367 meta_flag = metavar.replace("_", "-")1368 if meta_flag.lower() == flag_name.lower():1369 return meta_flag1370 return flag_name137113721373def get_params_convertors_ctx_param_name_from_function(1374 callback: Callable[..., Any] | None,1375) -> tuple[list[TyperArgument | TyperOption], dict[str, Any], str | None]:1376 params = []
330 unmodified lines
1707 is_flag = True1708 # Click doesn't accept a flag of type bool, only None, and then it sets it1709 # to bool internally1710 parameter_type = None1702 default_option_name = get_command_name(param.name)1711 default_option_name = get_default_option_flag_name(1712 param.name, parameter_info.metavar1713 )1714 if is_flag:1715 default_option_declaration = (1716 f"--{default_option_name}/--no-{default_option_name}"1717 )
305 unmodified lines
modified:typer/rich_utils.py+11 added-11 removed
368 unmodified lines
369 metavar_name = None370 metavar_type = None371 metavar_str = param.make_metavar(ctx=ctx)372 if isinstance(param, TyperArgument):373 # TODO: revise this legacy behaviour of keeping argument names lowercased for Rich formatting374 if param.metavar is None and param.name:375 metavar_name = metavar_str.replace(param.name.upper(), param.name)373 if param.metavar is not None:374 metavar_name = param.metavar375 else:377 metavar_name = metavar_str376 metavar_name = param.name or ""377 if isinstance(param, TyperOption):378 metavar_type = metavar_str379 elif isinstance(param, TyperArgument):380 metavar_type = param.type.get_metavar(param=param, ctx=ctx)381 if metavar_type is None:382 metavar_type = f"<{param.type.name}>"383384 for opt_str in param.opts:385 if "--" in opt_str:386 opt_long_strs.append(opt_str)
12 unmodified lines
399 # Column for recording the type400 types_data = Text(style=STYLE_TYPES, overflow="fold")401402 # Fetch type400 if metavar_type and metavar_type != "BOOLEAN":403 if metavar_type and "bool" not in metavar_type.lower():404 types_data.append(metavar_type)402 else:403 type_str = param.type.name.upper()404 if type_str != "BOOLEAN":405 types_data.append(type_str)405406 # Range - from407 # https://github.com/pallets/click/blob/c63c70dabd3f86ca68678b4f00951f78f52d0270/src/click/core.py#L2698-L2706 # noqa: E501408 # skip count with default range type
293 unmodified lines
702703 console = _get_rich_console(stderr=True)704 ctx: _click.Context | None = getattr(self, "ctx", None)705 if ctx is not None:707 console.print(ctx.get_usage())706 console.print(highlighter(ctx.get_usage()), style=STYLE_USAGE_COMMAND)707708 if ctx is not None and ctx.command.get_help_option(ctx) is not None:709 console.print(710 RICH_HELP.format(712 command_path=ctx.command_path, help_option=ctx.help_option_names[0]711 command_path=escape(ctx.command_path),712 help_option=ctx.help_option_names[0],713 ),714 style=STYLE_ERRORS_SUGGESTION,715 )716
56 unmodified lines
modified:README.md+18 added-18 removed
76 unmodified lines
77```console78// Run your application79$ typer main.py run8081// You get a nice error, you are missing NAME82Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME81// You get a nice error, you are missing 'name'82Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}83Try 'typer [PATH_OR_MODULE] run --help' for help.84╭─ Error ───────────────────────────────────────────╮85│ Missing argument 'NAME'. │85│ Missing argument 'name'. │86╰───────────────────────────────────────────────────╯878889// You get a --help for free90$ typer main.py run --help9192Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME92Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}9394Run the provided Typer app.9596╭─ Arguments ───────────────────────────────────────╮97│ * name TEXT [default: None] [required] |97│ * name <str> [required] │98╰───────────────────────────────────────────────────╯99╭─ Options ─────────────────────────────────────────╮100│ --help Show this message and exit. │101╰───────────────────────────────────────────────────╯102103// Now pass the NAME argument103// Now pass the 'name' argument104$ typer main.py run Camila105106Hello Camila107
29 unmodified lines
137```console138// Run your application139$ python main.py140141// You get a nice error, you are missing NAME142Usage: main.py [OPTIONS] NAME141// You get a nice error, you are missing 'name'142Usage: main.py [OPTIONS] {name}143Try 'main.py --help' for help.144╭─ Error ───────────────────────────────────────────╮145│ Missing argument 'NAME'. │145│ Missing argument 'name'. │146╰───────────────────────────────────────────────────╯147148149// You get a --help for free150$ python main.py --help151152Usage: main.py [OPTIONS] NAME152Usage: main.py [OPTIONS] {name}153154╭─ Arguments ───────────────────────────────────────╮155│ * name TEXT [default: None] [required] |155│ * name <str> [required] │156╰───────────────────────────────────────────────────╯157╭─ Options ─────────────────────────────────────────╮158│ --help Show this message and exit. │159╰───────────────────────────────────────────────────╯160161// Now pass the NAME argument161// Now pass the 'name' argument162$ python main.py Camila163164Hello Camila165
69 unmodified lines
235│ --help Show this message │236│ and exit. │237╰───────────────────────────────────────────────────╯238╭─ Commands ────────────────────────────────────────╮239│ goodbye │239│ hello │240│ goodbye │241╰───────────────────────────────────────────────────╯242243// When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion244245// You have 2 subcommands (the 2 functions): goodbye and hello245// You have 2 subcommands (the 2 functions): hello and goodbye246```247248</div>249
3 unmodified lines
253254```console255$ python main.py hello --help256257 Usage: main.py hello [OPTIONS] NAME257 Usage: main.py hello [OPTIONS] {name}258259╭─ Arguments ───────────────────────────────────────╮260│ * name TEXT [default: None] [required] │260│ * name <str> [required] │261╰───────────────────────────────────────────────────╯262╭─ Options ─────────────────────────────────────────╮263│ --help Show this message and exit. │264╰───────────────────────────────────────────────────╯
7 unmodified lines
272273```console274$ python main.py goodbye --help275276 Usage: main.py goodbye [OPTIONS] NAME276 Usage: main.py goodbye [OPTIONS] {name}277278╭─ Arguments ───────────────────────────────────────╮279│ * name TEXT [default: None] [required] │279│ * name <str> [required] │280╰───────────────────────────────────────────────────╯281╭─ Options ─────────────────────────────────────────╮282│ --formal --no-formal [default: no-formal] │283│ --help Show this message │
94 unmodified lines