2021-03-03 18:37:54 +01:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from cpl.application.application_host import ApplicationHost
|
|
|
|
from cpl.application.application_host_abc import ApplicationHostABC
|
|
|
|
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-08 22:02:16 +01:00
|
|
|
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
|
2021-03-04 19:06:53 +01:00
|
|
|
from cpl_cli.command.build import Build
|
2021-03-10 22:29:42 +01:00
|
|
|
from cpl_cli.command.generate import Generate
|
2021-03-09 22:29:14 +01:00
|
|
|
from cpl_cli.command.new import New
|
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.help import Help
|
|
|
|
from cpl_cli.command.version import Version
|
2021-03-04 06:53:38 +01:00
|
|
|
from cpl_cli.error import Error
|
2021-03-04 19:06:53 +01:00
|
|
|
from cpl_cli.publish.publisher import Publisher
|
|
|
|
from cpl_cli.publish.publisher_abc import PublisherABC
|
2021-03-03 18:37:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Startup(StartupABC):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
StartupABC.__init__(self)
|
|
|
|
|
|
|
|
self._app_host: Optional[ApplicationHostABC] = None
|
|
|
|
self._configuration: Optional[ConfigurationABC] = None
|
|
|
|
self._services: Optional[ServiceProviderABC] = None
|
|
|
|
|
|
|
|
def create_application_host(self) -> ApplicationHostABC:
|
|
|
|
self._app_host = ApplicationHost()
|
2021-03-04 06:53:38 +01:00
|
|
|
|
2021-03-04 07:09:08 +01:00
|
|
|
self._app_host.application_runtime.set_runtime_directory(__file__)
|
2021-03-04 06:53:38 +01:00
|
|
|
self._app_host.console_argument_error_function(Error.error)
|
|
|
|
|
2021-03-04 07:09:08 +01:00
|
|
|
self._configuration = self._app_host.configuration
|
|
|
|
self._services = self._app_host.services
|
|
|
|
|
2021-03-03 18:37:54 +01:00
|
|
|
return self._app_host
|
|
|
|
|
|
|
|
def create_configuration(self) -> ConfigurationABC:
|
|
|
|
self._configuration.add_environment_variables('PYTHON_')
|
|
|
|
self._configuration.add_environment_variables('CPL_')
|
2021-03-04 19:06:53 +01:00
|
|
|
self._configuration.add_json_file('cpl.json', optional=True, output=False)
|
2021-03-09 22:29:14 +01:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'build', ['b', 'B'], ''))
|
2021-03-10 22:29:42 +01:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'generate', ['g', 'G'], '', [
|
|
|
|
ConsoleArgument('', 'abc', ['a', 'A'], ' '),
|
|
|
|
ConsoleArgument('', 'class', ['c', 'C'], ' '),
|
|
|
|
ConsoleArgument('', 'enum', ['e', 'E'], ' '),
|
2021-03-12 15:44:55 +01:00
|
|
|
ConsoleArgument('', 'service', ['s', 'S'], ' '),
|
|
|
|
ConsoleArgument('', 'settings', ['st', 'ST'], ' ')
|
2021-03-10 22:29:42 +01:00
|
|
|
]))
|
2021-03-09 22:29:14 +01:00
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'help', ['h', 'H'], ''))
|
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'new', ['n', 'N'], '', [
|
|
|
|
ConsoleArgument('', 'console', ['c', 'C'], ' ')
|
|
|
|
]))
|
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'publish', ['p', 'P'], ''))
|
|
|
|
self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], ''))
|
2021-03-03 18:37:54 +01:00
|
|
|
self._configuration.add_console_arguments()
|
|
|
|
|
|
|
|
return self._configuration
|
|
|
|
|
|
|
|
def create_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-04 19:06:53 +01:00
|
|
|
self._services.add_transient(PublisherABC, Publisher)
|
|
|
|
|
|
|
|
self._services.add_transient(Build)
|
2021-03-10 22:29:42 +01:00
|
|
|
self._services.add_transient(Generate)
|
2021-03-04 19:06:53 +01:00
|
|
|
self._services.add_transient(Help)
|
2021-03-09 22:29:14 +01:00
|
|
|
self._services.add_transient(New)
|
2021-03-08 20:29:08 +01:00
|
|
|
self._services.add_transient(Publish)
|
2021-03-04 19:06:53 +01:00
|
|
|
self._services.add_transient(Version)
|
2021-03-03 19:37:35 +01:00
|
|
|
|
2021-03-03 18:37:54 +01:00
|
|
|
return self._services
|