mod install;
mod socket;
mod uri;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(
name = "portal-handler",
version = "0.1.0",
about = "Forward les URIs nvim:// vers une instance Neovim active via RPC"
)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Debug, Subcommand)]
enum Commands {
Open {
uri: String,
#[arg(long, short = 's')]
socket: Option<String>,
},
Install {
#[arg(long)]
binary: Option<String>,
},
Uninstall,
List,
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Open { uri, socket } => {
uri::handle(&uri, socket.as_deref()).await?;
}
Commands::Install { binary } => {
let bin = binary.unwrap_or_else(|| {
std::env::current_exe()
.expect("impossible de lire le chemin du binaire courant")
.to_string_lossy()
.into_owned()
});
install::install(&bin)?;
println!("✓ handler nvim:// enregistré dans le système");
}
Commands::Uninstall => {
install::uninstall()?;
println!("✓ handler nvim:// dé-enregistré");
}
Commands::List => {
let sockets = socket::find_all();
if sockets.is_empty() {
println!("Aucune instance Neovim active trouvée.");
} else {
println!("Instances Neovim actives ({}) :", sockets.len());
for s in &sockets {
println!(" {}", s.display());
}
}
}
}
Ok(())
}