@@ -81,10 +81,8 @@ def activate(self) -> None:
8181 exec_configs [command ]['help' ] = self ._get_help (exec_configs [command ]['bin_path' ])
8282 # create a new command for the bot
8383 self .log .debug (f"Creating new command for { command } " )
84- commands .append (Command (lambda plugin , msg , args : self ._run_command (msg ,
85- args ),
86- name = command ,
87- doc = exec_configs [command ]['help' ]))
84+ commands .append (Command (lambda plugin , msg , args : self .run_command (msg , args ),
85+ name = command , doc = exec_configs [command ]['help' ]))
8886 # create a dynamic plugin for all of our executables
8987 self .create_dynamic_plugin (self .config ['PLUGIN_NAME' ], tuple (commands ))
9088
@@ -398,7 +396,7 @@ def _read_json_config(self, file: Path) -> List[Dict]:
398396
399397 return read_data
400398
401- def _run_command (self , msg : ErrbotMessage , args : str ) -> str :
399+ def run_command (self , msg : ErrbotMessage , args : str ) -> str :
402400 """
403401 Runs an executable with args from chatops and replies in a thread with the results of the execution
404402 Args:
@@ -410,7 +408,6 @@ def _run_command(self, msg: ErrbotMessage, args: str) -> str:
410408 Returns:
411409 Str - messages to send to the user
412410 """
413- # TODO: PAss along env vars from config
414411 self .log .debug (f"Message coming in { msg } " )
415412 msg_without_args = msg .body .replace (args , '' )
416413 self .log .debug (f"Message stripped of args { msg_without_args } " )
@@ -427,7 +424,8 @@ def _run_command(self, msg: ErrbotMessage, args: str) -> str:
427424 command = delegator .run (f"{ executable_config ['bin_path' ]} { args } " ,
428425 block = False ,
429426 timeout = executable_config ['timeout' ] if 'timeout' in executable_config else
430- self .config ['TIMEOUT' ])
427+ self .config ['TIMEOUT' ],
428+ env = executable_config ['env_vars' ] if 'env_vars' in executable_config else None )
431429 except FileNotFoundError :
432430 self .log .error (f"Executable not found at { executable_config ['bin_path' ]} " )
433431 return f"Error: Executable not found at { executable_config ['bin_path' ]} "
@@ -437,11 +435,14 @@ def _run_command(self, msg: ErrbotMessage, args: str) -> str:
437435
438436 self .log .info (f"{ executable_config ['bin_path' ]} running with PID { command .pid } " )
439437
440- yield f"Started your command with PID { command .pid } "
438+ # argh, gotta use self.send rather than yielding here because of how we're calling this from a lambda to make
439+ # it a bot cmd. This breaks people's "divert to thread" or "divert to dm" rules. Sorry.
440+ self .send (msg .to , text = f"Started your command with PID { command .pid } " , in_reply_to = msg )
441441 command .block ()
442442
443- yield command .out ()
444- yield f"Command RC: { command .return_code } "
443+ self .send (msg .to , text = command .out , in_reply_to = msg )
444+ self .send (msg .to , text = f"Command RC: { command .return_code } " , in_reply_to = msg )
445+ return
445446
446447 def _get_help (self , executable : Path ) -> str :
447448 """
0 commit comments