2021-07-24 17:24:01 +02:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
2021-08-05 14:21:42 +02:00
|
|
|
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
|
|
|
from cpl_core.console.console import Console
|
2021-07-24 17:24:01 +02:00
|
|
|
from cpl_cli.command_abc import CommandABC
|
|
|
|
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
|
|
|
|
|
|
|
|
|
|
|
class CustomScriptService(CommandABC):
|
|
|
|
|
|
|
|
def __init__(self, config: ConfigurationABC, ws: WorkspaceSettings):
|
|
|
|
"""
|
|
|
|
Service for CLI scripts
|
|
|
|
"""
|
|
|
|
CommandABC.__init__(self)
|
|
|
|
|
|
|
|
self._config = config
|
|
|
|
self._workspace = ws
|
|
|
|
|
|
|
|
@property
|
|
|
|
def help_message(self) -> str:
|
|
|
|
return ''
|
|
|
|
|
2022-05-22 18:33:07 +02:00
|
|
|
def execute(self, args: list[str]):
|
2022-05-20 09:12:28 +02:00
|
|
|
cmd = self._config.get_configuration('ACTIVE_EXECUTABLE')
|
2021-07-24 17:24:01 +02:00
|
|
|
|
|
|
|
for script in self._workspace.scripts:
|
|
|
|
if script == cmd:
|
|
|
|
command = self._workspace.scripts[script]
|
|
|
|
try:
|
2021-11-23 19:01:00 +01:00
|
|
|
subprocess.run(command, shell=True if os.name == 'posix' else None)
|
2021-07-24 17:24:01 +02:00
|
|
|
except Exception as e:
|
|
|
|
Console.error(str(e))
|