sh_cpl/src/cpl_cli/command_handler.py

25 lines
724 B
Python
Raw Normal View History

2021-03-04 07:18:36 +01:00
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
2021-03-03 19:37:35 +01:00
from cpl.dependency_injection.service_abc import ServiceABC
from cpl_cli.command import Command
class CommandHandler(ServiceABC):
2021-03-04 07:18:36 +01:00
def __init__(self, runtime: ApplicationRuntimeABC):
2021-03-03 19:37:35 +01:00
ServiceABC.__init__(self)
2021-03-04 07:18:36 +01:00
self._runtime = runtime
2021-03-03 19:37:35 +01:00
self._commands: list[Command] = []
def add_command(self, cmd: Command):
self._commands.append(cmd)
def remove_command(self, cmd: Command):
self._commands.remove(cmd)
def handle(self, cmd: str, args: list[str]):
for command in self._commands:
if cmd == command.name or cmd in command.aliases:
command.command.run(args)