exec arbitrary commands

This commit is contained in:
boyska 2023-12-25 15:30:58 +01:00
parent 3ded0784be
commit ee70ecb7bf

View file

@ -217,6 +217,10 @@ def get_parser():
sub = p.add_subparsers()
execute = sub.add_parser("exec")
execute.set_defaults(func=main_exec)
execute.add_argument("cmd")
get = sub.add_parser("get")
get.set_defaults(func=main_get)
get.add_argument("variable")
@ -252,6 +256,15 @@ def output(args, content):
print(repr(content["value"]))
def main_exec(args, pira: Pira):
try:
out = pira.execute_command(args.cmd)
except CommandError as exc:
print(f"Command error: {exc}", file=sys.stderr)
sys.exit(1)
output(args, dict(cmd=args.cmd, value=out))
def main_get(args, pira: Pira):
try:
out = pira.read_variable(args.variable)