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

18 out of 18 users completed this Bite.
Will you be the 19th person to crack this Bite?
Resolution time: ~40 min. (avg. submissions of 5-240 min.)

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help