mecha10_cli/services/dev/
mod.rs1use anyhow::{Context, Result};
7use std::collections::HashMap;
8
9pub struct DevService {
10 #[allow(dead_code)]
11 redis_url: String,
12}
13
14impl DevService {
15 pub fn new(redis_url: String) -> Self {
21 Self { redis_url }
22 }
23
24 pub async fn load_project_info(
30 ctx: &mut crate::context::CliContext,
31 ) -> Result<(String, String, crate::types::ProjectConfig)> {
32 let project = ctx.project()?;
33 let name = project.name()?.to_string();
34 let version = project.version()?.to_string();
35 let config = ctx.load_project_config().await?;
36 Ok((name, version, config))
37 }
38
39 pub async fn flush_redis<C>(&self, conn: &mut C) -> Result<()>
49 where
50 C: redis::aio::ConnectionLike,
51 {
52 redis::cmd("FLUSHALL")
53 .query_async::<()>(conn)
54 .await
55 .context("Failed to flush Redis")?;
56 Ok(())
57 }
58
59 #[allow(dead_code)]
68 pub fn get_default_env_vars(&self) -> HashMap<String, String> {
69 let mut env = HashMap::new();
70 env.insert("REDIS_URL".to_string(), self.redis_url.clone());
71 env.insert("RUST_LOG".to_string(), "info".to_string());
72 env
73 }
74}
75
76impl Default for DevService {
77 fn default() -> Self {
78 Self::new("redis://localhost:6379".to_string())
79 }
80}