use crate::paths;
use anyhow::{anyhow, Context, Result};
use std::path::Path;
pub fn check_project_initialized(project_root: &Path) -> Result<()> {
let config_file = project_root.join(paths::PROJECT_CONFIG);
if !config_file.exists() {
return Err(anyhow!(
"Not in a Mecha10 project directory.\n\
Run 'mecha10 init' to create a new project."
));
}
Ok(())
}
#[allow(dead_code)] pub async fn check_redis_connection(redis_url: &str) -> Result<()> {
let client = redis::Client::open(redis_url).context("Failed to create Redis client")?;
let mut conn = client
.get_multiplexed_async_connection()
.await
.context("Failed to connect to Redis")?;
redis::cmd("PING")
.query_async::<String>(&mut conn)
.await
.context("Failed to ping Redis")?;
Ok(())
}
pub fn validate_node_names(requested_nodes: &[String], available_nodes: &[String]) -> Result<Vec<String>> {
let mut invalid = Vec::new();
for node in requested_nodes {
if !available_nodes.contains(node) {
invalid.push(node.clone());
}
}
if !invalid.is_empty() {
return Err(anyhow!(
"Unknown nodes: {}\nAvailable nodes: {}",
invalid.join(", "),
available_nodes.join(", ")
));
}
Ok(requested_nodes.to_vec())
}