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