"""CLI entrypoint for cclog."""

import webbrowser
from pathlib import Path

import click


@click.command()
@click.option("--port", "-p", default=9117, help="Port to serve the web UI on")
@click.option("--claude-home", type=click.Path(exists=True), help="Path to Claude home directory")
@click.option("--no-open", is_flag=True, help="Don't open browser automatically")
@click.option("--host", default="127.0.0.1", help="Host to bind to")
def main(port: int, claude_home: str | None, no_open: bool, host: str):
    """Browse, search, and analyze your Claude Code conversation history."""
    import uvicorn
    from .app import create_app

    home = Path(claude_home) if claude_home else None
    app = create_app(claude_home=home)

    if not no_open:
        webbrowser.open(f"http://localhost:{port}")

    uvicorn.run(app, host=host, port=port, log_level="info")


if __name__ == "__main__":
    main()
