use anyhow::Result;
use browser_control::cli::{list, set};
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[command(name = "browser-control", version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand, Debug)]
enum Command {
ListInstalled {
#[arg(long)]
json: bool,
},
ListRunning {
#[arg(long)]
json: bool,
},
Start {
browser: Option<String>,
#[arg(long)]
headless: bool,
#[arg(long)]
profile: Option<std::path::PathBuf>,
#[arg(long)]
json: bool,
},
Mcp {
#[arg(env = "BROWSER_CONTROL")]
browser: Option<String>,
#[arg(long)]
playwright: bool,
},
Set {
#[arg(value_enum)]
key: set::Key,
value: Option<String>,
#[arg(long)]
json: bool,
},
Get {
#[arg(value_enum)]
key: set::Key,
#[arg(long)]
json: bool,
},
Unset {
#[arg(value_enum)]
key: set::Key,
#[arg(long)]
json: bool,
},
}
fn init_tracing() {
let filter = tracing_subscriber::EnvFilter::try_from_env("BROWSER_CONTROL_LOG")
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
tracing_subscriber::fmt()
.with_env_filter(filter)
.with_writer(std::io::stderr)
.init();
}
#[tokio::main]
async fn main() -> Result<()> {
init_tracing();
let cli = Cli::parse();
match cli.command {
Command::ListInstalled { json } => list::run_list_installed(json),
Command::ListRunning { json } => list::run_list_running(json),
Command::Start {
browser,
headless,
profile,
json,
} => browser_control::cli::start::run(browser, headless, profile, json).await,
Command::Mcp {
browser,
playwright,
} => browser_control::cli::mcp::run_cli(browser, playwright).await,
Command::Set { key, value, json } => set::run_set(key, value, json),
Command::Get { key, json } => set::run_get(key, json),
Command::Unset { key, json } => set::run_unset(key, json),
}
}