avatar Bite 356. Using Typer Callbacks to Create Command Line Interface (CLI) Parameters

In the previous Bite you have created your first simple Typer application with several commands.

You might have asked yourself, "How do I create arguments or options that are initialized once and can be used by several commands?". Without a feature like that, one could potentially have lots of redundant code that initializes the same arguments and options for multiple commands.

Luckily, Typer Callback serves exactly this purpose.

In this Bite, you will implement a simple Typer Callback, to get familiar with the concept.

Let's add a verbosity option such that the commands can return a less verbose output by default.

Check out the tests for more information about what output is expected.

Enjoy!

Login and get coding
go back Intermediate level
Bitecoin 3X

7 out of 7 users completed this Bite.
Will you be Pythonista #8 to crack this Bite?
Resolution time: ~21 min. (avg. submissions of 5-240 min.)

Focus on this Bite hiding sidebars, turn on Focus Mode.
We use Python 3.8