use clap::Parser;
use std::path::PathBuf;
#[derive(Parser, Debug, Clone)]
#[command(name = "bindings-generat")]
#[command(version, about, long_about = None)]
pub struct Cli {
#[arg(value_name = "SOURCE")]
pub source: String,
#[arg(short = 'o', long, value_name = "PATH")]
pub output: Option<PathBuf>,
#[arg(long, value_name = "GLOB")]
pub headers: Option<String>,
#[arg(long, value_name = "NAME")]
pub lib_name: Option<String>,
#[arg(long, value_name = "MODEL", default_value = "deepseek-coder:6.7b")]
pub model: String,
#[arg(long)]
pub no_llm: bool,
#[arg(short = 'i', long)]
pub interactive: bool,
#[arg(long)]
pub non_interactive: bool,
#[arg(long, value_name = "PROFILE", default_value = "ergonomic")]
pub style: String,
#[arg(long, value_name = "PATH")]
pub cache_dir: Option<PathBuf>,
#[arg(long)]
pub dry_run: bool,
#[arg(short = 'v', long)]
pub verbose: bool,
}
impl Cli {
pub fn get_output_dir(&self) -> PathBuf {
self.output
.clone()
.unwrap_or_else(|| PathBuf::from("./bindings-output"))
}
pub fn validate(&self) -> anyhow::Result<()> {
if !self.source.starts_with("http://") && !self.source.starts_with("https://") {
let path = PathBuf::from(&self.source);
if !path.exists() {
anyhow::bail!("Source path does not exist: {}", self.source);
}
}
let output_path = self.get_output_dir();
if output_path.exists() && !self.dry_run {
anyhow::bail!(
"Output path already exists: {}. Please choose a different location or remove the existing directory.",
output_path.display()
);
}
if self.interactive && self.non_interactive {
anyhow::bail!("Cannot use both --interactive and --non-interactive");
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_output_dir_default() {
let cli = Cli {
source: "test.zip".to_string(),
output: None,
headers: None,
lib_name: None,
model: "qwen2.5-coder:1.5b".to_string(),
no_llm: false,
interactive: false,
non_interactive: false,
style: "ergonomic".to_string(),
cache_dir: None,
dry_run: false,
verbose: false,
};
assert_eq!(cli.get_output_dir(), PathBuf::from("./bindings-output"));
}
#[test]
fn test_get_output_dir_custom() {
let cli = Cli {
source: "test.zip".to_string(),
output: Some(PathBuf::from("/custom/path")),
headers: None,
lib_name: None,
model: "qwen2.5-coder:1.5b".to_string(),
no_llm: false,
interactive: false,
non_interactive: false,
style: "ergonomic".to_string(),
cache_dir: None,
dry_run: false,
verbose: false,
};
assert_eq!(cli.get_output_dir(), PathBuf::from("/custom/path"));
}
}