sh_cpl/src/cpl_cli/cli.py

31 lines
1.1 KiB
Python
Raw Normal View History

2021-03-03 19:37:35 +01:00
from typing import Optional
2021-03-03 18:37:54 +01:00
from cpl.application.application_abc import ApplicationABC
from cpl.console.console import Console
2021-03-03 19:37:35 +01:00
from cpl_cli.command import Command
from cpl_cli.command_handler import CommandHandler
from cpl_cli.commands.help import Help
from cpl_cli.commands.version import Version
2021-03-03 18:37:54 +01:00
class CLI(ApplicationABC):
def __init__(self):
ApplicationABC.__init__(self)
2021-03-03 19:37:35 +01:00
self._command_handler: Optional[CommandHandler] = None
2021-03-03 18:37:54 +01:00
def configure(self):
2021-03-03 19:37:35 +01:00
self._command_handler: CommandHandler = self._services.get_service(CommandHandler)
2021-03-03 18:37:54 +01:00
2021-03-03 19:37:35 +01:00
self._command_handler.add_command(Command('help', ['h', 'H'], self._services.get_service(Help)))
self._command_handler.add_command(Command('version', ['v', 'V'], self._services.get_service(Version)))
2021-03-03 18:37:54 +01:00
def main(self):
2021-03-03 19:37:35 +01:00
if len(self._configuration.additional_arguments) < 1:
Console.error(f'Expected command')
Console.error('Run \'cpl help\'')
return
self._command_handler.handle(self._configuration.additional_arguments[0], self._configuration.additional_arguments[1:])