2021.10.2 #33

Merged
edraft merged 4 commits from 2021.10.2 into 2021.10 2021-07-25 12:05:12 +02:00
2 changed files with 29 additions and 2 deletions
Showing only changes of commit 0bb272d89b - Show all commits

View File

@ -109,6 +109,10 @@ class CLI(ApplicationABC):
for arg in result_args: for arg in result_args:
args.append(arg) args.append(arg)
else:
Error.error(f'Unexpected command')
return
if command is None: if command is None:
Error.error(f'Expected command') Error.error(f'Expected command')
return return

View File

@ -1,4 +1,5 @@
import os import os
import subprocess
from abc import ABC from abc import ABC
from typing import Optional from typing import Optional
@ -6,6 +7,7 @@ from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.console import Console from cpl.console.console import Console
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl.utils.string import String from cpl.utils.string import String
from cpl_cli.command.custom_script_service import CustomScriptService
from cpl_cli.configuration.workspace_settings import WorkspaceSettings from cpl_cli.configuration.workspace_settings import WorkspaceSettings
from cpl_cli.error import Error from cpl_cli.error import Error
from cpl_cli.command_model import CommandModel from cpl_cli.command_model import CommandModel
@ -57,7 +59,6 @@ class CommandHandler(ABC):
workspace: Optional[WorkspaceSettings] = None workspace: Optional[WorkspaceSettings] = None
if os.path.isfile(os.path.join(self._env.working_directory, 'cpl-workspace.json')): if os.path.isfile(os.path.join(self._env.working_directory, 'cpl-workspace.json')):
# self._config.add_json_file('cpl-workspace.json', optional=True, output=False)
workspace = self._config.get_configuration(WorkspaceSettings) workspace = self._config.get_configuration(WorkspaceSettings)
if command.is_project_needed: if command.is_project_needed:
@ -111,5 +112,27 @@ class CommandHandler(ABC):
self._config.add_json_file(project_json, optional=True, output=False) self._config.add_json_file(project_json, optional=True, output=False)
self._services.get_service(command.command).run(args) # pre scripts
Console.write('\n') Console.write('\n')
self._handle_pre_or_post_scripts(True, workspace, command)
self._services.get_service(command.command).run(args)
# post scripts
Console.write('\n\n')
self._handle_pre_or_post_scripts(False, workspace, command)
Console.write('\n')
def _handle_pre_or_post_scripts(self, pre: bool, workspace: WorkspaceSettings, command: CommandModel):
script_type = 'pre-' if pre else 'post-'
if workspace is not None and len(workspace.scripts) > 0:
for script in workspace.scripts:
if script_type in script and script.split(script_type)[1] == command.name:
script_name = script
script_cmd = workspace.scripts[script]
if script_cmd in workspace.scripts:
script_name = workspace.scripts[script]
css: CustomScriptService = self._services.get_service(CustomScriptService)
if css is None:
continue
css.run([script_name])