|
1 | 1 | use engraph::config; |
2 | 2 | use engraph::indexer; |
| 3 | +use engraph::profile; |
3 | 4 | use engraph::search; |
4 | 5 | use engraph::store; |
5 | 6 |
|
@@ -64,6 +65,15 @@ enum Command { |
64 | 65 | #[arg(long)] |
65 | 66 | all: bool, |
66 | 67 | }, |
| 68 | + |
| 69 | + /// Initialize vault profile with auto-detection. |
| 70 | + Init { |
| 71 | + /// Path to the vault (defaults to current directory). |
| 72 | + path: Option<PathBuf>, |
| 73 | + }, |
| 74 | + |
| 75 | + /// Interactively configure vault profile. |
| 76 | + Configure, |
67 | 77 | } |
68 | 78 |
|
69 | 79 | /// Check whether an index has been built by looking for engraph.db in data_dir. |
@@ -214,6 +224,78 @@ fn main() -> Result<()> { |
214 | 224 | } |
215 | 225 | } |
216 | 226 | } |
| 227 | + |
| 228 | + Command::Init { path } => { |
| 229 | + // Resolve vault path: CLI arg > config > cwd. |
| 230 | + cfg.merge_vault_path(path); |
| 231 | + let vault_path = match &cfg.vault_path { |
| 232 | + Some(p) => p.clone(), |
| 233 | + None => std::env::current_dir()?, |
| 234 | + }; |
| 235 | + let vault_path = vault_path.canonicalize().unwrap_or(vault_path); |
| 236 | + |
| 237 | + println!("Detecting vault profile for: {}", vault_path.display()); |
| 238 | + |
| 239 | + let vault_type = profile::detect_vault_type(&vault_path); |
| 240 | + let structure = profile::detect_structure(&vault_path)?; |
| 241 | + let stats = profile::scan_vault_stats(&vault_path)?; |
| 242 | + |
| 243 | + // Print detection results. |
| 244 | + println!(); |
| 245 | + println!(" Vault type: {:?}", vault_type); |
| 246 | + println!(" Structure: {:?}", structure.method); |
| 247 | + if let Some(ref inbox) = structure.folders.inbox { |
| 248 | + println!(" inbox: {}", inbox); |
| 249 | + } |
| 250 | + if let Some(ref projects) = structure.folders.projects { |
| 251 | + println!(" projects: {}", projects); |
| 252 | + } |
| 253 | + if let Some(ref areas) = structure.folders.areas { |
| 254 | + println!(" areas: {}", areas); |
| 255 | + } |
| 256 | + if let Some(ref resources) = structure.folders.resources { |
| 257 | + println!(" resources: {}", resources); |
| 258 | + } |
| 259 | + if let Some(ref archive) = structure.folders.archive { |
| 260 | + println!(" archive: {}", archive); |
| 261 | + } |
| 262 | + if let Some(ref templates) = structure.folders.templates { |
| 263 | + println!(" templates: {}", templates); |
| 264 | + } |
| 265 | + if let Some(ref daily) = structure.folders.daily { |
| 266 | + println!(" daily: {}", daily); |
| 267 | + } |
| 268 | + if let Some(ref people) = structure.folders.people { |
| 269 | + println!(" people: {}", people); |
| 270 | + } |
| 271 | + println!(); |
| 272 | + println!(" Total .md files: {}", stats.total_files); |
| 273 | + println!(" With frontmatter: {}", stats.files_with_frontmatter); |
| 274 | + println!(" Wikilinks: {}", stats.wikilink_count); |
| 275 | + println!(" Unique tags: {}", stats.unique_tags); |
| 276 | + println!(" Folders: {}", stats.folder_count); |
| 277 | + println!(" Max folder depth: {}", stats.folder_depth); |
| 278 | + |
| 279 | + let vault_profile = profile::VaultProfile { |
| 280 | + vault_path, |
| 281 | + vault_type, |
| 282 | + structure, |
| 283 | + stats, |
| 284 | + }; |
| 285 | + |
| 286 | + // Ensure data dir exists and write vault.toml. |
| 287 | + std::fs::create_dir_all(&data_dir)?; |
| 288 | + profile::write_vault_toml(&vault_profile, &data_dir)?; |
| 289 | + |
| 290 | + println!(); |
| 291 | + println!("Wrote {}", data_dir.join("vault.toml").display()); |
| 292 | + } |
| 293 | + |
| 294 | + Command::Configure => { |
| 295 | + println!( |
| 296 | + "Interactive configuration not yet implemented. Run 'engraph init' for auto-detection." |
| 297 | + ); |
| 298 | + } |
217 | 299 | } |
218 | 300 |
|
219 | 301 | Ok(()) |
|
0 commit comments