sh_cpl/unittests/unittests_shared/cli_commands.py

35 lines
889 B
Python
Raw Normal View History

2022-05-26 14:47:36 +02:00
import os
import subprocess
2022-05-26 15:29:49 +02:00
from unittests_cli.constants import CLI_PATH
2022-05-26 14:47:36 +02:00
class CLICommands:
@staticmethod
2022-05-27 18:07:12 +02:00
def _run(cmd: str, *args, output=False):
2022-05-26 14:47:36 +02:00
env_vars = os.environ
2022-05-27 18:07:12 +02:00
env_vars['CPL_IS_UNITTEST'] = 'NO' if output else 'YES'
2022-05-26 15:29:49 +02:00
command = ['python', CLI_PATH, cmd]
2022-05-26 14:47:36 +02:00
for arg in args:
command.append(arg)
subprocess.run(command, env=env_vars)
2022-06-03 23:35:07 +02:00
@classmethod
def add(cls, source: str, target: str):
cls._run('add', source, target)
2022-05-26 14:47:36 +02:00
@classmethod
2022-05-27 18:07:12 +02:00
def generate(cls, schematic: str, name: str, output=False):
cls._run('generate', schematic, name, output=output)
2022-05-26 14:47:36 +02:00
@classmethod
2022-05-27 18:07:12 +02:00
def new(cls, project_type: str, name: str, *args, output=False):
cls._run('new', project_type, name, *args, output=output)
2022-06-03 23:44:26 +02:00
@classmethod
def remove(cls, project: str):
cls._run('remove', project)