From 60c26377845c050212d1e7d836c682bf1bc6eb09 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 15 Oct 2020 18:11:27 +0200 Subject: [PATCH] Enhanced run_flaschengeist --- run_flaschengeist | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/run_flaschengeist b/run_flaschengeist index d69c3f5..4a89b5d 100644 --- a/run_flaschengeist +++ b/run_flaschengeist @@ -1,23 +1,38 @@ #!/usr/bin/python3 -from flaschengeist.app import create_app, install_all -import bjoern +import sys import argparse +import bjoern + + +def install(arguments): + from flaschengeist.app import create_app, install_all + app = create_app() + with app.app_context(): + install_all() + + +def run(arguments): + from flaschengeist.app import create_app + app = create_app() + with app.app_context(): + if arguments.debug: + app.run(arguments.host, arguments.port, debug=True) + else: + bjoern.run(app, arguments.host, arguments.port, reuse_port=True) if __name__ == '__main__': + # create the top-level parser parser = argparse.ArgumentParser() - parser.add_argument("--host", help="set hostname to listen on", default="127.0.0.1") - parser.add_argument("--port", help="set port to listen on", type=int, default=5000) - parser.add_argument("--debug", help="run in debug mode", action="store_true") - parser.add_argument("--install", help="installer", action="store_true") - args = parser.parse_args() + subparsers = parser.add_subparsers(help='sub-command help', dest="sub_command") + subparsers.required = True + parser_run = subparsers.add_parser('run', help='run flaschengeist') + parser_run.set_defaults(func=run) + parser_run.add_argument("--host", help="set hostname to listen on", default="127.0.0.1") + parser_run.add_argument("--port", help="set port to listen on", type=int, default=5000) + parser_run.add_argument("--debug", help="run in debug mode", action="store_true") + parser_install = subparsers.add_parser('install', help='run database setup for flaschengeist and all installed plugins') + parser_install.set_defaults(func=install) - app = create_app() - if args.install: - with app.app_context(): - install_all() - else: - if args.debug: - app.run(args.host, args.port, debug=True) - else: - bjoern.run(app, args.host, args.port, reuse_port=True) + args = parser.parse_args() + args.func(args)