"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/
Python
refactor: simplify Path conversion and persist https in save_config
pyxl1cf993dc97d4
diff --git a/adguardhome/agent-harness/cli_anything/adguardhome/adguardhome_cli.py b/adguardhome/agent-harness/cli_anything/adguardhome/adguardhome_cli.pyindex c165d289d..1d2cd77a9 100644--- a/adguardhome/agent-harness/cli_anything/adguardhome/adguardhome_cli.py+++ b/adguardhome/agent-harness/cli_anything/adguardhome/adguardhome_cli.py@@ -69,14 +69,15 @@ def cli(ctx: click.Context, host, port, username, password, config_path, use_htt"""cli-anything-adguardhome - control AdGuardHome from the command line."""ctx.ensure_object(dict)- cfg = project.load_config(Path(config_path) if config_path else None)+ config_path_obj = Path(config_path) if config_path else None+ cfg = project.load_config(config_path_obj)ctx.obj["host"] = host or cfg["host"]ctx.obj["port"] = port or cfg["port"]ctx.obj["username"] = username or cfg["username"]ctx.obj["password"] = password or cfg["password"]ctx.obj["use_https"] = use_https or cfg.get("https", False)ctx.obj["as_json"] = as_json- ctx.obj["config_path"] = Path(config_path) if config_path else None+ ctx.obj["config_path"] = config_path_objif ctx.invoked_subcommand is None:ctx.invoke(repl)@@ -177,6 +178,7 @@ def config_save(ctx: click.Context):path = project.save_config(host=obj["host"], port=obj["port"],username=obj["username"], password=obj["password"],+ https=obj.get("use_https", False),config_path=obj.get("config_path"),)result = {"saved": str(path)}diff --git a/adguardhome/agent-harness/cli_anything/adguardhome/core/project.py b/adguardhome/agent-harness/cli_anything/adguardhome/core/project.pyindex 801765537..f7fc9b61e 100644--- a/adguardhome/agent-harness/cli_anything/adguardhome/core/project.py+++ b/adguardhome/agent-harness/cli_anything/adguardhome/core/project.py@@ -40,11 +40,13 @@ def load_config(config_path: Path | None = None) -> dict:def save_config(host: str, port: int, username: str, password: str,+ https: bool = False,config_path: Path | None = None) -> Path:"""Save connection settings to config file."""path = config_path or DEFAULT_CONFIG_PATHpath.parent.mkdir(parents=True, exist_ok=True)- data = {"host": host, "port": port, "username": username, "password": password}+ data = {"host": host, "port": port, "username": username, "password": password,+ "https": https}with open(path, "w") as f:json.dump(data, f, indent=2)return path