Improved configuration

This commit is contained in:
Sven Heidemann 2022-05-25 13:11:41 +02:00
parent 3e7a3d75c5
commit 9f4077a073

View File

@ -5,8 +5,6 @@ import traceback
from collections.abc import Callable from collections.abc import Callable
from typing import Union, Type, Optional from typing import Union, Type, Optional
from cpl_cli.command.custom_script_service import CustomScriptService
from cpl_cli.configuration import WorkspaceSettings
from cpl_core.configuration.argument_abc import ArgumentABC from cpl_core.configuration.argument_abc import ArgumentABC
from cpl_core.configuration.argument_builder import ArgumentBuilder from cpl_core.configuration.argument_builder import ArgumentBuilder
from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC
@ -158,6 +156,8 @@ class Configuration(ConfigurationABC):
def _handle_pre_or_post_executables(self, pre: bool, argument: ExecutableArgument, services: ServiceProviderABC): def _handle_pre_or_post_executables(self, pre: bool, argument: ExecutableArgument, services: ServiceProviderABC):
script_type = 'pre-' if pre else 'post-' script_type = 'pre-' if pre else 'post-'
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
workspace: Optional[WorkspaceSettings] = self.get_configuration(WorkspaceSettings) workspace: Optional[WorkspaceSettings] = self.get_configuration(WorkspaceSettings)
if workspace is None or len(workspace.scripts) == 0: if workspace is None or len(workspace.scripts) == 0:
return return
@ -170,12 +170,13 @@ class Configuration(ConfigurationABC):
if script.split(script_type)[1] != argument.name: if script.split(script_type)[1] != argument.name:
continue continue
from cpl_cli.command.custom_script_service import CustomScriptService
css: CustomScriptService = services.get_service(CustomScriptService) css: CustomScriptService = services.get_service(CustomScriptService)
if css is None: if css is None:
continue continue
Console.write_line() Console.write_line()
self.add_configuration('ACTIVE_EXECUTABLE', script) self._set_variable('ACTIVE_EXECUTABLE', script)
css.run([]) css.run([])
def _parse_arguments(self, executables: list[ArgumentABC], arg_list: list[str], args_types: list[ArgumentABC]): def _parse_arguments(self, executables: list[ArgumentABC], arg_list: list[str], args_types: list[ArgumentABC]):
@ -333,7 +334,7 @@ class Configuration(ConfigurationABC):
cmd: ArgumentExecutableABC = services.get_service(exe.executable_type) cmd: ArgumentExecutableABC = services.get_service(exe.executable_type)
self._handle_pre_or_post_executables(True, exe, services) self._handle_pre_or_post_executables(True, exe, services)
self.add_configuration('ACTIVE_EXECUTABLE', exe.name) self._set_variable('ACTIVE_EXECUTABLE', exe.name)
cmd.execute(self._additional_arguments) cmd.execute(self._additional_arguments)
self._handle_pre_or_post_executables(False, exe, services) self._handle_pre_or_post_executables(False, exe, services)
prevent = exe.prevent_next_executable prevent = exe.prevent_next_executable