From ee70ecb7bfc3dd1efd0c3a3d50500224db57c9b9 Mon Sep 17 00:00:00 2001 From: boyska Date: Mon, 25 Dec 2023 15:30:58 +0100 Subject: [PATCH] exec arbitrary commands --- sergio.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sergio.py b/sergio.py index 8030497..cfb9c68 100755 --- a/sergio.py +++ b/sergio.py @@ -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)