use super::daemon_utils::daemon_base_url;
use super::index_resolve::{print_index_header, resolve_index};
use super::reindex_engine::run_reindex_opts;
use crate::detect::detect_project;
use anyhow::Result;
pub async fn handle_reindex(
explicit_index: &Option<String>,
path: Option<std::path::PathBuf>,
timeout: Option<u64>,
) -> Result<()> {
let (index_id, warned) = resolve_index(explicit_index);
print_index_header(&index_id, warned);
crate::commands::daemon_guard::ensure_daemon_running_for_indexing(&daemon_base_url()).await?;
let reindex_path = path.unwrap_or_else(|| {
let cwd = std::env::current_dir().unwrap_or_default();
detect_project(&cwd).root_path
});
let (timeout_secs, timeout_explicit) = match timeout {
Some(n) => (n, true),
None => (0, false),
};
run_reindex_opts(&index_id, &reindex_path, timeout_secs, timeout_explicit).await
}