exec arbitrary commands
This commit is contained in:
parent
3ded0784be
commit
ee70ecb7bf
1 changed files with 13 additions and 0 deletions
13
sergio.py
13
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)
|
||||
|
|
Loading…
Reference in a new issue