mecha10_cli/dev/
validation.rs1use anyhow::{anyhow, Context, Result};
4use std::path::Path;
5
6pub fn check_project_initialized(project_root: &Path) -> Result<()> {
8 let config_file = project_root.join("mecha10.json");
9
10 if !config_file.exists() {
11 return Err(anyhow!(
12 "Not in a Mecha10 project directory.\n\
13 Run 'mecha10 init' to create a new project."
14 ));
15 }
16
17 Ok(())
18}
19
20#[allow(dead_code)] pub async fn check_redis_connection(redis_url: &str) -> Result<()> {
23 let client = redis::Client::open(redis_url).context("Failed to create Redis client")?;
24
25 let mut conn = client
26 .get_multiplexed_async_connection()
27 .await
28 .context("Failed to connect to Redis")?;
29
30 redis::cmd("PING")
32 .query_async::<String>(&mut conn)
33 .await
34 .context("Failed to ping Redis")?;
35
36 Ok(())
37}
38
39pub fn validate_node_names(requested_nodes: &[String], available_nodes: &[String]) -> Result<Vec<String>> {
41 let mut invalid = Vec::new();
42
43 for node in requested_nodes {
44 if !available_nodes.contains(node) {
45 invalid.push(node.clone());
46 }
47 }
48
49 if !invalid.is_empty() {
50 return Err(anyhow!(
51 "Unknown nodes: {}\nAvailable nodes: {}",
52 invalid.join(", "),
53 available_nodes.join(", ")
54 ));
55 }
56
57 Ok(requested_nodes.to_vec())
58}