|
1 | | -use lino_arguments::Parser; |
| 1 | +//! CLI entrypoint for docker-git-browser-connection |
| 2 | +//! |
| 3 | +//! Usage (из коробки): |
| 4 | +//! docker-git-browser-connection start --project myproj |
| 5 | +//! |
| 6 | +//! This binary is what MCP Playwright / Hermes / docker-git entrypoints invoke |
| 7 | +//! to guarantee a single unified browser (noVNC + CDP). |
2 | 8 |
|
3 | | -use example_sum_package_name::sum; |
| 9 | +use clap::{Parser, Subcommand}; |
| 10 | +use docker_git_browser_connection::{BrowserConnection, BrowserInfo}; |
4 | 11 |
|
5 | | -#[derive(Parser, Debug)] |
6 | | -#[command(name = "example-sum-package-name", about = "Sum two numbers")] |
7 | | -struct Args { |
8 | | - #[arg(long, env = "A", default_value = "0", allow_hyphen_values = true)] |
9 | | - a: i64, |
| 12 | +#[derive(Parser)] |
| 13 | +#[command(name = "docker-git-browser-connection", version, about = "Unified noVNC + CDP browser for docker-git, MCP Playwright and Hermes (per #347)")] |
| 14 | +struct Cli { |
| 15 | + #[command(subcommand)] |
| 16 | + command: Commands, |
| 17 | +} |
10 | 18 |
|
11 | | - #[arg(long, env = "B", default_value = "0", allow_hyphen_values = true)] |
12 | | - b: i64, |
| 19 | +#[derive(Subcommand)] |
| 20 | +enum Commands { |
| 21 | + /// Start (or reuse) the single browser container for a project |
| 22 | + Start { |
| 23 | + #[arg(long)] |
| 24 | + project: String, |
| 25 | + }, |
| 26 | + /// Show status / URLs for the project's browser |
| 27 | + Status { |
| 28 | + #[arg(long)] |
| 29 | + project: String, |
| 30 | + }, |
13 | 31 | } |
14 | 32 |
|
15 | | -fn main() { |
16 | | - let args = Args::parse(); |
17 | | - println!("{}", sum(args.a, args.b)); |
| 33 | +#[tokio::main] |
| 34 | +async fn main() -> anyhow::Result<()> { |
| 35 | + env_logger::init(); |
| 36 | + |
| 37 | + let cli = Cli::parse(); |
| 38 | + |
| 39 | + let conn = BrowserConnection::new()?; |
| 40 | + |
| 41 | + match cli.command { |
| 42 | + Commands::Start { project } => { |
| 43 | + let info: BrowserInfo = conn.start_browser(&project).await?; |
| 44 | + println!("Browser started for project: {}", info.project_id); |
| 45 | + println!("Container: {}", info.container_name); |
| 46 | + println!("noVNC: {}", info.novnc_url); |
| 47 | + println!("CDP (for MCP Playwright / Hermes): {}", info.cdp_url); |
| 48 | + println!("Use the CDP URL in your MCP Playwright config to get automatic noVNC."); |
| 49 | + } |
| 50 | + Commands::Status { project } => { |
| 51 | + let novnc = conn.get_novnc_url(&project); |
| 52 | + let cdp = conn.get_cdp_url(&project); |
| 53 | + println!("noVNC: {}", novnc); |
| 54 | + println!("CDP: {}", cdp); |
| 55 | + println!("Invariant check: {}", conn.is_single_browser_session(&cdp, &novnc)); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + Ok(()) |
18 | 60 | } |
0 commit comments