sh_cpl/src/cpl_cli/cli.py

34 lines
1.3 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
2021-03-04 19:06:53 +01:00
from cpl_cli.command.build import Build
2021-03-08 20:29:08 +01:00
from cpl_cli.command.publish import Publish
2021-03-03 19:37:35 +01:00
from cpl_cli.command_handler import CommandHandler
2021-03-04 19:06:53 +01:00
from cpl_cli.command_model import CommandModel
2021-03-04 06:42:40 +01:00
from cpl_cli.error import Error
2021-03-04 19:06:53 +01:00
from cpl_cli.command.help import Help
from cpl_cli.command.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-08 22:29:28 +01:00
self._command_handler.add_command(CommandModel('build', ['h', 'B'], Build, True))
self._command_handler.add_command(CommandModel('help', ['h', 'H'], Help, False))
self._command_handler.add_command(CommandModel('publish', ['p', 'P'], Publish, True))
self._command_handler.add_command(CommandModel('version', ['v', 'V'], Version, False))
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:
2021-03-04 06:42:40 +01:00
Error.error(f'Expected command')
2021-03-03 19:37:35 +01:00
return
self._command_handler.handle(self._configuration.additional_arguments[0], self._configuration.additional_arguments[1:])