1use clap::Parser;
2use std::path::PathBuf;
3
4#[derive(Parser, Debug, Clone)]
6#[command(name = "bindings-generat")]
7#[command(version, about, long_about = None)]
8pub struct Cli {
9 #[arg(value_name = "SOURCE")]
18 pub source: String,
19
20 #[arg(short = 'o', long, value_name = "PATH")]
22 pub output: Option<PathBuf>,
23
24 #[arg(long, value_name = "GLOB")]
26 pub headers: Option<String>,
27
28 #[arg(long, value_name = "NAME")]
30 pub lib_name: Option<String>,
31
32 #[arg(long, value_name = "MODEL", default_value = "deepseek-coder:6.7b")]
34 pub model: String,
35
36 #[arg(long)]
38 pub no_llm: bool,
39
40 #[arg(short = 'i', long)]
42 pub interactive: bool,
43
44 #[arg(long)]
46 pub non_interactive: bool,
47
48 #[arg(long, value_name = "PROFILE", default_value = "ergonomic")]
50 pub style: String,
51
52 #[arg(long, value_name = "PATH")]
54 pub cache_dir: Option<PathBuf>,
55
56 #[arg(long)]
58 pub dry_run: bool,
59
60 #[arg(short = 'v', long)]
62 pub verbose: bool,
63}
64
65impl Cli {
66 pub fn get_output_dir(&self) -> PathBuf {
68 self.output
69 .clone()
70 .unwrap_or_else(|| PathBuf::from("./bindings-output"))
71 }
72
73 pub fn validate(&self) -> anyhow::Result<()> {
75 if !self.source.starts_with("http://") && !self.source.starts_with("https://") {
77 let path = PathBuf::from(&self.source);
78 if !path.exists() {
79 anyhow::bail!("Source path does not exist: {}", self.source);
80 }
81 }
82
83 let output_path = self.get_output_dir();
84 if output_path.exists() && !self.dry_run {
85 anyhow::bail!(
86 "Output path already exists: {}. Please choose a different location or remove the existing directory.",
87 output_path.display()
88 );
89 }
90
91 if self.interactive && self.non_interactive {
92 anyhow::bail!("Cannot use both --interactive and --non-interactive");
93 }
94
95 Ok(())
96 }
97}
98
99#[cfg(test)]
100mod tests {
101 use super::*;
102
103 #[test]
104 fn test_get_output_dir_default() {
105 let cli = Cli {
106 source: "test.zip".to_string(),
107 output: None,
108 headers: None,
109 lib_name: None,
110 model: "qwen2.5-coder:1.5b".to_string(),
111 no_llm: false,
112 interactive: false,
113 non_interactive: false,
114 style: "ergonomic".to_string(),
115 cache_dir: None,
116 dry_run: false,
117 verbose: false,
118 };
119
120 assert_eq!(cli.get_output_dir(), PathBuf::from("./bindings-output"));
121 }
122
123 #[test]
124 fn test_get_output_dir_custom() {
125 let cli = Cli {
126 source: "test.zip".to_string(),
127 output: Some(PathBuf::from("/custom/path")),
128 headers: None,
129 lib_name: None,
130 model: "qwen2.5-coder:1.5b".to_string(),
131 no_llm: false,
132 interactive: false,
133 non_interactive: false,
134 style: "ergonomic".to_string(),
135 cache_dir: None,
136 dry_run: false,
137 verbose: false,
138 };
139
140 assert_eq!(cli.get_output_dir(), PathBuf::from("/custom/path"));
141 }
142}