2025-06-23 20:59:49 +02:00
|
|
|
use crate::errors::NyxResult;
|
2025-06-16 16:46:22 +02:00
|
|
|
use crate::utils::get_project_info;
|
2025-06-24 20:27:06 +02:00
|
|
|
use console::style;
|
|
|
|
|
use std::{env, fs};
|
2025-06-16 16:46:22 +02:00
|
|
|
|
2025-06-24 20:27:06 +02:00
|
|
|
pub fn handle(project: Option<String>, all: bool, config_dir: &std::path::Path) -> NyxResult<()> {
|
2025-06-16 16:46:22 +02:00
|
|
|
if all {
|
2025-06-23 19:37:19 +02:00
|
|
|
println!("{}", style("Cleaning all indexes...").cyan().bold());
|
2025-06-16 16:46:22 +02:00
|
|
|
if config_dir.exists() {
|
|
|
|
|
fs::remove_dir_all(config_dir)?;
|
|
|
|
|
fs::create_dir_all(config_dir)?;
|
|
|
|
|
}
|
2025-06-23 19:37:19 +02:00
|
|
|
println!("{}", style("✔ All indexes cleaned").green().bold());
|
2025-06-16 16:46:22 +02:00
|
|
|
} else if let Some(proj_name) = project {
|
2025-06-28 17:36:14 +02:00
|
|
|
let db_path = config_dir.join(format!("{proj_name}.sqlite"));
|
2025-06-16 16:46:22 +02:00
|
|
|
if db_path.exists() {
|
|
|
|
|
fs::remove_file(&db_path)?;
|
2025-06-24 20:27:06 +02:00
|
|
|
println!(
|
|
|
|
|
"{} {}",
|
|
|
|
|
style("✔ Cleaned index for").green(),
|
|
|
|
|
style(&proj_name).white().bold()
|
|
|
|
|
);
|
2025-06-16 16:46:22 +02:00
|
|
|
} else {
|
2025-06-24 20:27:06 +02:00
|
|
|
println!(
|
|
|
|
|
"{} {}",
|
|
|
|
|
style("✖ No index found for").red(),
|
|
|
|
|
style(&proj_name).white().bold()
|
|
|
|
|
);
|
2025-06-16 16:46:22 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let current_dir = env::current_dir()?;
|
|
|
|
|
let (project_name, db_path) = get_project_info(¤t_dir, config_dir)?;
|
|
|
|
|
|
|
|
|
|
if db_path.exists() {
|
|
|
|
|
fs::remove_file(&db_path)?;
|
2025-06-24 20:27:06 +02:00
|
|
|
println!(
|
|
|
|
|
"{} {}",
|
|
|
|
|
style("✔ Cleaned index for").green(),
|
|
|
|
|
style(&project_name).white().bold()
|
|
|
|
|
);
|
2025-06-16 16:46:22 +02:00
|
|
|
} else {
|
2025-06-24 20:27:06 +02:00
|
|
|
println!(
|
|
|
|
|
"{} {}",
|
|
|
|
|
style("✖ No index found for current project").red(),
|
|
|
|
|
style(&project_name).white().bold()
|
|
|
|
|
);
|
2025-06-16 16:46:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 19:37:19 +02:00
|
|
|
std::process::exit(0);
|
2025-06-24 20:27:06 +02:00
|
|
|
}
|