2021-04-07 18:19:34 +02:00
|
|
|
import os
|
|
|
|
|
2021-03-03 18:37:54 +01:00
|
|
|
from cpl.application.startup_abc import StartupABC
|
2021-03-09 22:29:14 +01:00
|
|
|
from cpl.configuration.console_argument import ConsoleArgument
|
2021-03-03 18:37:54 +01:00
|
|
|
from cpl.configuration.configuration_abc import ConfigurationABC
|
2021-03-26 13:16:40 +01:00
|
|
|
from cpl.dependency_injection.service_collection_abc import ServiceCollectionABC
|
2021-03-08 22:02:16 +01:00
|
|
|
from cpl.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.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
|
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-03-03 18:37:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Startup(StartupABC):
|
|
|
|
|
2021-03-29 08:56:18 +02:00
|
|
|
def __init__(self, config: ConfigurationABC, services: ServiceCollectionABC):
|
2021-03-19 14:20:57 +01:00
|
|
|
StartupABC.__init__(self)
|
|
|
|
|
|
|
|
self._configuration = config
|
2021-03-29 08:56:18 +02:00
|
|
|
self._env = self._configuration.environment
|
2021-03-19 14:20:57 +01:00
|
|
|
self._services = services
|
2021-03-04 06:53:38 +01:00
|
|
|
|
2021-04-07 18:19:34 +02:00
|
|
|
self._env.set_runtime_directory(os.path.dirname(__file__))
|
2021-03-04 07:09:08 +01:00
|
|
|
|
2021-03-19 14:15:53 +01:00
|
|
|
def configure_configuration(self) -> ConfigurationABC:
|
|
|
|
self._configuration.argument_error_function = Error.error
|
2021-03-03 18:37:54 +01:00
|
|
|
|
|
|
|
self._configuration.add_environment_variables('PYTHON_')
|
|
|
|
self._configuration.add_environment_variables('CPL_')
|
2021-03-29 08:56:18 +02:00
|
|
|
self._configuration.add_json_file('appsettings.json', path=self._env.runtime_directory,
|
2021-03-16 18:28:31 +01:00
|
|
|
optional=False, output=False)
|
2021-04-11 15:36:04 +02:00
|
|
|
|
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'add', ['a', 'a'], ' '))
|
2021-04-08 19:30:00 +02:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'build', ['b', 'B'], ''))
|
2021-03-13 22:53:28 +01:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'generate', ['g', 'G'], '', console_arguments=[
|
2021-03-10 22:29:42 +01:00
|
|
|
ConsoleArgument('', 'abc', ['a', 'A'], ' '),
|
|
|
|
ConsoleArgument('', 'class', ['c', 'C'], ' '),
|
|
|
|
ConsoleArgument('', 'enum', ['e', 'E'], ' '),
|
2021-03-12 15:44:55 +01:00
|
|
|
ConsoleArgument('', 'service', ['s', 'S'], ' '),
|
2021-03-12 16:01:44 +01:00
|
|
|
ConsoleArgument('', 'settings', ['st', 'ST'], ' '),
|
|
|
|
ConsoleArgument('', 'thread', ['t', 't'], ' ')
|
2021-03-10 22:29:42 +01:00
|
|
|
]))
|
2021-04-11 16:36:59 +02:00
|
|
|
self._configuration.add_console_argument(
|
|
|
|
ConsoleArgument('', 'help', ['h', 'H'], ' ', is_value_token_optional=True)
|
|
|
|
)
|
2021-03-13 22:53:28 +01:00
|
|
|
self._configuration.add_console_argument(
|
|
|
|
ConsoleArgument('', 'install', ['i', 'I'], ' ', is_value_token_optional=True)
|
|
|
|
)
|
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'new', ['n', 'N'], '', console_arguments=[
|
2021-03-30 12:44:31 +02:00
|
|
|
ConsoleArgument('', 'console', ['c', 'C'], ' '),
|
|
|
|
ConsoleArgument('', 'library', ['l', 'L'], ' ')
|
2021-03-09 22:29:14 +01:00
|
|
|
]))
|
2021-04-08 19:30:00 +02:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'publish', ['p', 'P'], ''))
|
2021-04-11 12:33:05 +02:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'remove', ['r', 'R'], ' '))
|
2021-04-08 19:30:00 +02:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'start', ['s', 'S'], ''))
|
2021-03-17 07:59:12 +01:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' '))
|
2021-03-13 21:39:59 +01:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], ''))
|
2021-03-09 22:29:14 +01:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], ''))
|
2021-03-15 18:47:08 +01:00
|
|
|
self._configuration.add_console_arguments(error=False)
|
2021-03-03 18:37:54 +01:00
|
|
|
|
|
|
|
return self._configuration
|
|
|
|
|
2021-03-19 14:15:53 +01:00
|
|
|
def configure_services(self) -> ServiceProviderABC:
|
2021-03-04 19:06:53 +01:00
|
|
|
self._services.add_singleton(CommandHandler)
|
2021-03-03 19:37:35 +01:00
|
|
|
|
2021-03-12 16:10:43 +01:00
|
|
|
self._services.add_transient(PublisherABC, PublisherService)
|
2021-03-13 11:05:17 +01:00
|
|
|
self._services.add_transient(LiveServerService)
|
2021-03-04 19:06:53 +01:00
|
|
|
|
2021-04-11 15:36:04 +02:00
|
|
|
self._services.add_transient(AddService)
|
2021-03-12 16:06:30 +01:00
|
|
|
self._services.add_transient(BuildService)
|
|
|
|
self._services.add_transient(GenerateService)
|
|
|
|
self._services.add_transient(HelpService)
|
2021-03-13 22:53:28 +01:00
|
|
|
self._services.add_transient(InstallService)
|
2021-03-12 16:06:30 +01:00
|
|
|
self._services.add_transient(NewService)
|
|
|
|
self._services.add_transient(PublishService)
|
2021-04-11 12:33:05 +02:00
|
|
|
self._services.add_transient(RemoveService)
|
2021-03-12 22:53:02 +01:00
|
|
|
self._services.add_transient(StartService)
|
2021-03-14 10:58:59 +01:00
|
|
|
self._services.add_transient(UninstallService)
|
2021-03-13 21:39:59 +01:00
|
|
|
self._services.add_transient(UpdateService)
|
2021-03-12 16:06:30 +01:00
|
|
|
self._services.add_transient(VersionService)
|
2021-03-03 19:37:35 +01:00
|
|
|
|
2021-03-26 13:16:40 +01:00
|
|
|
return self._services.build_service_provider()
|