use anyhow::{Context, Result};
use std::collections::HashMap;
pub struct DevService {
#[allow(dead_code)]
redis_url: String,
}
impl DevService {
pub fn new(redis_url: String) -> Self {
Self { redis_url }
}
pub async fn load_project_info(
ctx: &mut crate::context::CliContext,
) -> Result<(String, String, crate::types::ProjectConfig)> {
let project = ctx.project()?;
let name = project.name()?.to_string();
let version = project.version()?.to_string();
let config = ctx.load_project_config().await?;
Ok((name, version, config))
}
pub async fn flush_redis<C>(&self, conn: &mut C) -> Result<()>
where
C: redis::aio::ConnectionLike,
{
redis::cmd("FLUSHALL")
.query_async::<()>(conn)
.await
.context("Failed to flush Redis")?;
Ok(())
}
#[allow(dead_code)]
pub fn get_default_env_vars(&self) -> HashMap<String, String> {
let mut env = HashMap::new();
env.insert("REDIS_URL".to_string(), self.redis_url.clone());
env.insert("RUST_LOG".to_string(), "info".to_string());
env
}
}
impl Default for DevService {
fn default() -> Self {
Self::new("redis://localhost:6379".to_string())
}
}