From f9a26ae9e4ac4e551e353c77fe491132e31162f1 Mon Sep 17 00:00:00 2001
From: "r.jaepel" <r.jaepel@fz-juelich.de>
Date: Thu, 23 Nov 2023 15:57:02 +0100
Subject: [PATCH] add ability to run python files and arbitrary commands from
 the CLI

---
 cadetrdm/cli_integration.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/cadetrdm/cli_integration.py b/cadetrdm/cli_integration.py
index 32815ac..0a72993 100644
--- a/cadetrdm/cli_integration.py
+++ b/cadetrdm/cli_integration.py
@@ -1,3 +1,6 @@
+import shlex
+import subprocess
+
 import click
 
 from .repositories import ProjectRepo
@@ -47,6 +50,26 @@ def fill_data_from_cadet_rdm_json(re_load=False):
     repo.fill_data_from_cadet_rdm_json(re_load=re_load)
 
 
+@cli.command()
+@click.argument('file_name')
+@click.argument('results_commit_message')
+def run_python_file(file_name, results_commit_message):
+    repo = ProjectRepo(".")
+    repo.enter_context()
+    subprocess.run(["python", file_name])
+    repo.exit_context(results_commit_message)
+
+
+@cli.command()
+@click.argument('command')
+@click.argument('results_commit_message')
+def run_command(command, results_commit_message):
+    repo = ProjectRepo(".")
+    repo.enter_context()
+    subprocess.run(shlex.split(command))
+    repo.exit_context(results_commit_message)
+
+
 @cli.command()
 @click.option('--output_repo_name', default="output",
               help='Name of the folder where the tracked output should be stored. Optional. Default: "output".')
-- 
GitLab