From 6a4384cbc71c08f34dbbedc201d29eafe5c85c04 Mon Sep 17 00:00:00 2001 From: retoor Date: Sat, 14 Dec 2024 18:27:52 +0100 Subject: [PATCH] Added argument parser. --- src/app/app.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/src/app/app.py b/src/app/app.py index 14c5ec2..07a31a1 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -2,7 +2,7 @@ import base64 import json import time import uuid - +import argparse import dataset from aiohttp import web @@ -243,8 +243,62 @@ class Application(WebDbApplication): content_type="application/json", ) + +argument_parser = argparse.ArgumentParser("Web service") +argument_parser.add_argument( + "--host", + default="0.0.0.0", + required=False + type=str, + help="Host to serve on." +) +argument_parser.add_argument( + "--port", + default=8888, + required=False, + type=int, + help="Port to serve on." +) +argument_parser.add_argument( + "--db-path", + default="sqlite:///:memory:", + required=False, + type=str, + help="SQLAlchemy db url. (e.g. sqlite:///app.db)" +) +argument_parser.add_argument( + "--basic-username", + default=None, + required=False, + type=str, + help="Basic Auth username." +) +argument_parser.add_argument( + "--basic-password", + default=None, + required=False, + type=str, + help="Basic Auth password." +) +argument_parser.add_argument( + "--db-web", + action="store_true", + help="Enable /db/* endpoints", + default=False, + type=bool +) + + + + def create_app(*args, **kwargs): - app = Application(*args, **kwargs) - + global argument_parser + args = argument_parser.parse_args() + app = create_app(db_path=args.db_path,basic_username=args.basic_username,basic_password=args.basic_password) + return app + + +def main(): + app = create_app() return app