fix that the cli still used the DEFAULT_SOCKET Const, give better error message when no browser found adding test for client and update cli test, and update version and readme
This commit is contained in:
+3
-5
@@ -124,7 +124,7 @@ main.add_command(search_group)
|
||||
def cmd_clients():
|
||||
"""Show connected browser clients."""
|
||||
import json as _json
|
||||
from browser_cli.client import REGISTRY_PATH, DEFAULT_SOCKET
|
||||
from browser_cli.client import REGISTRY_PATH
|
||||
|
||||
# Build a map of profile → socket path from the registry
|
||||
profiles: dict[str, str] = {}
|
||||
@@ -133,8 +133,6 @@ def cmd_clients():
|
||||
profiles = _json.loads(REGISTRY_PATH.read_text())
|
||||
except Exception:
|
||||
pass
|
||||
if not profiles:
|
||||
profiles = {"default": DEFAULT_SOCKET}
|
||||
|
||||
all_clients = []
|
||||
for profile_name, sock_path in profiles.items():
|
||||
@@ -148,7 +146,7 @@ def cmd_clients():
|
||||
all_clients.append({"profile": profile_name, "name": "—", "version": "—", "platform": "disconnected"})
|
||||
|
||||
if not all_clients:
|
||||
console.print("[yellow]No browser clients found[/yellow]")
|
||||
console.print("[yellow]No browser clients found. Start a browser with the extension enabled first.[/yellow]")
|
||||
sys.exit(1)
|
||||
|
||||
from rich.table import Table
|
||||
@@ -158,7 +156,7 @@ def cmd_clients():
|
||||
table.add_column("Version")
|
||||
table.add_column("Platform")
|
||||
for c in all_clients:
|
||||
table.add_row(c.get("profile", "default"), c.get("name", ""), c.get("version", ""), c.get("platform", ""))
|
||||
table.add_row(c.get("profile", ""), c.get("name", ""), c.get("version", ""), c.get("platform", ""))
|
||||
console.print(table)
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ Profile selection order:
|
||||
1. Explicit `profile` argument to send_command()
|
||||
2. BROWSER_CLI_PROFILE environment variable
|
||||
3. First entry in /tmp/.browser_cli/registry.json
|
||||
4. Fallback: /tmp/.browser_cli/default.sock
|
||||
4. Otherwise, no browser can be resolved automatically
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
@@ -18,7 +18,6 @@ from typing import Any
|
||||
|
||||
SOCKET_DIR = Path("/tmp/.browser_cli")
|
||||
REGISTRY_PATH = SOCKET_DIR / "registry.json"
|
||||
DEFAULT_SOCKET = str(SOCKET_DIR / "default.sock")
|
||||
|
||||
|
||||
class BrowserNotConnected(Exception):
|
||||
@@ -64,7 +63,11 @@ def _resolve_socket(profile: str | None = None) -> str:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return DEFAULT_SOCKET
|
||||
raise BrowserNotConnected(
|
||||
"Cannot resolve a browser socket automatically.\n"
|
||||
"Make sure the browser is running with the browser-cli extension enabled,\n"
|
||||
"or pass --browser <alias> / set BROWSER_CLI_PROFILE to a known alias."
|
||||
)
|
||||
|
||||
|
||||
def send_command(command: str, args: dict | None = None, profile: str | None = None) -> Any:
|
||||
|
||||
Reference in New Issue
Block a user