💥 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
Provenance
- Commit
42196d4- Tree
929b02f- Author
Sofie Van Landeghem <svlandeg@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
3a3bd0f
133 files changed+685 added−454 removed
modified:docs/js/custom.js+25 added-2 removed
12345678910111213141516171811 unmodified lines3031323334353637383940414211 unmodified lines5455565739585960616212 unmodified lines757677786079808182838485868782 unmodified linesfunction escapePlainCliLine(line) { return line .replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">");}
function prepareTermynalLines(lines, isRichHtml) { if (isRichHtml) { return lines.join("<br>"); } return lines.map(escapePlainCliLine).join("<br>");}
function setupTermynal() { document.querySelectorAll(".use-termynal").forEach(node => { node.style.display = "block"; new Termynal(node, {11 unmodified lines .querySelectorAll(`.${termynalActivateClass} .highlight code`) .forEach(node => { const text = node.textContent; const lines = text.split("\n"); // If it is a type in brackets like <str> or <str int boolean>, it won't have // HTML attributes (=) or a closing tag, while Rich HTML tags do. const hasHtmlAttribute = /<[A-Za-z][^>]*=/.test(text); const hasClosingTag = /<\/[a-zA-Z0-9]/.test(text); const isRichHtml = hasHtmlAttribute || hasClosingTag; const useLines = []; let buffer = []; function saveBuffer() { if (buffer.length) {11 unmodified lines // A last single <br> won't have effect // so put an additional one buffer.push(""); } const bufferValue = buffer.join("<br>"); const bufferValue = prepareTermynalLines(buffer, isRichHtml); dataValue["value"] = bufferValue; useLines.push(dataValue); buffer = []; }12 unmodified lines value: value }); } else if (line.startsWith("// ")) { saveBuffer(); const value = "💬 " + line.replace("// ", "").trimEnd(); let comment = line.replace("// ", "").trimEnd(); if (!isRichHtml) { comment = escapePlainCliLine(comment); } const value = "💬 " + comment; useLines.push({ value: value, class: "termynal-comment", delay: 082 unmodified linesmodified:docs/tutorial/arguments/default.md+4 added-4 removed
25 unmodified lines26 // Check the help27 $ python main.py --help28 29 // Notice the [default: Wade Wilson] ✨30-Usage: main.py [OPTIONS] [NAME]30+Usage: main.py [OPTIONS] [name]31 32 Arguments:33- [NAME] [default: Wade Wilson]33+ name [default: Wade Wilson]34 35 Options:36 --help Show this message and exit.37 33 unmodified lines71 ```console72 // Check the help73 $ python main.py --help74 75-Usage: main.py [OPTIONS] [NAME]75+Usage: main.py [OPTIONS] [name]76 77 Arguments:78- [NAME] [default: (dynamic)]78+ name [default: (dynamic)]79 80 Options:81 --help Show this message and exit.82 20 unmodified linesmodified:docs/tutorial/arguments/envvar.md+6 added-6 removed
18 unmodified lines19 ```console20 // Check the help21 $ python main.py --help22 23-Usage: main.py [OPTIONS] [NAME]23+Usage: main.py [OPTIONS] [name]24 25 Arguments:26- [NAME] [env var: AWESOME_NAME;default: World]26+ name [env var: AWESOME_NAME; default: World]27 28 Options:29 --help Show this message and exit.30 33 unmodified lines64 ```console65 // Check the help66 $ python main.py --help67 68-Usage: main.py [OPTIONS] [NAME]68+Usage: main.py [OPTIONS] [name]69 70 Arguments:71- [NAME] [env var: AWESOME_NAME, GOD_NAME;default: World]71+ name [env var: AWESOME_NAME, GOD_NAME; default: World]72 73 Options:74 --help Show this message and exit.75 24 unmodified lines100 //Check the help101 $ python main.py --help102 103 // It won't show the env var104-Usage: main.py [OPTIONS] [NAME]104+Usage: main.py [OPTIONS] [name]105 106 Arguments:107- [NAME] [default: World]107+ name [default: World]108 109 Options:110 --help Show this message and exit.111 7 unmodified linesmodified:docs/tutorial/arguments/help.md+25 added-25 removed
20 unmodified lines21 ```console22 $ python main.py --help23 24 // Check the section with Arguments below 🚀25-Usage: main.py [OPTIONS] NAME25+Usage: main.py [OPTIONS] {name}26 27 Arguments:28- NAME The name of the user to greet [required]28+ name The name of the user to greet [required]29 30 Options:31 --help Show this message and exit.32 ```13 unmodified lines46 ```console47 $ python main.py --help48 49 // Notice that we have the help text from the docstring and also the Arguments 📝50-Usage: main.py [OPTIONS] NAME50+Usage: main.py [OPTIONS] {name}51 52- Say hi to NAME very gently, like Dirk.52+ Say hi to 'name' very gently, like Dirk.53 54 Arguments:55- NAME The name of the user to greet [required]55+ name The name of the user to greet [required]56 57 Options:58 --help Show this message and exit.59 ```13 unmodified lines73 ```console74 $ python main.py --help75 76 // Notice the [default: World] 🔍77-Usage: main.py [OPTIONS] [NAME]77+Usage: main.py [OPTIONS] [name]78 79- Say hi to NAME very gently, like Dirk.79+ Say hi to 'name' very gently, like Dirk.80 81 Arguments:82- [NAME] Who to greet [default: World]82+ name Who to greet [default: World]83 84 Options:85 --help Show this message and exit.86 ```11 unmodified lines98 ```console99 $ python main.py --help100 101 // Notice the there's no [default: World] now 🔥102-Usage: main.py [OPTIONS] [NAME]102+Usage: main.py [OPTIONS] [name]103 104- Say hi to NAME very gently, like Dirk.104+ Say hi to 'name' very gently, like Dirk.105 106 Arguments:107- [NAME] Who to greet107+ name Who to greet108 109 Options:110 --help Show this message and exit.111 ```12 unmodified lines124 125 ```console126 $ python main.py --help127 128-Usage: main.py [OPTIONS] [NAME]128+Usage: main.py [OPTIONS] [name]129 130 Arguments:131- [NAME] Who to greet [default: (Deadpoolio the amazing's name)]131+ name Who to greet [default: (Deadpoolio the amazing's name)]132 133 134 Options:135 --help Show this message and exit.6 unmodified lines142 ## Custom help name (`metavar`)143 144 You can also customize the text used in the generated help text to represent a *CLI argument*.145 146-By default, it will be the same name you declared, in uppercase letters.146+By default, it will be the same name you declared, with casing preserved.147 148 So, if you declare it as:149 150 ```Python2 unmodified lines153 154 It will be shown as:155 156 ```157-NAME157+name158 ```159 160 But you can customize it with the `metavar` parameter for `typer.Argument()`.161 162-For 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:162+For 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:163 164 {* docs_src/arguments/help/tutorial006_an_py310.py hl[9] *}165 166-Now the generated help text will have `✨username✨` instead of `NAME`:166+Now the generated help text will have `✨username✨` instead of `name`:167 168 <div class="termy">169 170 ```console1 unmodified line172 173 Usage: main.py [OPTIONS] [✨username✨]174 175 Arguments:176- [✨username✨] [default: World]176+ ✨username✨ [default: World]177 178 Options:179 --help Show this message and exit.180 ```16 unmodified lines197 198 ```console199 $ python main.py --help200 201-<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.204 205 <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'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'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 lines239 ```console240 $ python main.py --help241 242 // Notice there's no Arguments section at all 🔥243-Usage: main.py [OPTIONS] [NAME]243+Usage: main.py [OPTIONS] [name]244 245- Say hi to NAME very gently, like Dirk.245+ Say hi to 'name' very gently, like Dirk.246 247 Options:248 --help Show this message and exit.249 ```18 unmodified linesmodified:docs/tutorial/arguments/optional.md+6 added-6 removed
82 unmodified lines83 84 ```console85 $ python main.py86 87-Usage: main.py [OPTIONS] NAME87+Usage: main.py [OPTIONS] {name}88 Try "main.py --help" for help.89 90-Error: Missing argument 'NAME'.90+Error: Missing argument 'name'.91 ```92 93 </div>94 36 unmodified lines131 ```console132 // First check the help133 $ python main.py --help134 135-Usage: main.py [OPTIONS] [NAME]135+Usage: main.py [OPTIONS] [name]136 137 Arguments:138- [NAME]138+ name [default: World]139 140 Options:141 --help Show this message and exit.142 ```1 unmodified line144 </div>145 146 /// tip147 148-Notice that `NAME` is still a *CLI argument*, it's shown up there in the "`Usage: main.py` ...".148+Notice that `name` is still a *CLI argument*, it's shown up there in the "`Usage: main.py` ...".149 150-Also notice that now `[NAME]` has brackets ("`[`" and "`]`") around (before it was just `NAME`) to denote that it's **optional**, not **required**.150+Also 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.151 152 ///153 154 Now run it and test it:84 unmodified linesmodified:docs/tutorial/commands/arguments.md+4 added-1 removed
8 unmodified lines9 ```console10 // Check the help for create11 $ python main.py create --help12 13-Usage: main.py create [OPTIONS] USERNAME13+Usage: main.py create [OPTIONS] {username}14 15+Arguments:16+ username [required]17+18 Options:19 --help Show this message and exit.20 21 // Call it with a CLI argument27 unmodified linesmodified:docs/tutorial/commands/callback.md+3 added-3 removed
38 unmodified lines39 40 Manage users in the awesome CLI app.41 42 Options: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 lines66 67 // Notice that --verbose belongs to the callback, it has to go before create or delete ⛔️68 $ python main.py create --verbose Camila69 70-Usage: main.py create [OPTIONS] USERNAME70+Usage: main.py create [OPTIONS] {username}71 Try "main.py create --help" for help.72 73 Error: No such option: --verbose74 ```66 unmodified lines141 Manage users CLI app.142 143 Use it with the create command.144 145- A new user with the given NAME will be created.145+ A new user with the given 'name' will be created.146 147 Options: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 linesmodified:docs/tutorial/commands/help.md+37 added-37 removed
22 unmodified lines23 --show-completion Show completion for the current shell, to copy it or customize the installation.24 --help Show this message and exit.25 26 Commands: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.31 32 // Now the commands have inline help 🎉33 34 // Check the help for create35 $ python main.py create --help36 37-Usage: main.py create [OPTIONS] USERNAME37+Usage: main.py create [OPTIONS] {username}38 39- Create a new user with USERNAME.39+ Create a new user with username.40 41+Arguments:42+ username [required]43+44 Options:45 --help Show this message and exit.46 47 // Check the help for delete48 $ python main.py delete --help49 47-Usage: main.py delete [OPTIONS] USERNAME50+Usage: main.py delete [OPTIONS] {username}51 49- Delete a user with USERNAME.52+ Delete a user with username.53 54 If --force is not used, will ask for confirmation.55 56+Arguments:57+ username [required]58+59 Options:60 --force / --no-force Force deletion without confirmation. [required]61 --help Show this message and exit.62 54 unmodified lines117 it or customize the installation.118 --help Show this message and exit.119 120 Commands: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.123 118-// 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 ```126 127 </div>128 36 unmodified lines165 166 ```console167 $ python main.py delete --help168 163-<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.174 175 <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><str></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 lines237 238 ```console239 $ python main.py create --help240 235-<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>245 246 <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><str></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 lines260 261 ```console262 $ python main.py delete --help263 259-<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>.267 268 <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><str></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 lines294 295 ```console296 $ python main.py create --help297 294-<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. ✨301 302 <font color="#F4BF75"><b> • </b></font><font color="#A5A5A1">Create a username </font>2 unmodified lines305 <font color="#F4BF75">───────────────────────────────────────────────────────────────────</font>306 Learn more at the <font color="#44919F">Typer docs website</font>307 308 <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><str></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 lines322 323 ```console324 $ python main.py delete --help325 323-<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>.329 330 <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><str></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 lines379 <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 lines412 413 ```console414 $ python main.py create --help415 414-<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. ✨419 420 <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><str></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><int> </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><str> </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 ```438 439 </div>20 unmodified lines460 <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 ```467 468 </div>12 unmodified lines481 482 ```console483 $ python main.py --help484 485-<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. ✨488 489 <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><str></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 linesmodified:docs/tutorial/commands/one-or-multiple.md+5 added-5 removed
10 unmodified lines11 ```console12 // Without a CLI argument13 $ python main.py14 15-Usage: main.py [OPTIONS] NAME15+Usage: main.py [OPTIONS] {name}16 Try "main.py --help" for help.17 18-Error: Missing argument 'NAME'.18+Error: Missing argument 'name'.19 20-// With the NAME CLI argument20+// With the 'name' CLI argument21 $ python main.py Camila22 23 Hello Camila24 25 // Asking for help26-$ python main.py26+$ python main.py --help27 28-Usage: main.py [OPTIONS] NAME28+Usage: main.py [OPTIONS] {name}29 30 Options: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 linesmodified:docs/tutorial/multiple-values/arguments-with-multiple-values.md+2 added-2 removed
45 unmodified lines46 ```console47 // Check the help48 $ python main.py --help49 50-Usage: main.py [OPTIONS] [NAMES]...50+Usage: main.py [OPTIONS] [names]...51 52 Arguments:53- [NAMES]... Select 3 characters to play with [default: Harry, Hermione, Ron]53+ names... Select 3 characters to play with [default: Harry, Hermione, Ron]54 55 Options:56 --help Show this message and exit.57 21 unmodified linesmodified:docs/tutorial/multiple-values/options-with-multiple-values.md+3 added-3 removed
56 unmodified lines57 ```console58 // check the help59 $ python main.py --help60 61-// Notice the <TEXT INTEGER BOOLEAN>61+// Notice the <str int boolean>62 Usage: main.py [OPTIONS]63 64 Options:65- --user <TEXT INTEGER BOOLEAN>...66- --help Show this message and exit.65+ --user <str int boolean>...66+ --help Show this message and exit.67 68 // Now try it69 $ python main.py --user Camila 50 yes70 15 unmodified linesmodified:docs/tutorial/options/callback-and-context.md+2 added-2 removed
59 unmodified lines60 // Then try with "run" and --help61 $ typer ./main.py run --help62 63 // You get a help text with your CLI options as you normally would64-Usage: typer run [OPTIONS]64+Usage: typer [PATH_OR_MODULE] run [OPTIONS]65 66 Run the provided Typer app.67 68 Options:69- --name TEXT [required]69+ --name <str>70 --help Show this message and exit.71 72 // Then try completion with your program73 $ typer ./main.py run --[TAB][TAB]132 unmodified linesmodified:docs/tutorial/options/help.md+11 added-11 removed
29 unmodified lines30 31 ```console32 $ python main.py --help33 34-Usage: main.py [OPTIONS] NAME34+Usage: main.py [OPTIONS] {name}35 36- Say hi to NAME, optionally with a --lastname.36+ Say hi to 'name', optionally with a --lastname.37 38 If --formal is used, say hi very formally.39 40 Arguments:41- NAME [required]41+ name [required]42 43 Options: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.47 48 // Now you have a help text for the --lastname and --formal CLI options 🎉49 ```16 unmodified lines66 67 ```console68 $ python main.py --help69 70-<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>74 75 <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><str></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><str></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 lines118 119 Usage: main.py [OPTIONS]120 121 Options:122- --fullname TEXT122+ --fullname <str>123 --help Show this message and exit.124 125 // Notice there's no [default: Wade Wilson] 🔥126 ```20 unmodified lines147 148 Usage: main.py [OPTIONS]149 150 Options: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.153 154 // Notice how it shows "(Deadpoolio the amazing's name)" instead of the actual default of "Wade Wilson"155 ```2 unmodified linesmodified:docs/tutorial/options/name.md+5 added-5 removed
51 unmodified lines52 // Notice the --name instead of --user-name53 Usage: main.py [OPTIONS]54 55 Options:56- --name TEXT [required]56+ --name <str> [required]57 --help Show this message and exit.58 59 // Try it60 $ python main.py --name Camila139 unmodified lines200 // Notice the two CLI option names -n and --name201 Usage: main.py [OPTIONS]202 203 Options:204- -n, --name TEXT [required]204+ -n, --name <str> [required]205 --help Show this message and exit.206 207 // Try the short version208 $ python main.py -n Camila19 unmodified lines228 // Notice there's no --name nor --user-name, only -n229 Usage: main.py [OPTIONS]230 231 Options:232- -n TEXT [required]232+ -n <str> [required]233 --help Show this message and exit.234 235 // Try it236 $ python main.py -n Camila20 unmodified lines257 // and we also have the short version -n258 Usage: main.py [OPTIONS]259 260 Options:261- -n, --user-name TEXT [required]261+ -n, --user-name <str> [required]262 --help Show this message and exit.263 264 // Try it265 $ python main.py --user-name Camila31 unmodified lines297 // And also long versions --name and --formal298 Usage: main.py [OPTIONS]299 300 Options:301- -n, --name TEXT [required]301+ -n, --name <str> [required]302 -f, --formal303 --help Show this message and exit.304 305 // Try the short versions12 unmodified linesmodified:docs/tutorial/options/prompt.md+2 added-2 removed
7 unmodified lines8 9 <div class="termy">10 11 ```console12-// Call it with the NAME CLI argument12+// Call it with the 'name' CLI argument13 $ python main.py Camila14 15 // It asks for the missing CLI option --lastname16 # Lastname: $ Gutiérrez13 unmodified lines30 31 <div class="termy">32 33 ```console34-// Call it with the NAME CLI argument34+// Call it with the 'name' CLI argument35 $ python main.py Camila36 37 // It uses the custom prompt38 # Please tell me your last name: $ Gutiérrez46 unmodified linesmodified:docs/tutorial/options/required.md+7 added-4 removed
40 unmodified lines41 42 <div class="termy">43 44 ```console45-// Pass the NAME CLI argument45+// Pass the 'name' CLI argument46 $ python main.py Camila47 48 // We didn't pass the now required --lastname CLI option49-Usage: main.py [OPTIONS] NAME49+Usage: main.py [OPTIONS] {name}50 Try "main.py --help" for help.51 52 Error: Missing option '--lastname'.53 4 unmodified lines58 59 // And if you check the help60 $ python main.py --help61 62-Usage: main.py [OPTIONS] NAME62+Usage: main.py [OPTIONS] {name}63 64+Arguments:65+ name [required]66+67 Options:65- --lastname TEXT [required]68+ --lastname <str> [required]69 --help Show this message and exit.70 71 // It now tells you that --lastname is required 🎉72 ```2 unmodified linesmodified:docs/tutorial/options/version.md+1 added-1 removed
32 unmodified lines33 Usage: main.py [OPTIONS]34 35 Options:36 --version37- --name TEXT37+ --name <str> [default: World]38 --help Show this message and exit.39 40 41 // We can call it normally71 unmodified linesmodified:docs/tutorial/parameter-types/bool.md+2 added-2 removed
22 unmodified lines23 // Notice there's only --force, we no longer have --no-force24 Usage: main.py [OPTIONS]25 26 Options:27- --force [default: False]27+ --force28 --help Show this message and exit.29 30 // Try it:31 $ python main.py80 unmodified lines112 // Notice the -f, --force / -F, --no-force113 Usage: main.py [OPTIONS]114 115 Options:116- -f, --force / -F, --no-force [default: False]116+ -f, --force / -F, --no-force [default: no-force]117 --help Show this message and exit.118 119 // Try with the short name -f120 $ python main.py -f59 unmodified linesmodified:docs/tutorial/parameter-types/datetime.md+5 added-4 removed
17 unmodified lines18 19 ```console20 $ python main.py --help21 22-Usage: main.py [OPTIONS] BIRTH:[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]22+Usage: main.py [OPTIONS] {birth}:<%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S>23 24 Arguments: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]26 27 Options:28 --help Show this message and exit.29 5 unmodified lines35 36 // An invalid date37 $ python main.py july-19-198938 39-Usage: main.py [OPTIONS] [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d%H:%M:%S]39+Usage: main.py [OPTIONS] {birth}:<%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S>40+Try 'main.py --help' for help.41 41-Error: 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'.42+Error: 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 ```44 45 </div>46 40 unmodified linesmodified:docs/tutorial/parameter-types/enum.md+6 added-6 removed
17 unmodified lines18 19 ```console20 $ python main.py --help21 22-// Notice the predefined values [simple|conv|lstm]22+// Notice the predefined values <simple|conv|lstm>23 Usage: main.py [OPTIONS]24 25 Options:26- --network [simple|conv|lstm] [default: simple]26+ --network <simple|conv|lstm> [default: simple]27 --help Show this message and exit.28 29 // Try it30 $ python main.py --network conv59 unmodified lines90 // Notice the default values being shown91 Usage: main.py [OPTIONS]92 93 Options: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.96 97 // Try it with the default values98 $ python main.py99 22 unmodified lines122 123 ```console124 $ python main.py --help125 126-// Notice the predefined values [simple|conv|lstm]126+// Notice the predefined values <simple|conv|lstm>127 Usage: main.py [OPTIONS]128 129 Options:130- --network [simple|conv|lstm] [default: simple]130+ --network <simple|conv|lstm> [default: simple]131 --help Show this message and exit.132 133 // Try it134 $ python main.py --network conv13 unmodified linesmodified:docs/tutorial/parameter-types/index.md+12 added-12 removed
8 unmodified lines9 For example:10 11 {* docs_src/parameter_types/index/tutorial001_py310.py hl[7] *}12 13-In this example, the value received for the *CLI argument* `NAME` will be treated as `str`.13+In this example, the value received for the *CLI argument* `name` will be treated as `str`.14 15 The value for the *CLI option* `--age` will be converted to an `int` and `--height-meters` will be converted to a `float`.16 17 And as `female` is a `bool` *CLI option*, **Typer** will convert it to a "flag" `--female` and the counterpart `--no-female`.4 unmodified lines22 23 ```console24 $ python main.py --help25 26-// Notice how --age is an INTEGER and --height-meters is a FLOAT27-Usage: main.py [OPTIONS] NAME26+// Notice how --age is an 'int' (integer) and --height-meters is a 'float'27+Usage: main.py [OPTIONS] {name}28 29 Arguments:30- NAME [required]30+ name [required]31 32 Options: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.37 38 // Call it with CLI parameters39 $ python main.py Camila --age 15 --height-meters 1.70 --female40 41 // All the data has the correct Python type42-NAME is Camila, of type: class 'str'42+name 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'46 47 // And if you pass an incorrect type48 $ python main.py Camila --age 15.349 50-Usage: main.py [OPTIONS] NAME50+Usage: main.py [OPTIONS] {name}51 Try "main.py --help" for help.52 53-Error: Invalid value for '--age': '15.3' is not a valid integer53+Error: Invalid value for '--age': '15.3' is not a valid int.54 55-// Because 15.3 is not an INTEGER (it's a float)55+// Because 15.3 is not an integer (it's a float)56 ```57 58 </div>59 3 unmodified linesmodified:docs/tutorial/parameter-types/number.md+9 added-9 removed
13 unmodified lines14 15 ```console16 $ python main.py --help17 18-// Notice the extra RANGE in the help text for --age and --score19-Usage: main.py [OPTIONS] ID18+// Notice the extra range information in the help text for --age and --score19+Usage: main.py [OPTIONS] {ID}20 21 Arguments:22 ID [required]23 24 Options: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.28 29 // Pass all the CLI parameters30 $ python main.py 5 --age 20 --score 9031 3 unmodified lines35 36 // Pass an invalid ID37 $ python main.py 100238 39-Usage: main.py [OPTIONS] ID39+Usage: main.py [OPTIONS] {ID}40 Try "main.py --help" for help.41 42 Error: Invalid value for 'ID': 1002 is not in the range 0<=x<=1000.43 44 // Pass an invalid age45 $ python main.py 5 --age 1546 47-Usage: main.py [OPTIONS] ID47+Usage: main.py [OPTIONS] {ID}48 Try "main.py --help" for help.49 50 Error: Invalid value for '--age': 15 is not in the range x>=18.51 52 // Pass an invalid score53 $ python main.py 5 --age 20 --score 100.554 55-Usage: main.py [OPTIONS] ID55+Usage: main.py [OPTIONS] {ID}56 Try "main.py --help" for help.57 58 Error: Invalid value for '--score': 100.5 is not in the range x<=100.59 22 unmodified lines82 ```console83 // ID doesn't have clamp, so it shows an error84 $ python main.py 100285 86-Usage: main.py [OPTIONS] ID86+Usage: main.py [OPTIONS] {ID}87 Try "main.py --help" for help.88 89 Error: Invalid value for 'ID': 1002 is not in the range 0<=x<=1000.90 55 unmodified linesmodified:docs/tutorial/parameter-types/path.md+1 added-1 removed
14 unmodified lines15 ```console16 // No config17 $ python main.py18 19+Aborted.20 No config file20-Aborted!21 22 // Pass a config that doesn't exist23 $ python main.py --config config.txt24 82 unmodified linesmodified:docs/tutorial/parameter-types/uuid.md+3 added-3 removed
32 unmodified lines33 ```console34 // Pass a valid UUID v435 $ python main.py d48edaa6-871a-4082-a196-4daab372d4a136 37-USER_ID is d48edaa6-871a-4082-a196-4daab372d4a137+User ID is d48edaa6-871a-4082-a196-4daab372d4a138 UUID version is: 439 40 // An invalid value41 $ python main.py 7479706572-72756c657342 43-Usage: main.py [OPTIONS] USER_ID43+Usage: main.py [OPTIONS] {user_id}44 Try "main.py --help" for help.45 46-Error: Invalid value for 'USER_ID': 7479706572-72756c6573 is not a valid UUID.46+Error: Invalid value for 'user_id': 7479706572-72756c6573 is not a valid UUID.47 ```48 49 </div>modified:docs/tutorial/subcommands/add-typer.md+1 added-1 removed
82 unmodified lines83 --show-completion Show completion for the current shell, to copy it or customize the installation.84 --help Show this message and exit.85 86 Commands:87- items87 users88+ items89 ```90 91 </div>92 76 unmodified linesmodified:docs/tutorial/subcommands/nested-subcommands.md+3 added-3 removed
65 unmodified lines66 --show-completion Show completion for the current shell, to copy it or customize the installation.67 --help Show this message and exit.68 69 Commands:70- burn70 found71+ burn72 73 // Try it74 $ python towns.py found "New Asgard"75 53 unmodified lines129 Options:130 --help Show this message and exit.131 132 Commands:133- burn133 found134+ burn135 ```136 137 </div>138 65 unmodified lines204 --show-completion Show completion for the current shell, to copy it or customize the installation.205 --help Show this message and exit.206 207 Commands:208+ users209 items210 lands210- users211 212 // Try some users commands213 $ python main.py users create Camila214 69 unmodified linesmodified:docs/tutorial/first-steps.md+25 added-28 removed
68 unmodified lines69 70 $ python main.py71 72 // 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">'main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">'</font><font color="#A5A5A1"> for help.</font>75 <font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>76-<font color="#F92672">│</font> Missing argument 'NAME'. <font color="#F92672">│</font>76+<font color="#F92672">│</font> Missing argument 'name'. <font color="#F92672">│</font>77 <font color="#F92672">╰───────────────────────────────────────────────────╯</font>78 79-// Now pass that NAME CLI argument79+// Now pass that 'name' CLI argument80 $ python main.py Camila81 82 Hello Camila83 26 unmodified lines110 ```console111 // Check the main --help112 $ python main.py --help113 114-<font color="#F4BF75">Usage: </font>main.py [OPTIONS] NAME115-<font color="#A5A5A1">Try </font><font color="#44919F">'main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">'</font><font color="#A5A5A1"> for help.</font>116-<font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>117-<font color="#F92672">│</font> Missing argument 'NAME'. <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><str></b></font> <font color="#A6194C">[required]</font> │118+<font color="#A5A5A1">│ </font><font color="#F92672">*</font> lastname <font color="#F4BF75"><b><str></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>124 120-<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">'main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">'</font><font color="#A5A5A1"> for help.</font>124-<font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>125-<font color="#F92672">│</font> Missing argument 'NAME'. <font color="#F92672">│</font>126-<font color="#F92672">╰───────────────────────────────────────────────────╯</font>127-125 // There are now 2 CLI arguments, name and lastname126 127 // Now pass a single name argument128 $ python main.py Camila129 133-<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">'main.py </font><font color="#44919F"><b>--help</b></font><font color="#44919F">'</font><font color="#A5A5A1"> for help.</font>132 <font color="#F92672">╭─ Error ───────────────────────────────────────────╮</font>136-<font color="#F92672">│</font> Missing argument 'LASTNAME'. <font color="#F92672">│</font>133+<font color="#F92672">│</font> Missing argument 'lastname'. <font color="#F92672">│</font>134 <font color="#F92672">╰───────────────────────────────────────────────────╯</font>135 136 // These 2 arguments are required, so, pass both:137 $ python main.py Camila Gutiérrez96 unmodified lines234 ```console235 // Get the help236 $ python main.py --help237 241-<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><str></b></font> <font color="#A6194C">[required]</font> │242+<font color="#A5A5A1">│ </font><font color="#F92672">*</font> lastname <font color="#F4BF75"><b><str></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 lines294 295 ```console296 $ python main.py --help297 301-<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><str></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><str></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 lines365 366 ```console367 $ python main.py --help368 372-<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>373 374 <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><str></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><str></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 linesmodified:docs/tutorial/one-file-per-command.md+2 added-2 removed
5 unmodified lines6 7 We will create a simple CLI with the following commands:8 9 - `version`10-- `users add NAME`11-- `users delete NAME`10+- `users add 'name'`11+- `users delete 'name'`12 13 ## CLI structure14 15 Here is the structure we'll be working with:129 unmodified linesmodified:docs/tutorial/typer-app.md+7 added-4 removed
49 unmodified lines50 ```console51 // Without a CLI argument52 $ python main.py53 54-Usage: main.py [OPTIONS] NAME54+Usage: main.py [OPTIONS] {name}55 Try "main.py --help" for help.56 57-Error: Missing argument 'NAME'.57+Error: Missing argument 'name'.58 59-// With the NAME CLI argument59+// With the 'name' CLI argument60 $ python main.py Camila61 62 Hello Camila63 64 // Asking for help65 $ python main.py --help66 67-Usage: main.py [OPTIONS] NAME67+Usage: main.py [OPTIONS] {name}68 69+Arguments:70+ name [required]71+72 Options: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 linesmodified:docs/tutorial/typer-command.md+14 added-14 removed
167 unmodified lines168 <div class="termy">169 170 ```console171 $ typer main.py run --help172-Usage: typer run [OPTIONS]172+Usage: typer [PATH_OR_MODULE] run [OPTIONS]173 174 Say hi to someone, by default to the World.175 176 Options:177- --name TEXT178- --help Show this message and exit.177+ --name <str> [default: World]178+ --help Show this message and exit.179 180 $ typer main.py run --name Camila181 182 Hello Camila12 unmodified lines195 <div class="termy">196 197 ```console198 $ typer my_package.main run --help199-Usage: typer run [OPTIONS]199+Usage: typer [PATH_OR_MODULE] run [OPTIONS]200 201 Options:202- --name TEXT202+ --name <str>203 --help Show this message and exit.204 205 $ typer my_package.main run --name Camila206 57 unmodified lines264 ///265 266 **Options**:267 268-* `--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.271 272 For example:273 274 <div class="termy">29 unmodified lines304 * `--help`: Show this message and exit.305 306 **Commands**:307 308-* `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.312 313 ## `awesome-cli create`314 315-Create a new user with USERNAME.315+Create a new user with username.316 317 **Usage**:318 319 ```console320-$ awesome-cli create [OPTIONS] USERNAME320+$ awesome-cli create [OPTIONS] {username}321 ```322 323 **Options**:324 325 * `--help`: Show this message and exit.326 327 ## `awesome-cli delete`328 329-Delete a user with USERNAME.329+Delete a user with 'username'.330 331 If --force is not used, will ask for confirmation.332 333 **Usage**:334 335 ```console336-$ awesome-cli delete [OPTIONS] USERNAME336+$ awesome-cli delete [OPTIONS] {username}337 ```338 339 **Options**:340 33 unmodified linesmodified:docs/index.md+18 added-18 removed
84 unmodified lines85 ```console86 // Run your application87 $ typer main.py run88 89-// You get a nice error, you are missing NAME90-Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME89+// You get a nice error, you are missing 'name'90+Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}91 Try 'typer [PATH_OR_MODULE] run --help' for help.92 ╭─ Error ───────────────────────────────────────────╮93-│ Missing argument 'NAME'. │93+│ Missing argument 'name'. │94 ╰───────────────────────────────────────────────────╯95 96 97 // You get a --help for free98 $ typer main.py run --help99 100-Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME100+Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}101 102 Run the provided Typer app.103 104 ╭─ Arguments ───────────────────────────────────────╮105-│ * name TEXT [default: None] [required] |105+│ * name <str> [required] │106 ╰───────────────────────────────────────────────────╯107 ╭─ Options ─────────────────────────────────────────╮108 │ --help Show this message and exit. │109 ╰───────────────────────────────────────────────────╯110 111-// Now pass the NAME argument111+// Now pass the 'name' argument112 $ typer main.py run Camila113 114 Hello Camila115 29 unmodified lines145 ```console146 // Run your application147 $ python main.py148 149-// You get a nice error, you are missing NAME150-Usage: main.py [OPTIONS] NAME149+// You get a nice error, you are missing 'name'150+Usage: main.py [OPTIONS] {name}151 Try 'main.py --help' for help.152 ╭─ Error ───────────────────────────────────────────╮153-│ Missing argument 'NAME'. │153+│ Missing argument 'name'. │154 ╰───────────────────────────────────────────────────╯155 156 157 // You get a --help for free158 $ python main.py --help159 160-Usage: main.py [OPTIONS] NAME160+Usage: main.py [OPTIONS] {name}161 162 ╭─ Arguments ───────────────────────────────────────╮163-│ * name TEXT [default: None] [required] |163+│ * name <str> [required] │164 ╰───────────────────────────────────────────────────╯165 ╭─ Options ─────────────────────────────────────────╮166 │ --help Show this message and exit. │167 ╰───────────────────────────────────────────────────╯168 169-// Now pass the NAME argument169+// Now pass the 'name' argument170 $ python main.py Camila171 172 Hello Camila173 69 unmodified lines243 │ --help Show this message │244 │ and exit. │245 ╰───────────────────────────────────────────────────╯246 ╭─ Commands ────────────────────────────────────────╮247-│ goodbye │247 │ hello │248+│ goodbye │249 ╰───────────────────────────────────────────────────╯250 251 // When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion252 253-// You have 2 subcommands (the 2 functions): goodbye and hello253+// You have 2 subcommands (the 2 functions): hello and goodbye254 ```255 256 </div>257 3 unmodified lines261 262 ```console263 $ python main.py hello --help264 265- Usage: main.py hello [OPTIONS] NAME265+ Usage: main.py hello [OPTIONS] {name}266 267 ╭─ Arguments ───────────────────────────────────────╮268-│ * name TEXT [default: None] [required] │268+│ * name <str> [required] │269 ╰───────────────────────────────────────────────────╯270 ╭─ Options ─────────────────────────────────────────╮271 │ --help Show this message and exit. │272 ╰───────────────────────────────────────────────────╯7 unmodified lines280 281 ```console282 $ python main.py goodbye --help283 284- Usage: main.py goodbye [OPTIONS] NAME284+ Usage: main.py goodbye [OPTIONS] {name}285 286 ╭─ 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 linesmodified:docs_src/arguments/help/tutorial002_an_py310.py+1 added-1 removed
6 unmodified lines7 8 @app.command()9 def 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}")14 15 2 unmodified linesmodified:docs_src/arguments/help/tutorial002_py310.py+1 added-1 removed
4 unmodified lines5 6 @app.command()7 def 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}")12 13 2 unmodified linesmodified:docs_src/arguments/help/tutorial003_an_py310.py+1 added-1 removed
6 unmodified lines7 8 @app.command()9 def 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}")14 15 2 unmodified linesmodified:docs_src/arguments/help/tutorial003_py310.py+1 added-1 removed
4 unmodified lines5 6 @app.command()7 def 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}")12 13 2 unmodified linesmodified:docs_src/arguments/help/tutorial004_an_py310.py+1 added-1 removed
10 unmodified lines11 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}")18 19 2 unmodified linesmodified:docs_src/arguments/help/tutorial004_py310.py+1 added-1 removed
4 unmodified lines5 6 @app.command()7 def 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}")12 13 2 unmodified linesmodified:docs_src/arguments/help/tutorial007_an_py310.py+1 added-1 removed
15 unmodified lines16 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}")23 24 2 unmodified linesmodified:docs_src/arguments/help/tutorial007_py310.py+1 added-1 removed
12 unmodified lines13 "", 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}")20 21 2 unmodified linesmodified:docs_src/arguments/help/tutorial008_an_py310.py+1 added-1 removed
6 unmodified lines7 8 @app.command()9 def 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}")14 15 2 unmodified linesmodified:docs_src/arguments/help/tutorial008_py310.py+1 added-1 removed
4 unmodified lines5 6 @app.command()7 def 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}")12 13 2 unmodified linesmodified:docs_src/commands/help/tutorial001_an_py310.py+2 added-2 removed
6 unmodified lines7 8 @app.command()9 def 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}")14 15 8 unmodified lines24 ),25 ],26 ):27 """28- Delete a user with USERNAME.28+ Delete a user with username.29 30 If --force is not used, will ask for confirmation.31 """32 if force:36 unmodified linesmodified:docs_src/commands/help/tutorial001_py310.py+2 added-2 removed
4 unmodified lines5 6 @app.command()7 def 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}")12 13 6 unmodified lines20 help="Force deletion without confirmation.",21 ),22 ):23 """24- Delete a user with USERNAME.24+ Delete a user with username.25 26 If --force is not used, will ask for confirmation.27 """28 if force:34 unmodified linesmodified:docs_src/commands/help/tutorial002_py310.py+2 added-2 removed
1 unmodified line2 3 app = typer.Typer()4 5 6-@app.command(help="Create a new user with USERNAME.")6+@app.command(help="Create a new user with username.")7 def create(username: str):8 """9 Some internal utility function to create.10 """11 print(f"Creating user: {username}")12 13 14-@app.command(help="Delete a user with USERNAME.")14+@app.command(help="Delete a user with username.")15 def delete(username: str):16 """17 Some internal utility function to delete.18 """5 unmodified linesmodified:docs_src/commands/help/tutorial004_an_py310.py+1 added-1 removed
17 unmodified lines18 """19 print(f"Creating user: {username}")20 21 22-@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].")23 def delete(24 username: Annotated[25 str, typer.Argument(help="The username to be [red]deleted[/red]")26 ],12 unmodified linesmodified:docs_src/commands/help/tutorial004_py310.py+1 added-1 removed
15 unmodified lines16 """17 print(f"Creating user: {username}")18 19 20-@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].")21 def 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 linesmodified:docs_src/commands/help/tutorial005_an_py310.py+1 added-1 removed
21 unmodified lines22 """23 print(f"Creating user: {username}")24 25 26-@app.command(help="**Delete** a user with *USERNAME*.")26+@app.command(help="**Delete** a user with *username*.")27 def 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 linesmodified:docs_src/commands/help/tutorial005_py310.py+1 added-1 removed
17 unmodified lines18 """19 print(f"Creating user: {username}")20 21 22-@app.command(help="**Delete** a user with *USERNAME*.")22+@app.command(help="**Delete** a user with *username*.")23 def 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 linesmodified:docs_src/first_steps/tutorial006_py310.py+1 added-1 removed
1 unmodified line2 3 4 def 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.7 8 If --formal is used, say hi very formally.9 """10 if formal:7 unmodified linesmodified:docs_src/options/help/tutorial001_an_py310.py+1 added-1 removed
10 unmodified lines11 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.16 17 If --formal is used, say hi very formally.18 """19 if formal:7 unmodified linesmodified:docs_src/options/help/tutorial001_py310.py+1 added-1 removed
8 unmodified lines9 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.14 15 If --formal is used, say hi very formally.16 """17 if formal:7 unmodified linesmodified:docs_src/options/help/tutorial002_an_py310.py+1 added-1 removed
21 unmodified lines22 ),23 ] = False,24 ):25 """26- Say hi to NAME, optionally with a --lastname.26+ Say hi to 'name', optionally with a --lastname.27 28 If --formal is used, say hi very formally.29 """30 if formal:7 unmodified linesmodified:docs_src/options/help/tutorial002_py310.py+1 added-1 removed
13 unmodified lines14 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.19 20 If --formal is used, say hi very formally.21 """22 if formal:7 unmodified linesmodified:docs_src/parameter_types/number/tutorial001_an_py310.py+2 added-2 removed
5 unmodified lines6 7 8 @app.command()9 def 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}")17 18 2 unmodified linesmodified:docs_src/parameter_types/number/tutorial001_py310.py+2 added-2 removed
3 unmodified lines4 5 6 @app.command()7 def 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}")15 16 2 unmodified linesmodified:docs_src/parameter_types/number/tutorial002_an_py310.py+2 added-2 removed
5 unmodified lines6 7 8 @app.command()9 def 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}")17 18 2 unmodified linesmodified:docs_src/parameter_types/number/tutorial002_py310.py+2 added-2 removed
3 unmodified lines4 5 6 @app.command()7 def 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}")15 16 2 unmodified linesmodified:docs_src/parameter_types/uuid/tutorial001_py310.py+1 added-1 removed
5 unmodified lines6 7 8 @app.command()9 def 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}")12 13 14 if __name__ == "__main__":1 unmodified lineadded:tests/assets/cli/minimum_main.py+8 added
1+import typer2+3+app = typer.Typer()4+5+6+@app.callback()7+def main(name: str) -> None:8+ pass # pragma: no covermodified:tests/assets/cli/multiapp-docs-title.md+4 added-4 removed
63 unmodified lines64 ```65 66 **Options**:67 68-* `--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.71 72 ### `multiapp sub hi`73 1 unmodified line75 76 **Usage**:77 78 ```console79-$ multiapp sub hi [OPTIONS] [USER]79+$ multiapp sub hi [OPTIONS] [user]80 ```81 82 **Arguments**:83 84-* `[USER]`: The name of the user to greet [default: World]84+* `user`: The name of the user to greet [default: World]85 86 **Options**:87 88 * `--help`: Show this message and exit.14 unmodified linesmodified:tests/assets/cli/multiapp-docs.md+4 added-4 removed
63 unmodified lines64 ```65 66 **Options**:67 68-* `--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.71 72 ### `multiapp sub hi`73 1 unmodified line75 76 **Usage**:77 78 ```console79-$ multiapp sub hi [OPTIONS] [USER]79+$ multiapp sub hi [OPTIONS] [user]80 ```81 82 **Arguments**:83 84-* `[USER]`: The name of the user to greet [default: World]84+* `user`: The name of the user to greet [default: World]85 86 **Options**:87 88 * `--help`: Show this message and exit.14 unmodified linesmodified:tests/assets/cli/richformattedapp-docs.md+3 added-3 removed
3 unmodified lines4 5 **Usage**:6 7 ```console8-$ hello [OPTIONS] USER_1 [USER_2]8+$ hello [OPTIONS] {user_1} [user_2]9 ```10 11 **Arguments**:12 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]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]15 16 **Options**:17 18 * `--force / --no-force`: Force the welcome <span style="color: #800000; text-decoration-color: #800000">message</span> [default: no-force]3 unmodified linesmodified:tests/test_cli/test_help.py+16 added-1 removed
119 unmodified lines120 121 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(" ")126 127 128 def test_format_long_help_option() -> None:27 unmodified lines156 assert (157 "Description is rendered in the next line for long option labels."158 in continuation_block159 )160+161+162+def test_typer_run_usage() -> None:163+ from typer.cli import app as typer_cli_app164+165+ result = runner.invoke(166+ typer_cli_app,167+ ["tests/assets/cli/minimum_main.py", "run"],168+ prog_name="typer",169+ )170+171+ 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.outputmodified:tests/test_completion/example_rich_tags.py+2 added-2 removed
4 unmodified lines5 6 @app.command()7 def 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}")12 13 14 @app.command()15 def 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}")20 21 10 unmodified linesmodified:tests/test_completion/test_completion_complete_rich.py+4 added-4 removed
56 unmodified lines57 "_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.stdout64 65 9 unmodified lines75 "_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 )82 83 8 unmodified lines92 "_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.stdout98 99 100 def test_completion_complete_subcommand_pwsh():7 unmodified lines108 "_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.stdoutmodified:tests/test_completion/test_completion_complete.py+4 added-4 removed
65 unmodified lines66 "_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.stdout73 74 25 unmodified lines100 "_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 )107 108 41 unmodified lines150 "_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.stdout156 157 158 def test_completion_complete_subcommand_pwsh(mod: ModuleType):8 unmodified lines167 "_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.stdout173 174 175 def test_completion_complete_subcommand_noshell(mod: ModuleType):12 unmodified linesmodified:tests/test_tutorial/test_arguments/test_default/test_tutorial001.py+1 added-1 removed
23 unmodified lines24 25 def 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.output31 32 19 unmodified linesmodified:tests/test_tutorial/test_arguments/test_default/test_tutorial002.py+1 added-1 removed
23 unmodified lines24 25 def 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.output31 32 21 unmodified linesmodified:tests/test_tutorial/test_arguments/test_envvar/test_tutorial001.py+2 added-2 removed
25 unmodified lines26 27 def 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 line36 def 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 linesmodified:tests/test_tutorial/test_arguments/test_envvar/test_tutorial002.py+1 added-1 removed
23 unmodified lines24 25 def 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 linesmodified:tests/test_tutorial/test_arguments/test_envvar/test_tutorial003.py+1 added-1 removed
23 unmodified lines24 25 def 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 linesmodified:tests/test_tutorial/test_arguments/test_help/test_tutorial001.py+4 added-4 removed
24 unmodified lines25 26 def 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.output34 35 36 def 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.output45 46 13 unmodified linesmodified:tests/test_tutorial/test_arguments/test_help/test_tutorial002.py+3 added-3 removed
23 unmodified lines24 25 def 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.output34 35 13 unmodified linesmodified:tests/test_tutorial/test_arguments/test_help/test_tutorial003.py+3 added-3 removed
23 unmodified lines24 25 def 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.output34 35 13 unmodified linesmodified:tests/test_tutorial/test_arguments/test_help/test_tutorial004.py+3 added-3 removed
23 unmodified lines24 25 def 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.output34 35 13 unmodified linesmodified:tests/test_tutorial/test_arguments/test_help/test_tutorial005.py+1 added-1 removed
23 unmodified lines24 25 def 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 linesmodified:tests/test_tutorial/test_arguments/test_help/test_tutorial007.py+1 added-1 removed
23 unmodified lines24 25 def 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.output31 32 13 unmodified linesmodified:tests/test_tutorial/test_arguments/test_help/test_tutorial008.py+4 added-4 removed
24 unmodified lines25 26 def 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.output33 34 35 def 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.output43 44 13 unmodified linesmodified:tests/test_tutorial/test_arguments/test_optional/test_tutorial000.py+1 added-1 removed
37 unmodified lines38 39 def 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.output43 44 45 def test_script(mod: ModuleType):46 result = subprocess.run(5 unmodified linesmodified:tests/test_tutorial/test_arguments/test_optional/test_tutorial001.py+2 added-2 removed
24 unmodified lines25 26 def 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.output30 31 32 def test_call_no_arg_standalone(mod: ModuleType):33 # Mainly for coverage5 unmodified lines39 # 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.output44 45 46 def test_call_arg(mod: ModuleType):47 result = runner.invoke(mod.app, ["Camila"])11 unmodified linesmodified:tests/test_tutorial/test_arguments/test_optional/test_tutorial002.py+1 added-1 removed
23 unmodified lines24 25 def 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 30 31 def test_call_no_arg(mod: ModuleType):32 result = runner.invoke(mod.app)17 unmodified linesmodified:tests/test_tutorial/test_arguments/test_optional/test_tutorial003.py+2 added-2 removed
13 unmodified lines14 15 def 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.output19 20 21 def test_call_no_arg_standalone():22 # Mainly for coverage5 unmodified lines28 # 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.output33 34 35 def test_call_arg():36 result = runner.invoke(app, ["Camila"])11 unmodified linesmodified:tests/test_tutorial/test_commands/test_arguments/test_tutorial001.py+2 added-2 removed
11 unmodified lines12 13 def 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.output17 18 19 def 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.output23 24 25 def test_create():26 result = runner.invoke(app, ["create", "Camila"])17 unmodified linesmodified:tests/test_tutorial/test_commands/test_help/test_tutorial001.py+6 added-6 removed
25 unmodified lines26 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.output1 unmodified line38 39 def 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.output44 45 46 def 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 linesmodified:tests/test_tutorial/test_commands/test_help/test_tutorial002.py+4 added-4 removed
12 unmodified lines13 def 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.output22 23 24 def 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.output29 30 31 def 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.output36 37 38 def test_create():18 unmodified linesmodified:tests/test_tutorial/test_commands/test_help/test_tutorial004.py+2 added-2 removed
27 unmodified lines28 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.output35 36 7 unmodified lines44 45 def 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 linesmodified:tests/test_tutorial/test_commands/test_help/test_tutorial005.py+2 added-2 removed
27 unmodified lines28 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.output35 36 8 unmodified lines45 46 def 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 linesmodified:tests/test_tutorial/test_commands/test_help/test_tutorial007.py+1 added-1 removed
34 unmodified lines35 36 def 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.output27 unmodified linesmodified:tests/test_tutorial/test_first_steps/test_tutorial002.py+1 added-1 removed
13 unmodified lines14 15 def 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.output19 20 21 def test_2():22 result = runner.invoke(app, ["Camila"])11 unmodified linesmodified:tests/test_tutorial/test_first_steps/test_tutorial003.py+1 added-1 removed
13 unmodified lines14 15 def 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.output19 20 21 def test_2():22 result = runner.invoke(app, ["Camila", "Gutiérrez"])11 unmodified linesmodified:tests/test_tutorial/test_first_steps/test_tutorial004.py+2 added-2 removed
14 unmodified lines15 def 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 linesmodified:tests/test_tutorial/test_first_steps/test_tutorial005.py+2 added-2 removed
14 unmodified lines15 def 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.output25 26 31 unmodified linesmodified:tests/test_tutorial/test_first_steps/test_tutorial006.py+1 added-1 removed
13 unmodified lines14 15 def 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.output20 21 22 def test_1():30 unmodified linesmodified:tests/test_tutorial/test_multiple_values/test_arguments_with_multiple_values/test_tutorial002.py+1 added-1 removed
25 unmodified lines26 27 def 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.output33 34 29 unmodified linesmodified:tests/test_tutorial/test_multiple_values/test_options_with_multiple_values/test_tutorial001.py+3 added
56 unmodified lines57 capture_output=True,58 encoding="utf-8",59 )60 assert "Usage" in result.stdout61+62+ # ensure that also tuple of None's isn't displayed63+ assert "[default: None, None, None]" not in result.stdoutmodified:tests/test_tutorial/test_options/test_help/test_tutorial001.py+1 added-1 removed
23 unmodified lines24 25 def 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 linesmodified:tests/test_tutorial/test_options/test_help/test_tutorial003.py+1 added-1 removed
30 unmodified lines31 def 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.output37 38 39 def test_script(mod: ModuleType):6 unmodified linesmodified:tests/test_tutorial/test_options/test_help/test_tutorial004.py+1 added-1 removed
32 unmodified lines33 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.output39 40 41 def test_script(mod: ModuleType):6 unmodified linesmodified:tests/test_tutorial/test_options/test_name/test_tutorial001.py+1 added-1 removed
24 unmodified lines25 def 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.output31 32 33 def test_call(mod: ModuleType):18 unmodified linesmodified:tests/test_tutorial/test_options/test_name/test_tutorial002.py+1 added-1 removed
25 unmodified lines26 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.output32 33 34 def test_call(mod: ModuleType):18 unmodified linesmodified:tests/test_tutorial/test_options/test_name/test_tutorial003.py+1 added-1 removed
24 unmodified lines25 def 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.output32 33 13 unmodified linesmodified:tests/test_tutorial/test_options/test_name/test_tutorial004.py+1 added-1 removed
25 unmodified lines26 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.output32 33 34 def test_call(mod: ModuleType):18 unmodified linesmodified:tests/test_tutorial/test_options/test_name/test_tutorial005.py+1 added-1 removed
25 unmodified lines26 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.output33 34 30 unmodified linesmodified:tests/test_tutorial/test_options/test_password/test_tutorial001.py+1 added-1 removed
42 unmodified lines43 def 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_spaces48 49 50 def test_script(mod: ModuleType):51 result = subprocess.run(5 unmodified linesmodified:tests/test_tutorial/test_options/test_password/test_tutorial002.py+1 added-1 removed
46 unmodified lines47 def 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_spaces52 53 54 def test_script(mod: ModuleType):55 result = subprocess.run(5 unmodified linesmodified:tests/test_tutorial/test_options/test_prompt/test_tutorial001.py+1 added-1 removed
37 unmodified lines38 def 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.output44 45 46 def test_script(mod: ModuleType):6 unmodified linesmodified:tests/test_tutorial/test_options/test_prompt/test_tutorial002.py+1 added-1 removed
37 unmodified lines38 def 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.output44 45 46 def test_script(mod: ModuleType):6 unmodified linesmodified:tests/test_tutorial/test_options/test_prompt/test_tutorial003.py+1 added-1 removed
46 unmodified lines47 def 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.output53 54 55 def test_script(mod: ModuleType):6 unmodified linesmodified:tests/test_tutorial/test_options/test_required/test_tutorial001_tutorial002.py+2 added-2 removed
39 unmodified lines40 def 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.output46 47 48 def 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.output55 56 57 def test_script(mod: ModuleType):6 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_datetime/test_tutorial001.py+2 added-5 removed
18 unmodified lines19 20 def 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.output24 25 26 def test_main():27 result = runner.invoke(app, ["1956-01-31T10:00:00"])13 unmodified lines41 42 def 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.output9 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py+1 added-1 removed
11 unmodified lines12 def 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.output18 19 20 def test_main():38 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_enum/test_tutorial003.py+1 added-1 removed
24 unmodified lines25 def 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.output31 32 33 def test_call_no_arg(mod: ModuleType):24 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_enum/test_tutorial004.py+1 added-1 removed
23 unmodified lines24 25 def 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(" ", "")29 30 31 def test_main(mod):32 result = runner.invoke(mod.app, ["--network", "conv"])24 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_index/test_tutorial001.py+3 added-3 removed
22 unmodified lines23 def 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.output30 31 32 def test_params():33 result = runner.invoke(9 unmodified lines43 def 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.output48 49 50 def test_script():51 result = subprocess.run(5 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_number/test_tutorial001.py+5 added-5 removed
25 unmodified lines26 27 def test_type_repr(mod: ModuleType):28 command = typer.main.get_command(mod.app)29 30- 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>"32 33 age_param = next(param for param in command.params if param.name == "age")34 assert repr(age_param.type) == "<IntRange x>=18>"5 unmodified lines40 def 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.output47 48 49 def 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.output57 58 59 def test_params(mod: ModuleType):60 result = runner.invoke(mod.app, ["5", "--age", "20", "--score", "90"])44 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_uuid/test_tutorial001.py+4 added-6 removed
18 unmodified lines19 20 def 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.output25 26 27 def 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.output33 34 35 def 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.output40 41 42 def test_script():43 result = subprocess.run(5 unmodified linesmodified:tests/test_tutorial/test_typer_app/test_tutorial001.py+1 added-1 removed
11 unmodified lines12 13 def 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.output17 18 19 def test_arg():20 result = runner.invoke(app, ["Camila"])11 unmodified linesmodified:tests/test_core.py+61 added-1 removed
23 unmodified lines24 25 command = typer.main.get_command(app)26 params = {param.name: param for param in command.params}27 28- 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"31 32 343 unmodified lines376 377 result = runner.invoke(app, [], default_map={"names": "not-a-list"})378 assert result.exit_code == 2379 assert "Invalid value" in result.output380+381+382+def test_parameter_name_casing():383+ app = typer.Typer()384+385+ @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+ )401+402+ 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+ )425+426+ 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+ )432+433+ 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.output436+437+ 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.outputmodified:tests/test_others.py+2 added-1 removed
448 unmodified lines449 print(f"arg5: {type(arg5)} {arg5}")450 451 result = runner.invoke(app, ["Hello", "2", "invalid"])452 453- 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.stdout30 unmodified linesmodified:tests/test_prog_name.py+1 added-1 removed
8 unmodified lines9 [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.stdoutmodified:tests/test_rich_markup_mode.py+1 added-1 removed
23 unmodified lines24 result = runner.invoke(app, ["World"])25 assert "Hello World" in result.stdout26 27 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)30 31 32 def test_rich_markup_mode_rich():300 unmodified linesmodified:tests/test_rich_utils.py+48 added-13 removed
99 unmodified lines100 pass # pragma: no cover101 102 result = runner.invoke(app, ["--help"])103 assert "Usage" in result.stdout104- assert "BAR" in result.stdout104+ assert "{bar}" in result.stdout105 106 107 @needs_rich108 @pytest.mark.parametrize("input_text", ["[ARGS]", "[ARGS]..."])114 unmodified lines223 f"Right boundaries not aligned: A={pos_a}, B={pos_b}, C={pos_c}"224 )225 226 227+def test_rich_help_no_boolean_type() -> None:228+ app = typer.Typer(rich_markup_mode="rich")229+230+ @app.command()231+ def main(name: str) -> None:232+ pass # pragma: no cover233+234+ result = runner.invoke(app, ["--help"])235+ assert result.exit_code == 0236+ assert "<boolean>" not in result.output237+238+239 def test_rich_help_metavar():240 app = typer.Typer(rich_markup_mode="rich")241 242 @app.command()1 unmodified line244 *,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 cover256 257 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+ )262 263 out_nospace = result.stdout.replace(" ", "")264 265 # 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_nospace272 273 assert "arg7" not in result.stdout.lower()274 assert "arg8" not in result.stdout275 assert "ARG9" not in result.stdout276 277 # 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_nospace281+282+283+def 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")286+287+ @app.callback()288+ def main(path_or_module: str = typer.Argument(None)) -> None:289+ pass # pragma: no cover290+291+ @app.command()292+ def run(name: str) -> None:293+ pass # pragma: no cover294+295+ result = runner.invoke(app, ["my-module.py", "run"], prog_name="typer")296+297+ 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.outputmodified:tests/test_type_conversion.py+64 added-1 removed
1 import os2+from datetime import datetime3 from enum import Enum4 from pathlib import Path4-from typing import Any5+from typing import Annotated, Any, Literal6 7 import pytest8 import typer9 from typer import _click, models388 unmodified lines398 monkeypatch.setattr(sys, "getfilesystemencoding", lambda: filesystem_encoding)399 400 converted = _click.types.STRING.convert(b"\xff", None, None)401 assert converted == "ÿ"402+403+404+@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+)432+def test_param_type_help_metavar(parameter: Any, expected_metavar: str) -> None:433+ app = typer.Typer()434+435+ @app.command()436+ # TODO: type-specific default437+ def with_default(value: parameter = "my_default"):438+ pass # pragma: no cover439+440+ @app.command()441+ def without_default(value: parameter):442+ pass # pragma: no cover443+444+ result = runner.invoke(app, ["with-default", "--help"])445+ assert result.exit_code == 0446+ assert expected_metavar in result.output447+448+ result = runner.invoke(app, ["without-default", "--help"])449+ assert result.exit_code == 0450+ assert expected_metavar in result.output451+452+453+def test_metavar_preformatted_square_brackets() -> None:454+ app = typer.Typer()455+456+ @app.command()457+ def main(value: Annotated[str, typer.Argument(metavar="[VALUE]")]):458+ pass # pragma: no cover459+460+ result = runner.invoke(app, ["--help"])461+ assert result.exit_code == 0462+ assert "[VALUE]" in result.output463+ assert "[[VALUE]]" not in result.outputmodified:tests/test_types.py+2 added-2 removed
91 unmodified lines92 93 def 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.output97 98 result = runner.invoke(app, ["hello-option", "--help"])99 assert result.exit_code == 0100- assert "[rick|morty]" in result.output100+ assert "<rick|morty>" in result.output101 102 result = runner.invoke(app, ["hello-no-choices", "--help"])103 assert result.exit_code == 0104 assert "--name" in result.output61 unmodified linesmodified:typer/_click/core.py+5 added-1 removed
883 unmodified lines884 885 metavar = self.type.get_metavar(param=self, ctx=ctx)886 887 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}>"893 894 if self.nargs != 1:895 metavar += "..."896 219 unmodified linesmodified:typer/_click/types.py+4 added-4 removed
140 unmodified lines141 self.fail(value, param, ctx)142 143 144 class StringParamType(ParamType):145- name = "text"145+ name = "str"146 147 def convert(148 self, value: Any, param: Union["Parameter", None], ctx: Union["Context", None]149 ) -> Any:42 unmodified lines192 "%Y-%m-%d %H:%M:%S",193 ]194 195 def get_metavar(self, param: "Parameter", ctx: "Context") -> str | None:196- return f"[{'|'.join(self.formats)}]"196+ return f"<{'|'.join(self.formats)}>"197 198 def _try_to_convert_date(self, value: Any, format: str) -> datetime | None:199 try:200 return datetime.strptime(value, format)108 unmodified lines309 return f"<{type(self).__name__} {self._describe_range()}{clamp}>"310 311 312 class IntParamType(_NumberParamTypeBase):313- name = "integer"313+ name = "int"314 _number_class = int315 316 def __repr__(self) -> str:317 return "INT"9 unmodified lines327 If ``clamp`` is enabled, a value outside the range is clamped to the328 boundary instead of failing.329 """330 331- name = "integer range"331+ name = "int range"332 333 def _clamp( # type: ignore334 self, bound: int, dir: Literal[1, -1], open: bool335 ) -> int:360 unmodified linesmodified:typer/.agents/skills/typer/SKILL.md+2 added-2 removed
238 unmodified lines239 """240 print(f"Creating user: {username}")241 242 243-@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].")244 def delete(245 username: Annotated[246 str, typer.Argument(help="The username to be [red]deleted[/red]")247 ],20 unmodified lines268 import typer269 270 app = typer.Typer(rich_markup_mode="markdown")271 272-@app.command(help="**Delete** a user with *USERNAME*.")272+@app.command(help="**Delete** a user with *username*.")273 def delete(274 username: Annotated[str, typer.Argument(help="The username to be **deleted** :boom:")]275 ):276 print(f"Deleting user: {username}")12 unmodified linesmodified:typer/_types.py+3 added-7 removed
48 unmodified lines49 50 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 )60 61- # 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}>"63 65- # Use square braces to indicate an option or optional argument.66- return f"[{choices_str}]"67-64 def get_missing_message(65 self, param: _click.Parameter, ctx: _click.Context | None66 ) -> str:67 """Message shown when no choice is passed."""49 unmodified linesmodified:typer/cli.py+1 added-1 removed
159 unmodified lines160 @app.callback(cls=TyperCLIGroup, no_args_is_help=True)161 def 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 linesmodified:typer/core.py+23 added-13 removed
91 unmodified lines92 # 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 lines128 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 lines308 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.name313 314 def _get_default_string(315 self,316 *,68 unmodified lines385 386 help = f"{help} {extra_str}" if help else f"{extra_str}"387 return name, help388 383- 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 lines419 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], []430 431 def get_usage_pieces(self, ctx: _click.Context) -> list[str]:422- return [self.make_metavar(ctx)]432+ return [self.make_metavar(ctx, usage=True)]433 434 def get_error_hint(self, ctx: _click.Context) -> str:425- return f"'{self.make_metavar(ctx)}'"435+ return f"'{self.human_readable_name}'"436 437 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 lines584 opts.append(decl)585 586 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 = None591 592 return name, opts, secondary_opts635 unmodified linesmodified:typer/main.py+12 added-1 removed
1359 unmodified lines1360 def get_command_name(name: str) -> str:1361 return name.lower().replace("_", "-")1362 1363 1364+def 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_name1371+1372+1373 def 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 lines1707 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 linesmodified:typer/rich_utils.py+11 added-11 removed
368 unmodified lines369 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}>"383 384 for opt_str in param.opts:385 if "--" in opt_str:386 opt_long_strs.append(opt_str)12 unmodified lines399 # Column for recording the type400 types_data = Text(style=STYLE_TYPES, overflow="fold")401 402 # 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)405 406 # Range - from407 # https://github.com/pallets/click/blob/c63c70dabd3f86ca68678b4f00951f78f52d0270/src/click/core.py#L2698-L2706 # noqa: E501408 # skip count with default range type293 unmodified lines702 703 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)707 708 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 linesmodified:README.md+18 added-18 removed
76 unmodified lines77 ```console78 // Run your application79 $ typer main.py run80 81-// You get a nice error, you are missing NAME82-Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME81+// You get a nice error, you are missing 'name'82+Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}83 Try 'typer [PATH_OR_MODULE] run --help' for help.84 ╭─ Error ───────────────────────────────────────────╮85-│ Missing argument 'NAME'. │85+│ Missing argument 'name'. │86 ╰───────────────────────────────────────────────────╯87 88 89 // You get a --help for free90 $ typer main.py run --help91 92-Usage: typer [PATH_OR_MODULE] run [OPTIONS] NAME92+Usage: typer [PATH_OR_MODULE] run [OPTIONS] {name}93 94 Run the provided Typer app.95 96 ╭─ Arguments ───────────────────────────────────────╮97-│ * name TEXT [default: None] [required] |97+│ * name <str> [required] │98 ╰───────────────────────────────────────────────────╯99 ╭─ Options ─────────────────────────────────────────╮100 │ --help Show this message and exit. │101 ╰───────────────────────────────────────────────────╯102 103-// Now pass the NAME argument103+// Now pass the 'name' argument104 $ typer main.py run Camila105 106 Hello Camila107 29 unmodified lines137 ```console138 // Run your application139 $ python main.py140 141-// You get a nice error, you are missing NAME142-Usage: main.py [OPTIONS] NAME141+// You get a nice error, you are missing 'name'142+Usage: main.py [OPTIONS] {name}143 Try 'main.py --help' for help.144 ╭─ Error ───────────────────────────────────────────╮145-│ Missing argument 'NAME'. │145+│ Missing argument 'name'. │146 ╰───────────────────────────────────────────────────╯147 148 149 // You get a --help for free150 $ python main.py --help151 152-Usage: main.py [OPTIONS] NAME152+Usage: main.py [OPTIONS] {name}153 154 ╭─ Arguments ───────────────────────────────────────╮155-│ * name TEXT [default: None] [required] |155+│ * name <str> [required] │156 ╰───────────────────────────────────────────────────╯157 ╭─ Options ─────────────────────────────────────────╮158 │ --help Show this message and exit. │159 ╰───────────────────────────────────────────────────╯160 161-// Now pass the NAME argument161+// Now pass the 'name' argument162 $ python main.py Camila163 164 Hello Camila165 69 unmodified lines235 │ --help Show this message │236 │ and exit. │237 ╰───────────────────────────────────────────────────╯238 ╭─ Commands ────────────────────────────────────────╮239-│ goodbye │239 │ hello │240+│ goodbye │241 ╰───────────────────────────────────────────────────╯242 243 // When you create a package you get ✨ auto-completion ✨ for free, installed with --install-completion244 245-// You have 2 subcommands (the 2 functions): goodbye and hello245+// You have 2 subcommands (the 2 functions): hello and goodbye246 ```247 248 </div>249 3 unmodified lines253 254 ```console255 $ python main.py hello --help256 257- Usage: main.py hello [OPTIONS] NAME257+ Usage: main.py hello [OPTIONS] {name}258 259 ╭─ Arguments ───────────────────────────────────────╮260-│ * name TEXT [default: None] [required] │260+│ * name <str> [required] │261 ╰───────────────────────────────────────────────────╯262 ╭─ Options ─────────────────────────────────────────╮263 │ --help Show this message and exit. │264 ╰───────────────────────────────────────────────────╯7 unmodified lines272 273 ```console274 $ python main.py goodbye --help275 276- Usage: main.py goodbye [OPTIONS] NAME276+ Usage: main.py goodbye [OPTIONS] {name}277 278 ╭─ 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