From c41180b2f55b5fbdf1d6c43c44dcc207e979f48c Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Thu, 14 Sep 2023 13:28:45 -0400 Subject: [PATCH] allow for flags --- pioreactor/background_jobs/monitor.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pioreactor/background_jobs/monitor.py b/pioreactor/background_jobs/monitor.py index d1ca4c7a..11009ae1 100644 --- a/pioreactor/background_jobs/monitor.py +++ b/pioreactor/background_jobs/monitor.py @@ -573,13 +573,14 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None: "options": { "option_A": "value1", "option_B": "value2" + "flag": None }, "args": ["arg1", "arg2"] } effectively runs: - > pio run job_name arg1 arg2 --option-A value1 --option-B value2 + > pio run job_name arg1 arg2 --option-A value1 --option-B value2 --flag """ @@ -639,7 +640,10 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None: list_of_options: list[str] = [] for option, value in options.items(): - list_of_options.extend([f"--{option.replace('_', '-')}", str(value)]) + list_of_options.append(f"--{option.replace('_', '-')}") + if value is not None: + # this handles flag arguments, like --dry-run + list_of_options.append(str(value)) suffix = ">/dev/null 2>&1 &" @@ -647,7 +651,7 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None: # we don't escape the suffix. command = prefix + " " + join(core_command + args + list_of_options) + " " + suffix - self.logger.debug(f"Running `{command}` from Monitor job.") + self.logger.debug(f"Running `{command}` from monitor job.") Thread( target=subprocess.run,