Skip to content

Commit 28f7d36

Browse files
committed
📝 Tweak docs and example for setting help and name
1 parent ff6a3ef commit 28f7d36

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Commands:
4848

4949
</div>
5050

51-
We can set the `name` and `help` in several places, each one taking precedence over the other, overriding the previous value.
51+
We can set the `help` in several places, each one taking precedence over the other, overriding the previous value.
5252

5353
Let's see those locations.
5454

@@ -129,7 +129,7 @@ Commands:
129129

130130
/// note
131131

132-
Until Typer 0.14.0, in addition to the help text, the command name was also inferred from the callback function name, this is no longer the case.
132+
Before Typer 0.14.0, in addition to the help text, the command name was also inferred from the callback function name, this is no longer the case.
133133

134134
///
135135

@@ -291,7 +291,7 @@ Let's now see the places where you can set the command name and help text, from
291291

292292
/// tip
293293

294-
Setting the name and help text explicitly always has a higher precedence than inferring from a callback function.
294+
Setting the help text explicitly always has a higher precedence than inferring from a callback function.
295295

296296
///
297297

@@ -311,7 +311,7 @@ The rest of the callbacks and overrides are there only to show you that they don
311311

312312
///
313313

314-
We set an explicit name `exp-users`, and an explicit help `Explicit help.`.
314+
We set an explicit help `Explicit help.`.
315315

316316
So that will take precedence now.
317317

@@ -353,13 +353,13 @@ Commands:
353353

354354
### Help text in `@app.callback()`
355355

356-
Any parameter that you use when creating a `typer.Typer()` app can be overridden in the parameters of `@app.callback()`.
356+
Many parameters that you use when creating a `typer.Typer()` app can be overridden in the parameters of `@app.callback()`.
357357

358-
Continuing with the previous example, we now override the values in `@user_app.callback()`:
358+
Continuing with the previous example, we now override the `help` in `@user_app.callback()`:
359359

360360
{* docs_src/subcommands/name_help/tutorial007.py hl[24] *}
361361

362-
And now the command name will be `call-users` and the help text will be `Help from callback for users.`.
362+
And now the help text will be `Help from callback for users.`.
363363

364364
Check it:
365365

@@ -369,7 +369,7 @@ Check it:
369369
// Check the help
370370
$ python main.py --help
371371

372-
// The command name now is call-users and the help text is "Help from callback for users.".
372+
// The help text is now "Help from callback for users.".
373373
Usage: main.py [OPTIONS] COMMAND [ARGS]...
374374

375375
Options:
@@ -378,13 +378,13 @@ Options:
378378
--help Show this message and exit.
379379

380380
Commands:
381-
call-users Help from callback for users.
381+
users Help from callback for users.
382382

383-
// Check the call-users command help
384-
$ python main.py call-users --help
383+
// Check the users command help
384+
$ python main.py users --help
385385

386386
// Notice the main help text
387-
Usage: main.py call-users [OPTIONS] COMMAND [ARGS]...
387+
Usage: main.py users [OPTIONS] COMMAND [ARGS]...
388388

389389
Help from callback for users.
390390

@@ -443,12 +443,17 @@ Commands:
443443

444444
## Recap
445445

446-
The precedence to generate a command's name and help, from lowest priority to highest, is:
446+
The precedence to generate a command's **help**, from lowest priority to highest, is:
447+
448+
* Implicitly inferred from `sub_app = typer.Typer(callback=some_function)`
449+
* Implicitly inferred from the callback function under `@sub_app.callback()`
450+
* Implicitly inferred from `app.add_typer(sub_app, callback=some_function)`
451+
* Explicitly set on `sub_app = typer.Typer(help="Some help.")`
452+
* Explicitly set on `app.add_typer(sub_app, help="Some help.")`
453+
454+
And the priority to set the command's **name**, from lowest priority to highest, is:
447455

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)
451-
* Explicitly set on `sub_app = typer.Typer(name="some-name", help="Some help.")`
452-
* Explicitly set on `app.add_typer(sub_app, name="some-name", help="Some help.")`
456+
* Explicitly set on `sub_app = typer.Typer(name="some-name")`
457+
* Explicitly set on `app.add_typer(sub_app, name="some-name")`
453458

454459
So, `app.add_typer(sub_app, name="some-name", help="Some help.")` always wins.

docs_src/subcommands/name_help/tutorial007.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def old_callback():
99
"""
1010

1111

12-
users_app = typer.Typer(callback=old_callback, name="exp-users", help="Explicit help.")
12+
users_app = typer.Typer(callback=old_callback, name="users", help="Explicit help.")
1313

1414

1515
def new_users():
@@ -18,7 +18,7 @@ def new_users():
1818
"""
1919

2020

21-
app.add_typer(users_app, callback=new_users, name="users")
21+
app.add_typer(users_app, callback=new_users)
2222

2323

2424
@users_app.callback(help="Help from callback for users.")

0 commit comments

Comments
 (0)