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-12 16:06:30 +01:00
|
|
|
from cpl_cli.command.build_service import BuildService
|
|
|
|
from cpl_cli.command.generate_service import GenerateService
|
2021-03-13 22:53:28 +01:00
|
|
|
from cpl_cli.command.install_service import InstallService
|
2021-03-12 16:06:30 +01:00
|
|
|
from cpl_cli.command.new_service import NewService
|
|
|
|
from cpl_cli.command.publish_service import PublishService
|
2021-03-12 22:53:02 +01:00
|
|
|
from cpl_cli.command.start_service import StartService
|
2021-03-13 21:39:59 +01:00
|
|
|
from cpl_cli.command.update_service import UpdateService
|
2021-03-12 16:06:30 +01:00
|
|
|
from cpl_cli.command_handler_service 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-12 16:06:30 +01:00
|
|
|
from cpl_cli.command.help_service import HelpService
|
|
|
|
from cpl_cli.command.version_service import VersionService
|
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-12 16:06:30 +01:00
|
|
|
self._command_handler.add_command(CommandModel('build', ['h', 'B'], BuildService, True))
|
|
|
|
self._command_handler.add_command(CommandModel('generate', ['g', 'G'], GenerateService, True))
|
|
|
|
self._command_handler.add_command(CommandModel('help', ['h', 'H'], HelpService, False))
|
2021-03-13 22:53:28 +01:00
|
|
|
self._command_handler.add_command(CommandModel('install', ['i', 'I'], InstallService, False))
|
2021-03-12 16:06:30 +01:00
|
|
|
self._command_handler.add_command(CommandModel('new', ['n', 'N'], NewService, False))
|
|
|
|
self._command_handler.add_command(CommandModel('publish', ['p', 'P'], PublishService, True))
|
2021-03-12 22:53:02 +01:00
|
|
|
self._command_handler.add_command(CommandModel('start', ['s', 'S'], StartService, True))
|
2021-03-13 21:39:59 +01:00
|
|
|
self._command_handler.add_command(CommandModel('update', ['u', 'U'], UpdateService, True))
|
2021-03-12 16:06:30 +01:00
|
|
|
self._command_handler.add_command(CommandModel('version', ['v', 'V'], VersionService, False))
|
2021-03-03 18:37:54 +01:00
|
|
|
|
|
|
|
def main(self):
|
2021-03-13 22:53:28 +01:00
|
|
|
command = None
|
|
|
|
args = []
|
|
|
|
if len(self._configuration.additional_arguments) > 0:
|
|
|
|
command = self._configuration.additional_arguments[0]
|
|
|
|
if len(self._configuration.additional_arguments) > 1:
|
|
|
|
args = self._configuration.additional_arguments[1:]
|
|
|
|
else:
|
|
|
|
for cmd in self._command_handler.commands:
|
|
|
|
result = self._configuration.get_configuration(cmd.name)
|
|
|
|
if result is not None:
|
|
|
|
command = cmd.name
|
|
|
|
args.append(result)
|
|
|
|
|
|
|
|
if command is None:
|
2021-03-04 06:42:40 +01:00
|
|
|
Error.error(f'Expected command')
|
2021-03-03 19:37:35 +01:00
|
|
|
return
|
|
|
|
|
2021-03-13 22:53:28 +01:00
|
|
|
self._command_handler.handle(command, args)
|