This is answer to question from typer issue 261.
poetry install
pip install -r requirements.txt
Given name of the module something_click_else
:
python -m something_click_else
python -m typer_example
Example from this post with additions to make the script able to execute.
python -m click_example
- AbstractBaseClass that uses static methods to declare commands.
- Wrapper around
app.commmand()(lambda x: "my function")
python -m click_to_typer
- Usage of
self
attribute to expose some data.
python -m config_click_to_typer
- registering two typers.
python -m click_to_many_typers
- registering two typers.
- extract PapaTyper to avoid import conflicts.
- extending
classic
with custom static methods. - extending
angry
command with usage ofself
and typercontext
. - Add subcommand group
sub
forangry
command. - Helper for registering commands.
python -m many_typers_extended
- This extends
click_to_many_typers
. - Have in mind this example has a bug and does not work correctly.
- This uses
typer.app
as class variable. It is created when class is declared. Creatingself. app
in__init__
createsapp
for each instance of the class in the opposition to this example, whereapp
is created once for all class instances.
import typer
import abc
class BaseModule(abc.ABC):
app = typer.Typer()
The behaviour is incorrect: angry
commands are overwritten by classic
command. To check run:
python -m instance_app classic hello Mike
python -m instance_app angry hello Mike
You can see the message is the same. YourModule
overwritten behaviour described in AngryModule
python -m instance_app
- Modified code from original question to the state the user goes through designed path.
python -m typer_example