You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this case, the *CLI argument*`name` will have a default value of `"World"`, but will also read any value passed to the environment variable `AWESOME_NAME` if no value is provided in the command line:
16
16
@@ -55,7 +55,7 @@ Hello Mr. Czernobog
55
55
56
56
You are not restricted to a single environment variable, you can declare a list of environment variables that could be used to get a value if it was not passed in the command line:
And it will be used in the automatic `--help` option:
18
18
@@ -37,7 +37,7 @@ Options:
37
37
38
38
And of course, you can also combine that `help` with the <abbrtitle="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>:
@@ -161,7 +161,7 @@ But you can customize it with the `metavar` parameter for `typer.Argument()`.
161
161
162
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:
Now the generated help text will have `✨username✨` instead of `NAME`:
167
167
@@ -187,7 +187,7 @@ You might want to show the help information for *CLI arguments* in different pan
187
187
188
188
If you have installed Rich as described in the docs for [Printing and Colors](../printing.md){.internal-link target=_blank}, you can set the `rich_help_panel` parameter to the name of the panel where you want this *CLI argument* to be shown:
Then, if you check the `--help` option, you will see a default panel named "`Arguments`" for the *CLI arguments* that don't have a custom `rich_help_panel`.
193
193
@@ -230,7 +230,7 @@ If you want, you can make a *CLI argument* **not** show up in the `Arguments` se
230
230
231
231
You will probably not want to do this normally, but it's possible:
Because the first parameter passed to `typer.Argument(default="World")` (the new "default" value) is `"World"`, **Typer** knows that this is an **optional***CLI argument*, if no value is provided when calling it in the command line, it will have that default value of `"World"`.
@@ -92,7 +92,7 @@ You will also see how to use "Callbacks" later, and those include a way to add t
92
92
93
93
You will probably be better adding the help text as a docstring to your functions, but if for some reason you wanted to overwrite it, you can use the `help` function argument passed to `@app.command()`:
As of version 0.20.0, Typer added support for suggesting mistyped command names. This feature is **enabled by default**, but you can disable it with the parameter `suggest_commands=False`:
If a user mistypes a command, they'll see a helpful suggestion:
186
186
@@ -215,7 +215,7 @@ Alternatively, you can disable it globally using an environmental variable `TYPE
215
215
216
216
If you set `rich_markup_mode="rich"` when creating the `typer.Typer()` app (which is the default), you will be able to use <ahref="https://rich.readthedocs.io/en/stable/markup.html"class="external-link"target="_blank">Rich Console Markup</a> in the docstring, and even in the help for the *CLI arguments* and options:
With that, you can use <ahref="https://rich.readthedocs.io/en/stable/markup.html"class="external-link"target="_blank">Rich Console Markup</a> to format the text in the docstring for the command `create`, make the word "`create`" bold and green, and even use an <ahref="https://rich.readthedocs.io/en/stable/markup.html#emoji"class="external-link"target="_blank">emoji</a>.
With that, you can use Markdown to format the text in the docstring for the command `create`, make the word "`create`" bold, show a list of items, and even use an <ahref="https://rich.readthedocs.io/en/stable/markup.html#emoji"class="external-link"target="_blank">emoji</a>.
284
284
@@ -354,7 +354,7 @@ If you installed <a href="https://rich.readthedocs.io/" class="external-link" ta
354
354
355
355
To set the panel for a command you can pass the argument `rich_help_panel` with the name of the panel you want to use:
0 commit comments