First check
Description
I am just getting started with the library Typer for building CLI's. I apologize in advance if this issue has been raised more than once, but I could not find it on Google to help me with the correct implementation.
There are too many commands in my cli.py and I want to moved them to a separate folder “commands”, but I cannot figure out how to implement a dynamic loader for these commands in cli.py.
my_app/
__init__.py
commands/
__init__.py
command1.py
command2.py
cli.py
I want start by creating a class "Command" for each command with a single function "handle (**options)" that contains the functionality. But I am not sure if I am forming the class correctly. I want to make a class "AsyncCommand" because the command can be complex and can be properly decomposed into methods and encapsulated within one class
# a_test_command.py
from typer.core import TyperCommand
class AsyncCommand(TyperCommand):
@staticmethod
async def handle('a-test-command'):
print('test_command')
Ideally, when starting cli.py, I want to check which modules are there and load them dynamically, leaving the cli.py file clean. But I do not understand at all how it is better and more correct to implement it.
First check
Description
I am just getting started with the library Typer for building CLI's. I apologize in advance if this issue has been raised more than once, but I could not find it on Google to help me with the correct implementation.
There are too many commands in my cli.py and I want to moved them to a separate folder “commands”, but I cannot figure out how to implement a dynamic loader for these commands in cli.py.
I want start by creating a class "Command" for each command with a single function "handle (**options)" that contains the functionality. But I am not sure if I am forming the class correctly. I want to make a class "AsyncCommand" because the command can be complex and can be properly decomposed into methods and encapsulated within one class
Ideally, when starting cli.py, I want to check which modules are there and load them dynamically, leaving the cli.py file clean. But I do not understand at all how it is better and more correct to implement it.