added config command line option
This commit is contained in:
parent
e6d4878636
commit
307a8e9819
@ -6,7 +6,8 @@ from datetime import datetime
|
|||||||
from typing import Callable, Any
|
from typing import Callable, Any
|
||||||
|
|
||||||
|
|
||||||
def loadSettings() -> dict:
|
def loadSettings(path: str | None) -> dict:
|
||||||
|
if path is None:
|
||||||
path = f"{os.path.expanduser('~')}/.config/dyn-gandi/config.json"
|
path = f"{os.path.expanduser('~')}/.config/dyn-gandi/config.json"
|
||||||
|
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
@ -99,8 +100,29 @@ def renewRecords(api: dict[str, dict[str, list[str]]], current_ip: str, log: Cal
|
|||||||
log(f"[ERROR][{domain}][{record}][{response.status_code}] {response.json()}")
|
log(f"[ERROR][{domain}][{record}][{response.status_code}] {response.json()}")
|
||||||
|
|
||||||
|
|
||||||
|
def parseArgv(argv: list[str]) -> dict[str, list[str]]:
|
||||||
|
cli_options = {}
|
||||||
|
buffer = None
|
||||||
|
|
||||||
|
for arg in argv:
|
||||||
|
if arg.startswith('--'):
|
||||||
|
cli_options[arg.removeprefix('--')] = []
|
||||||
|
buffer = arg.removeprefix('--')
|
||||||
|
else:
|
||||||
|
cli_options[buffer].append(arg)
|
||||||
|
return cli_options
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
settings = loadSettings()
|
argv = os.sys.argv
|
||||||
|
options = {}
|
||||||
|
if len(argv) > 1:
|
||||||
|
options = parseArgv(argv[1:])
|
||||||
|
|
||||||
|
config_path = None
|
||||||
|
if 'config' in options:
|
||||||
|
config_path = options['config'][0]
|
||||||
|
|
||||||
|
settings = loadSettings(config_path)
|
||||||
log_path, ttl = settings['log_path'], settings['ttl']
|
log_path, ttl = settings['log_path'], settings['ttl']
|
||||||
def logger(x: str) -> Any: return log(x, log_path)
|
def logger(x: str) -> Any: return log(x, log_path)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user