2021.4.2 #12

Merged
edraft merged 22 commits from 2021.4.2 into 2021.4 2021-03-29 15:48:59 +02:00
2 changed files with 10 additions and 13 deletions
Showing only changes of commit 05b9fd801b - Show all commits

View File

@ -25,18 +25,17 @@ class ServiceProvider(ServiceProviderABC):
return None return None
def _get_service(self, service_type: type, parameter: Parameter) -> object: def _get_service(self, parameter: Parameter) -> object:
for descriptor in self._service_descriptors: for descriptor in self._service_descriptors:
if descriptor.service_type == parameter.annotation or issubclass(descriptor.service_type, if descriptor.service_type == parameter.annotation or issubclass(descriptor.service_type, parameter.annotation):
parameter.annotation):
if descriptor.implementation is not None: if descriptor.implementation is not None:
return descriptor.implementation return descriptor.implementation
implementation = self.build_service(service_type) implementation = self.build_service(descriptor.service_type)
if descriptor.lifetime == ServiceLifetimeEnum.singleton: if descriptor.lifetime == ServiceLifetimeEnum.singleton:
descriptor.implementation = implementation descriptor.implementation = implementation
return descriptor.implementation return implementation
def build_service(self, service_type: type) -> object: def build_service(self, service_type: type) -> object:
for descriptor in self._service_descriptors: for descriptor in self._service_descriptors:
@ -69,7 +68,7 @@ class ServiceProvider(ServiceProviderABC):
params.append(self._configuration) params.append(self._configuration)
else: else:
params.append(self._get_service(service_type, parameter)) params.append(self._get_service(parameter))
return service_type(*params) return service_type(*params)

View File

@ -1,7 +1,6 @@
import os import os
from collections import Callable from collections import Callable
from cpl.application.application_abc import ApplicationRuntimeABC
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.foreground_color_enum import ForegroundColorEnum from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.console.console import Console from cpl.console.console import Console
@ -18,11 +17,10 @@ from cpl_cli.templates.template_file_abc import TemplateFileABC
class GenerateService(CommandABC): class GenerateService(CommandABC):
def __init__(self, configuration: ConfigurationABC, runtime: ApplicationRuntimeABC): def __init__(self, configuration: ConfigurationABC):
""" """
Service for the CLI command generate Service for the CLI command generate
:param configuration: :param configuration:
:param runtime:
""" """
CommandABC.__init__(self) CommandABC.__init__(self)
@ -54,7 +52,7 @@ class GenerateService(CommandABC):
} }
self._config = configuration self._config = configuration
self._runtime = runtime self._env = self._config.environment
@staticmethod @staticmethod
def _help(message: str): def _help(message: str):
@ -105,7 +103,7 @@ class GenerateService(CommandABC):
template = template(class_name, schematic, self._schematics[schematic]["Upper"], rel_path) template = template(class_name, schematic, self._schematics[schematic]["Upper"], rel_path)
file_path = os.path.join(self._runtime.working_directory, template.path, template.name) file_path = os.path.join(self._env.working_directory, template.path, template.name)
if not os.path.isdir(os.path.dirname(file_path)): if not os.path.isdir(os.path.dirname(file_path)):
os.makedirs(os.path.dirname(file_path)) os.makedirs(os.path.dirname(file_path))
@ -113,9 +111,9 @@ class GenerateService(CommandABC):
Console.error(f'{String.first_to_upper(schematic)} already exists!') Console.error(f'{String.first_to_upper(schematic)} already exists!')
exit() exit()
message = f'Creating {self._runtime.working_directory}/{template.path}/{template.name}' message = f'Creating {self._env.working_directory}/{template.path}/{template.name}'
if template.path == '': if template.path == '':
message = f'Creating {self._runtime.working_directory}/{template.name}' message = f'Creating {self._env.working_directory}/{template.name}'
Console.spinner( Console.spinner(
message, message,