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>:
@@ -169,7 +169,7 @@ But you can customize it with the `metavar` parameter for `typer.Argument()`.
169
169
170
170
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`:
175
175
@@ -195,7 +195,7 @@ You might want to show the help information for *CLI arguments* in different pan
195
195
196
196
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`.
201
201
@@ -238,7 +238,7 @@ If you want, you can make a *CLI argument* **not** show up in the `Arguments` se
238
238
239
239
You will probably not want to do this normally, but it's possible:
Because the first parameter passed to `typer.Argument(default=None)` (the new "default" value) is `None`, **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 `None`.
224
+
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"`.
222
225
223
226
The `default` argument is the first one, so it's possible that you see code that passes the value without explicitly using `default=`, like:
...but again, try to use `Annotated` if possible, that way your code in terms of Python will mean the same thing as with **Typer** and you won't have to remember any of these details.
Copy file name to clipboardExpand all lines: docs/tutorial/commands/index.md
+1-119Lines changed: 1 addition & 119 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,127 +46,9 @@ Have that in mind so you don't get confused.
46
46
47
47
Here I'll use **CLI application** or **program** to refer to the program you are building in Python with Typer, and **command** to refer to one of these "subcommands" of your program.
48
48
49
-
## Explicit application
50
-
51
-
Before creating CLI applications with multiple commands/subcommands we need to understand how to create an explicit `typer.Typer()` application.
52
-
53
-
In the *CLI options* and *CLI argument* tutorials you have seen how to create a single function and then pass that function to `typer.run()`.
54
-
55
-
For example:
56
-
57
-
{* docs_src/first_steps/tutorial002.py hl[9]*}
58
-
59
-
But that is actually a shortcut. Under the hood, **Typer** converts that to a CLI application with `typer.Typer()` and executes it. All that inside of `typer.run()`.
60
-
61
-
There's also a more explicit way to achieve the same:
0 commit comments