mirror of
https://github.com/lnbits/lnbits.git
synced 2025-04-07 19:38:13 +02:00
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.
This commit is contained in:
parent
e607ab7a3e
commit
e91096c535
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user