use clap::{Args, Subcommand};
use crate::adapters::browser::{
RegistrationStatus, install_native_host, native_host_status, uninstall_native_host,
};
use crate::cli::error::CliError;
#[derive(Debug, Args)]
pub struct BrowserArgs {
#[command(subcommand)]
command: BrowserCommand,
}
#[derive(Debug, Subcommand)]
enum BrowserCommand {
Install {
#[arg(long)]
extension_id: String,
},
Status,
Uninstall,
}
pub(crate) fn execute(args: &BrowserArgs) -> Result<(), CliError> {
match &args.command {
BrowserCommand::Install { extension_id } => {
let path = install_native_host(extension_id).map_err(CliError::BrowserRegistration)?;
println!("✓ Native messaging host registered.");
println!("Manifest: {}", path.display());
}
BrowserCommand::Status => {
match native_host_status().map_err(CliError::BrowserRegistration)? {
RegistrationStatus::Missing => {
println!("Native messaging host is not registered.");
}
RegistrationStatus::Registered => {
println!("✓ Native messaging host is registered.");
}
RegistrationStatus::Stale => {
println!("✗ Native messaging registration is stale.");
}
}
}
BrowserCommand::Uninstall => {
let removed = uninstall_native_host().map_err(CliError::BrowserRegistration)?;
if removed {
println!("✓ Native messaging host unregistered.");
} else {
println!("Native messaging host is not registered.");
}
}
}
Ok(())
}