|
16 | 16 | class Executor(object): |
17 | 17 | """ All cli commands usually return a dict(command=...) that will be executed by this handler""" |
18 | 18 |
|
19 | | - def __call__(self, result, pass_trough=True): |
| 19 | + def __call__(self, result, pass_trough=True, cwd=None): |
20 | 20 | try: |
21 | | - return self._execute(result, pass_trough) |
| 21 | + return self._execute(result, pass_trough, cwd) |
22 | 22 | except Exception as ex: |
23 | 23 | display(ex.message, stderr=True, color='red') |
24 | 24 | display('------- TRACEBACK ----------', stderr=True, color='dark gray') |
25 | 25 | import traceback |
26 | 26 | traceback.print_exc() |
27 | 27 | display('------ END TRACEBACK -------', stderr=True, color='dark gray') |
28 | 28 |
|
29 | | - def _execute(self, result, pass_trough=True): |
| 29 | + def _execute(self, result, pass_trough=True, cwd=None): |
30 | 30 | if not result or not isinstance(result, dict): |
31 | 31 | return |
32 | 32 |
|
33 | 33 | if 'command' in result: |
34 | 34 | shell_command = result['command'] |
35 | 35 | display("%s" % self.shadow_credentials(shell_command), stderr=True, color='yellow') |
36 | 36 | if pass_trough: |
37 | | - exit_code = call(shell_command, shell=True) |
| 37 | + exit_code = call(shell_command, shell=True, cwd=cwd) |
38 | 38 | else: |
39 | | - p = Popen(shell_command, shell=True, stdout=PIPE, stderr=PIPE) |
| 39 | + p = Popen(shell_command, shell=True, stdout=PIPE, stderr=PIPE, cwd=cwd) |
40 | 40 | output, errors = p.communicate() |
41 | 41 | display(output) |
42 | 42 | if errors: |
|
0 commit comments