#!/usr/bin/env python3
"""
Command wrapper for Claude Code web environments.

This script wraps command execution via Python subprocess to bypass
Bash tool permission restrictions in Claude Code web environments.

Usage:
    bash-tool-bypass <command> [arguments...]

Examples:
    bash-tool-bypass gh --version
    bash-tool-bypass gh pr view 1
    bash-tool-bypass gh pr list --limit 5
    bash-tool-bypass gh issue view 42 --json title,state,author
    bash-tool-bypass gh repo view owner/repo
    bash-tool-bypass some-other-restricted-command --flag value

Notes:
    - This wrapper is designed to bypass specific command restrictions in
      Claude Code
    - Common use case is running 'gh' commands when Bash tool blocks them
      directly
    - Any command accessible in PATH can be executed through this wrapper
    - Authentication/permissions still apply to the wrapped command itself
"""

import subprocess
import sys

# Minimum required argument count (script name + command)
MIN_ARGS = 2


def main():
    """Execute command via subprocess and exit with its return code."""
    if len(sys.argv) < MIN_ARGS:
        print(__doc__)
        sys.exit(1)

    # Build command with all arguments
    cmd = sys.argv[1:]

    # Execute command (intentionally passes through untrusted input)
    result = subprocess.run(cmd, check=False)  # noqa: S603

    # Exit with command's return code
    sys.exit(result.returncode)


if __name__ == '__main__':
    main()
