From e91096c535fc9c81f96bae4eabbf83e8a91c8c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 19 Apr 2024 13:23:56 +0200 Subject: [PATCH] feat: remove magic argument parser from lnbits command (#2448) got the idea from: https://github.com/lnbits/lnbits/issues/2447 arguments it should be explicity allowed with `click` and a description should be added like here. --- lnbits/server.py | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/lnbits/server.py b/lnbits/server.py index 54f33f987..66ef7464f 100644 --- a/lnbits/server.py +++ b/lnbits/server.py @@ -24,14 +24,16 @@ from lnbits.settings import set_cli_settings, settings ) @click.option("--ssl-keyfile", default=None, help="Path to SSL keyfile") @click.option("--ssl-certfile", default=None, help="Path to SSL certificate") -@click.pass_context +@click.option( + "--reload", is_flag=True, default=False, help="Enable auto-reload for development" +) def main( - ctx, port: int, host: str, forwarded_allow_ips: str, ssl_keyfile: str, ssl_certfile: str, + reload: bool, ): """Launched with `poetry run lnbits` at root level""" @@ -46,23 +48,6 @@ def main( set_cli_settings(host=host, port=port, forwarded_allow_ips=forwarded_allow_ips) - # this beautiful beast parses all command line arguments and - # passes them to the uvicorn server - # TODO: why is this needed? it would be better only to rely on the commands options - d = {} - for a in ctx.args: - item = a.split("=") - if len(item) > 1: # argument like --key=value - print(a, item) - d[item[0].strip("--").replace("-", "_")] = ( # noqa: B005 - int(item[1]) # need to convert to int if it's a number - if item[1].isdigit() - else item[1] - ) - else: - # argument like --key - d[a.strip("--")] = True # noqa: B005 - while True: config = uvicorn.Config( "lnbits.__main__:app", @@ -72,7 +57,7 @@ def main( forwarded_allow_ips=forwarded_allow_ips, ssl_keyfile=ssl_keyfile, ssl_certfile=ssl_certfile, - **d + reload=reload or False, ) server = uvicorn.Server(config=config)