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 {
17 Self { redis_url }
18 }
19
20 pub async fn load_project_info(
22 ctx: &mut crate::context::CliContext,
23 ) -> Result<(String, String, crate::types::ProjectConfig)> {
24 let project = ctx.project()?;
25 let name = project.name()?.to_string();
26 let version = project.version()?.to_string();
27 let config = ctx.load_project_config().await?;
28 Ok((name, version, config))
29 }
30
31 pub async fn flush_redis<C>(&self, conn: &mut C) -> Result<()>
33 where
34 C: redis::aio::ConnectionLike,
35 {
36 redis::cmd("FLUSHALL")
37 .query_async::<()>(conn)
38 .await
39 .context("Failed to flush Redis")?;
40 Ok(())
41 }
42
43 #[allow(dead_code)]
45 pub fn get_default_env_vars(&self) -> HashMap<String, String> {
46 let mut env = HashMap::new();
47 env.insert("REDIS_URL".to_string(), self.redis_url.clone());
48 env.insert("RUST_LOG".to_string(), "info".to_string());
49 env
50 }
51}
52
53impl Default for DevService {
54 fn default() -> Self {
55 Self::new("redis://localhost:6379".to_string())
56 }
57}