Skip to content

Commit 08552ee

Browse files
committed
Update docs
1 parent d55f9e9 commit 08552ee

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

docs/tutorial/subcommands/name-and-help.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ app.add_typer(users.app, name="users")
1010

1111
## Add a help text
1212

13-
We can also set the `help` while adding a Typer:
13+
We can also set the `help` text while adding a Typer:
1414

1515
{* docs_src/subcommands/name_help/tutorial001.py hl[6] *}
1616

@@ -60,9 +60,9 @@ But those are documented later in another section.
6060

6161
///
6262

63-
## Inferring name and help from callback
63+
## Inferring help text from callback
6464

65-
### Inferring a command's name and help
65+
### Inferring a command's help text
6666

6767
When you create a command with `@app.command()`, by default, it generates the name from the function name.
6868

@@ -81,13 +81,13 @@ def create(item: str):
8181

8282
...will create a command `create` with a help text of `Create an item`.
8383

84-
### Inferring help from `@app.callback()`
84+
### Inferring the help text from `@app.callback()`
8585

8686
The same way, if you define a callback in a `typer.Typer()`, the help text is extracted from the callback function's docstring.
8787

8888
Here's an example:
8989

90-
{* docs_src/subcommands/name_help/tutorial002.py hl[6,9,10,11,12,13] *}
90+
{* docs_src/subcommands/name_help/tutorial002.py hl[9,10,11,12,13] *}
9191

9292
The help text for that command will be the callback function's docstring: `Manage users in the app.`.
9393

@@ -127,6 +127,12 @@ Commands:
127127

128128
</div>
129129

130+
/// note
131+
132+
In previous versions of Typer, in addition to the help text, the command name was also inferred from the callback function name, this is no longer the case.
133+
134+
///
135+
130136
### Help from callback parameter in `typer.Typer()`
131137

132138
If you pass a `callback` parameter while creating a `typer.Typer(callback=some_function)` it will be used to infer the help text.
@@ -277,7 +283,7 @@ So, when inferring help text, the precedence order from lowest priority to highe
277283

278284
That's for inferring the help text from functions.
279285

280-
But if you set the name and help text explicitly, that has a higher priority than these.
286+
But if you set the help text explicitly, that has a higher priority than these.
281287

282288
## Set the name and help
283289

@@ -345,7 +351,7 @@ Commands:
345351

346352
</div>
347353

348-
### Name and help in `@app.callback()`
354+
### Help text in `@app.callback()`
349355

350356
Any parameter that you use when creating a `typer.Typer()` app can be overridden in the parameters of `@app.callback()`.
351357

@@ -439,9 +445,9 @@ Commands:
439445

440446
The precedence to generate a command's name and help, from lowest priority to highest, is:
441447

442-
* Implicitly inferred from `sub_app = typer.Typer(callback=some_function)`
443-
* Implicitly inferred from the callback function under `@sub_app.callback()`
444-
* Implicitly inferred from `app.add_typer(sub_app, callback=some_function)`
448+
* Implicitly inferred from `sub_app = typer.Typer(callback=some_function)` (only the help text)
449+
* Implicitly inferred from the callback function under `@sub_app.callback()` (only the help text)
450+
* Implicitly inferred from `app.add_typer(sub_app, callback=some_function)` (only the help text)
445451
* Explicitly set on `sub_app = typer.Typer(name="some-name", help="Some help.")`
446452
* Explicitly set on `@sub_app.callback("some-name", help="Some help.")`
447453
* Explicitly set on `app.add_typer(sub_app, name="some-name", help="Some help.")`

docs_src/subcommands/name_help/tutorial007.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def new_users():
2121
app.add_typer(users_app, callback=new_users)
2222

2323

24+
# TODO: do we want this to work?
2425
@users_app.callback("call-users", help="Help from callback for users.")
2526
def users():
2627
"""

0 commit comments

Comments
 (0)