from __future__ import annotations import json import click from browser_cli.command_security import assert_command_allowed from browser_cli.commands import command_policy_from_options, command_policy_options, client_from_ctx, handle_errors @click.command("command") @click.argument("name") @click.argument("args_json", required=False, default="{}") @command_policy_options @handle_errors def cmd_command(name, args_json, allow_read_page, allow_control, allow_dangerous, allow_keys, allow_all): """Send a raw browser-cli wire command and print JSON.""" policy = command_policy_from_options(allow_read_page=allow_read_page, allow_control=allow_control, allow_dangerous=allow_dangerous, allow_keys=allow_keys, allow_all=allow_all) assert_command_allowed(name, policy) args = json.loads(args_json) if args_json else {} result = client_from_ctx().command(name, args) click.echo(json.dumps(result, indent=2, default=str))