utils/src/cli.py

31 lines
1.2 KiB
Python
Raw Normal View History

2022-07-22 15:24:11 -04:00
import code
import argparse
import importlib
import sys
BANNER = """
. o8o oooo o8o . o8o
.o8 `"' `888 `"' .o8 `"'
oooo oooo .o888oo oooo 888 oooo .o888oo oooo .ooooo. .oooo.o
`888 `888 888 `888 888 `888 888 `888 d88' `88b d88( "8
888 888 888 888 888 888 888 888 888ooo888 `"Y88b.
888 888 888 . 888 888 888 888 . 888 888 .o o. )88b
`V88V"V8P' "888" o888o o888o o888o "888" o888o `Y8bod8P' 8""888P'
"""
def main():
parser = argparse.ArgumentParser(
description='Run a specific script by name. If no name is provided, start a REPL.'
)
parser.add_argument('user_input', type=str, nargs='*',
help='The name of the script that you want to run plus any arguments for that script.')
args = parser.parse_args()
user_input = args.user_input
if len(user_input) == 0:
code.interact(banner=BANNER, local=locals())
else:
command_name = user_input.pop(0)
module = importlib.import_module(f"src.commands.{command_name}")
sys.exit(module.main(user_input))