forked from
stavola.xyz/mlf
A human-friendly DSL for ATProto Lexicons
1use crate::config::{init_mlf_cache, MlfConfig};
2use std::io::Write;
3
4pub fn run_init(skip_prompts: bool) -> Result<(), std::io::Error> {
5 let current_dir = std::env::current_dir()?;
6 let config_path = current_dir.join("mlf.toml");
7
8 // Check if mlf.toml already exists
9 if config_path.exists() {
10 eprintln!("mlf.toml already exists in current directory");
11 eprintln!("Remove it first if you want to reinitialize");
12 return Err(std::io::Error::new(
13 std::io::ErrorKind::AlreadyExists,
14 "mlf.toml already exists",
15 ));
16 }
17
18 if !skip_prompts {
19 println!("Initialize MLF project in {}?", current_dir.display());
20 println!("This will create:");
21 println!(" - mlf.toml (project configuration)");
22 println!(" - .mlf/ (cache directory for fetched lexicons)");
23 println!();
24 print!("Continue? (y/n): ");
25 std::io::stdout().flush()?;
26
27 let mut input = String::new();
28 std::io::stdin().read_line(&mut input)?;
29
30 if input.trim().to_lowercase() != "y" {
31 println!("Cancelled");
32 return Ok(());
33 }
34 }
35
36 // Create default mlf.toml
37 let config = MlfConfig::default();
38 config
39 .save(&config_path)
40 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
41
42 println!("✓ Created mlf.toml");
43
44 // Initialize .mlf directory
45 init_mlf_cache(¤t_dir)?;
46 println!("✓ Initialized .mlf/ directory");
47
48 println!();
49 println!("Project initialized successfully!");
50 println!();
51 println!("Next steps:");
52 println!(" 1. Create MLF files in ./lexicons/");
53 println!(" 2. Fetch dependencies: mlf fetch <namespace> --save");
54 println!(" 3. Check your lexicons: mlf check");
55 println!(" 4. Generate code: mlf generate");
56
57 Ok(())
58}