Skip to content

Commit

Permalink
vm: add --env flag to run-comand
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Aug 22, 2024
1 parent c9bac60 commit 7ae6de3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tasks/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,23 @@ def ssh(ctx, name):
)


@task
def run_command(ctx, name, path, cmd):
@task(iterable=["env"])
def run_command(ctx, name, path, cmd, env=None):
"""
Run a command on the remote VM
"""
ip_addr = _get_ip(name)
cmd_base = _build_ssh_command(ip_addr)
cmd = "{} \"bash -c 'cd {} && {}'\"".format(cmd_base, path, cmd)

env_var_str = ""
if env is not None:
env_var_list = [env_var for env_var in env]
env_var_str = " ".join(env_var_list)
env_var_str += " &&"

cmd = "{} \"bash -c '{}cd {} && {}'\"".format(
cmd_base, env_var_str, path, cmd
)
print(cmd)
run(cmd, shell=True, check=True)

Expand Down

0 comments on commit 7ae6de3

Please sign in to comment.