sh_cpl/src/cpl_cli/startup.py

105 lines
6.3 KiB
Python
Raw Normal View History

2021-04-07 18:19:34 +02:00
import os
from typing import Optional
2021-04-07 18:19:34 +02:00
2021-08-05 14:21:42 +02:00
from cpl_core.application.startup_abc import StartupABC
2022-05-19 08:25:32 +02:00
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
2021-08-05 14:21:42 +02:00
from cpl_core.configuration.configuration_abc import ConfigurationABC
2022-05-19 08:25:32 +02:00
from cpl_core.console import Console
2021-08-05 14:21:42 +02:00
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
2021-04-11 15:36:04 +02:00
from cpl_cli.command.add_service import AddService
2021-03-12 16:06:30 +01:00
from cpl_cli.command.build_service import BuildService
from cpl_cli.command.custom_script_service import CustomScriptService
2021-03-12 16:06:30 +01:00
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-04-11 12:33:05 +02:00
from cpl_cli.command.remove_service import RemoveService
2021-03-12 22:53:02 +01:00
from cpl_cli.command.start_service import StartService
2021-03-14 10:58:59 +01:00
from cpl_cli.command.uninstall_service import UninstallService
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
from cpl_cli.command.help_service import HelpService
from cpl_cli.command.version_service import VersionService
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
2021-03-04 06:53:38 +01:00
from cpl_cli.error import Error
2021-03-13 11:05:17 +01:00
from cpl_cli.live_server.live_server_service import LiveServerService
2021-03-12 16:10:43 +01:00
from cpl_cli.publish.publisher_service import PublisherService
2021-03-04 19:06:53 +01:00
from cpl_cli.publish.publisher_abc import PublisherABC
2021-10-03 11:23:17 +02:00
from cpl_core.environment import ApplicationEnvironment
2021-03-03 18:37:54 +01:00
class Startup(StartupABC):
2021-10-03 11:23:17 +02:00
def __init__(self):
2021-03-19 14:20:57 +01:00
StartupABC.__init__(self)
2021-10-03 11:23:17 +02:00
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
environment.set_runtime_directory(os.path.dirname(__file__))
configuration.argument_error_function = Error.error
2021-03-04 06:53:38 +01:00
2021-10-03 11:23:17 +02:00
configuration.add_environment_variables('PYTHON_')
configuration.add_environment_variables('CPL_')
configuration.add_json_file('appsettings.json', path=environment.runtime_directory, optional=False, output=False)
2022-05-19 08:25:32 +02:00
configuration.add_json_file('cpl-workspace.json', path=environment.working_directory, optional=True, output=False)
2021-03-04 07:09:08 +01:00
2022-05-19 08:25:32 +02:00
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'add', ['a', 'A'], AddService) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'build', ['b', 'B'], BuildService)
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'generate', ['g', 'G'], GenerateService) \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'abc', ['a', 'A'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'class', ['c', 'C'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'service', ['s', 'S'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 't'], ' ')
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'install', ['i', 'I'], InstallService) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'new', ['n', 'N'], NewService) \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'console', ['c', 'C'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'library', ['l', 'L'], ' ')
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'publish', ['p', 'P'], PublishService)
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'remove', ['r', 'R'], RemoveService) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['S', 'S'], StartService)
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'uninstall', ['ui', 'UI'], UninstallService) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'update', ['u', 'U'], UpdateService)
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'version', ['v', 'V'], VersionService)
2021-10-03 11:23:17 +02:00
2022-05-19 08:25:32 +02:00
configuration.for_each_argument(
lambda a: a.add_console_argument(ArgumentTypeEnum.Executable, '--', 'help', ['h', 'H'], HelpService)
)
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', 'help', ['h', 'H'], HelpService)
2021-10-03 11:23:17 +02:00
2022-05-19 08:25:32 +02:00
workspace: Optional[WorkspaceSettings] = configuration.get_configuration(WorkspaceSettings)
if workspace is not None:
for script in workspace.scripts:
2022-05-19 08:25:32 +02:00
configuration.create_console_argument(ArgumentTypeEnum.Executable, '', script, [], CustomScriptService)
2021-03-03 18:37:54 +01:00
2021-10-03 11:23:17 +02:00
return configuration
2021-03-03 18:37:54 +01:00
2021-10-03 11:23:17 +02:00
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
2022-05-19 08:25:32 +02:00
# services.add_singleton(CommandHandler)
2021-03-03 19:37:35 +01:00
2021-10-03 11:23:17 +02:00
services.add_transient(PublisherABC, PublisherService)
services.add_transient(LiveServerService)
2021-03-04 19:06:53 +01:00
2021-10-03 11:23:17 +02:00
services.add_transient(AddService)
services.add_transient(BuildService)
services.add_transient(CustomScriptService)
services.add_transient(GenerateService)
services.add_transient(HelpService)
services.add_transient(InstallService)
services.add_transient(NewService)
services.add_transient(PublishService)
services.add_transient(RemoveService)
services.add_transient(StartService)
services.add_transient(UninstallService)
services.add_transient(UpdateService)
services.add_transient(VersionService)
2021-03-03 19:37:35 +01:00
2021-10-03 11:23:17 +02:00
return services.build_service_provider()