mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 07:17:17 +00:00
add exec to shell subcommand
This commit is contained in:
parent
791ce4f242
commit
41080c5ff8
@ -762,6 +762,7 @@ def _set_shell_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
|||||||
parser = root.add_parser("shell", help="envoke python shell",
|
parser = root.add_parser("shell", help="envoke python shell",
|
||||||
description="drop into python shell while having created application",
|
description="drop into python shell while having created application",
|
||||||
formatter_class=_formatter)
|
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.add_argument("-v", "--verbose", help=argparse.SUPPRESS, action="store_true")
|
||||||
parser.set_defaults(handler=handlers.Shell, lock=None, report=False)
|
parser.set_defaults(handler=handlers.Shell, lock=None, report=False)
|
||||||
return parser
|
return parser
|
||||||
|
@ -56,4 +56,7 @@ class Shell(Handler):
|
|||||||
# licensed by https://creativecommons.org/licenses/by-sa/3.0
|
# licensed by https://creativecommons.org/licenses/by-sa/3.0
|
||||||
path = Path(sys.prefix) / "share" / "ahriman" / "templates" / "shell"
|
path = Path(sys.prefix) / "share" / "ahriman" / "templates" / "shell"
|
||||||
StringPrinter(path.read_text(encoding="utf8")).print(verbose=False)
|
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)
|
||||||
|
@ -17,6 +17,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
|||||||
Returns:
|
Returns:
|
||||||
argparse.Namespace: generated arguments for these test cases
|
argparse.Namespace: generated arguments for these test cases
|
||||||
"""
|
"""
|
||||||
|
args.code = None
|
||||||
args.verbose = False
|
args.verbose = False
|
||||||
return args
|
return args
|
||||||
|
|
||||||
@ -33,6 +34,19 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
|||||||
application_mock.assert_called_once_with(local=pytest.helpers.anyvar(int))
|
application_mock.assert_called_once_with(local=pytest.helpers.anyvar(int))
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_eval(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must run command
|
||||||
|
"""
|
||||||
|
args = _default_args(args)
|
||||||
|
args.code = """print("hello world")"""
|
||||||
|
mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||||
|
application_mock = mocker.patch("code.InteractiveConsole.runcode")
|
||||||
|
|
||||||
|
Shell.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||||
|
application_mock.assert_called_once_with(args.code)
|
||||||
|
|
||||||
|
|
||||||
def test_run_verbose(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
def test_run_verbose(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must run command with verbose option
|
must run command with verbose option
|
||||||
|
Loading…
Reference in New Issue
Block a user