Your music, beautifully tracked. All yours. (coming soon) teal.fm
teal-fm atproto
at fix-compose-path 116 lines 4.0 kB view raw
1use anyhow::Result; 2use colored::*; 3 4use crate::config::TealConfig; 5use crate::DevCommands; 6 7pub async fn run(cmd: DevCommands, config: &TealConfig) -> Result<()> { 8 match cmd { 9 DevCommands::Setup { 10 skip_docker, 11 skip_db, 12 } => setup_dev_environment(skip_docker, skip_db, config).await, 13 DevCommands::Clean { all } => clean_dev_artifacts(all).await, 14 DevCommands::Dev { port, watch } => run_dev_server(port, watch, config).await, 15 DevCommands::Seed { count, data_type } => generate_seed_data(count, data_type, config).await, 16 } 17} 18 19async fn setup_dev_environment( 20 skip_docker: bool, 21 skip_db: bool, 22 config: &TealConfig, 23) -> Result<()> { 24 println!("{} Setting up development environment...", "🛠️".blue()); 25 println!(); 26 27 if !skip_docker { 28 println!("{} Docker Setup:", "🐳".blue()); 29 println!(" {} Checking Docker...", "".bold()); 30 31 // TODO: Check if Docker is installed and running 32 println!(" {} Docker check not implemented", "⚠️".yellow()); 33 println!(" {} Manually ensure Docker is running", "💡".blue()); 34 println!(); 35 } 36 37 if !skip_db { 38 println!("{} Database Setup:", "🗄️".blue()); 39 println!(" {} Database URL: {}", "".bold(), mask_db_url(&config.database.url)); 40 41 // TODO: Run database initialization and migrations 42 println!(" {} Database setup not implemented", "⚠️".yellow()); 43 println!(" {} Run: teal database init", "💡".blue()); 44 println!(" {} Run: teal database migrate", "💡".blue()); 45 println!(); 46 } 47 48 println!("{} Keys Setup:", "🔐".blue()); 49 let key_path = config.get_key_path(&config.crypto.default_key_name); 50 if key_path.exists() { 51 println!(" {} Default key already exists", "".green()); 52 } else { 53 println!(" {} Generating default key...", "".bold()); 54 // TODO: Auto-generate key 55 println!(" {} Run: teal crypto gen-key", "💡".blue()); 56 } 57 println!(); 58 59 println!("{} Development environment setup complete!", "".green()); 60 println!(); 61 println!("{} Next steps:", "💡".yellow()); 62 println!(" 1. teal crypto gen-key --name dev"); 63 println!(" 2. teal database init"); 64 println!(" 3. teal dev dev --watch"); 65 66 Ok(()) 67} 68 69async fn clean_dev_artifacts(all: bool) -> Result<()> { 70 println!("{} Cleaning development artifacts...", "🧹".blue()); 71 println!(); 72 73 let mut cleaned_items = Vec::new(); 74 75 // Clean logs 76 if let Ok(entries) = std::fs::read_dir("logs") { 77 let mut log_count = 0; 78 for entry in entries.flatten() { 79 if entry.path().extension().map_or(false, |ext| ext == "log") { 80 // TODO: Actually delete log files 81 log_count += 1; 82 } 83 } 84 if log_count > 0 { 85 cleaned_items.push(format!("{} log files", log_count)); 86 } 87 } 88 89 // Clean temporary files 90 if let Ok(entries) = std::fs::read_dir(".") { 91 let mut temp_count = 0; 92 for entry in entries.flatten() { 93 let path = entry.path(); 94 if let Some(name) = path.file_name().and_then(|n| n.to_str()) { 95 if name.starts_with("tmp_") || name.ends_with(".tmp") { 96 temp_count += 1; 97 } 98 } 99 } 100 if temp_count > 0 { 101 cleaned_items.push(format!("{} temporary files", temp_count)); 102 } 103 } 104 105 if all { 106 // Clean build artifacts 107 cleaned_items.push("build artifacts".to_string()); 108 println!(" {} Would clean: target/ directory", "".bold()); 109 110 // Clean Docker artifacts 111 cleaned_items.push("Docker artifacts".to_string()); 112 println!(" {} Would clean: Docker images and containers", "".bold()); 113 } 114 115 if cleaned_items.is_empty() { 116 println!("{} No artifacts to clean", "ℹ️".blue