add exec to shell subcommand

This commit is contained in:
2022-11-10 18:46:35 +02:00
parent 791ce4f242
commit 41080c5ff8
3 changed files with 19 additions and 1 deletions

View File

@ -762,6 +762,7 @@ def _set_shell_parser(root: SubParserAction) -> argparse.ArgumentParser:
parser = root.add_parser("shell", help="envoke python shell",
description="drop into python shell while having created application",
formatter_class=_formatter)
parser.add_argument("code", help="instead of dropping into shell, just execute the specified code", nargs="?")
parser.add_argument("-v", "--verbose", help=argparse.SUPPRESS, action="store_true")
parser.set_defaults(handler=handlers.Shell, lock=None, report=False)
return parser

View File

@ -56,4 +56,7 @@ class Shell(Handler):
# licensed by https://creativecommons.org/licenses/by-sa/3.0
path = Path(sys.prefix) / "share" / "ahriman" / "templates" / "shell"
StringPrinter(path.read_text(encoding="utf8")).print(verbose=False)
code.interact(local=locals())
if args.code is None:
code.interact(local=locals())
else:
code.InteractiveConsole(locals=locals()).runcode(args.code)