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
1 changed files with 5 additions and 20 deletions
|
|
@ -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-keyfile", default=None, help="Path to SSL keyfile")
|
||||||
@click.option("--ssl-certfile", default=None, help="Path to SSL certificate")
|
@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(
|
def main(
|
||||||
ctx,
|
|
||||||
port: int,
|
port: int,
|
||||||
host: str,
|
host: str,
|
||||||
forwarded_allow_ips: str,
|
forwarded_allow_ips: str,
|
||||||
ssl_keyfile: str,
|
ssl_keyfile: str,
|
||||||
ssl_certfile: str,
|
ssl_certfile: str,
|
||||||
|
reload: bool,
|
||||||
):
|
):
|
||||||
"""Launched with `poetry run lnbits` at root level"""
|
"""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)
|
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:
|
while True:
|
||||||
config = uvicorn.Config(
|
config = uvicorn.Config(
|
||||||
"lnbits.__main__:app",
|
"lnbits.__main__:app",
|
||||||
|
|
@ -72,7 +57,7 @@ def main(
|
||||||
forwarded_allow_ips=forwarded_allow_ips,
|
forwarded_allow_ips=forwarded_allow_ips,
|
||||||
ssl_keyfile=ssl_keyfile,
|
ssl_keyfile=ssl_keyfile,
|
||||||
ssl_certfile=ssl_certfile,
|
ssl_certfile=ssl_certfile,
|
||||||
**d
|
reload=reload or False,
|
||||||
)
|
)
|
||||||
|
|
||||||
server = uvicorn.Server(config=config)
|
server = uvicorn.Server(config=config)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue