"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/
Python
fix: preserve server config when toggling log/filter settings
pyxl433c3cf880f8
diff --git a/adguardhome/agent-harness/cli_anything/adguardhome/adguardhome_cli.py b/adguardhome/agent-harness/cli_anything/adguardhome/adguardhome_cli.pyindex 1d2cd77a9..9b81b55b6 100644--- a/adguardhome/agent-harness/cli_anything/adguardhome/adguardhome_cli.py+++ b/adguardhome/agent-harness/cli_anything/adguardhome/adguardhome_cli.py@@ -556,9 +556,12 @@ def log_show(ctx: click.Context, limit: int, offset: int):@click.pass_contextdef log_config(ctx: click.Context, enabled, interval):client = make_client(ctx)- if enabled is not None:- output(log_core.set_log_config(client, enabled=enabled,- interval=interval or 90), ctx.obj["as_json"])+ if enabled is not None or interval is not None:+ current = log_core.get_log_config(client)+ effective_enabled = enabled if enabled is not None else current.get("enabled", True)+ effective_interval = interval if interval is not None else current.get("interval", 90)+ output(log_core.set_log_config(client, enabled=effective_enabled,+ interval=effective_interval), ctx.obj["as_json"])else:output(log_core.get_log_config(client), ctx.obj["as_json"])diff --git a/adguardhome/agent-harness/cli_anything/adguardhome/core/filtering.py b/adguardhome/agent-harness/cli_anything/adguardhome/core/filtering.pyindex daa7e9300..6daceef3e 100644--- a/adguardhome/agent-harness/cli_anything/adguardhome/core/filtering.py+++ b/adguardhome/agent-harness/cli_anything/adguardhome/core/filtering.py@@ -8,7 +8,9 @@ def get_status(client: AdGuardHomeClient) -> dict:def set_enabled(client: AdGuardHomeClient, enabled: bool) -> dict:- return client.post("/filtering/config", {"enabled": enabled, "interval": 24})+ current = get_status(client)+ interval = current.get("interval", 24)+ return client.post("/filtering/config", {"enabled": enabled, "interval": interval})def add_filter(client: AdGuardHomeClient, url: str, name: str,diff --git a/adguardhome/agent-harness/cli_anything/adguardhome/tests/test_core.py b/adguardhome/agent-harness/cli_anything/adguardhome/tests/test_core.pyindex 574c0d7a3..1855483f5 100644--- a/adguardhome/agent-harness/cli_anything/adguardhome/tests/test_core.py+++ b/adguardhome/agent-harness/cli_anything/adguardhome/tests/test_core.py@@ -175,11 +175,14 @@ class TestFiltering:def test_set_enabled(self):c = make_client()- resp = mock_response({})- with patch.object(c.session, "post", return_value=resp) as mock_post:- filtering.set_enabled(c, enabled=True)- body = mock_post.call_args.kwargs["json"]- assert body["enabled"] is True+ status_resp = mock_response({"enabled": False, "interval": 48})+ post_resp = mock_response({})+ with patch.object(c.session, "get", return_value=status_resp):+ with patch.object(c.session, "post", return_value=post_resp) as mock_post:+ filtering.set_enabled(c, enabled=True)+ body = mock_post.call_args.kwargs["json"]+ assert body["enabled"] is True+ assert body["interval"] == 48# ---------------------------------------------------------------------------