robin/
lib.rs

1pub const CONFIG_FILE: &str = ".robin.json";
2const GITHUB_TEMPLATE_BASE: &str = "https://raw.githubusercontent.com/cesarferreira/robin/refs/heads/main/templates";
3
4pub mod cli;
5pub mod config;
6pub mod tools;
7pub mod utils;
8pub mod scripts;
9
10pub use cli::{Cli, Commands};
11pub use config::RobinConfig;
12pub use tools::{check_environment, update_tools};
13pub use utils::{send_notification, split_command_and_args, replace_variables};
14pub use scripts::{run_script, list_commands, interactive_mode};
15
16use anyhow::{Context, Result, anyhow};
17use reqwest;
18
19#[cfg(not(feature = "test-utils"))]
20pub async fn fetch_template(template_name: &str) -> Result<RobinConfig> {
21    let url = format!("{}/{}.json", GITHUB_TEMPLATE_BASE, template_name);
22    let response = reqwest::get(&url)
23        .await
24        .with_context(|| format!("Failed to fetch template from: {}", url))?;
25    
26    if !response.status().is_success() {
27        return Err(anyhow!("Template '{}' not found", template_name));
28    }
29
30    let content = response.text()
31        .await
32        .with_context(|| "Failed to read template content")?;
33    
34    let config: RobinConfig = serde_json::from_str(&content)
35        .with_context(|| "Failed to parse template JSON")?;
36    
37    Ok(config)
38}
39
40#[cfg(feature = "test-utils")]
41pub async fn fetch_template(_template_name: &str) -> Result<RobinConfig> {
42    use std::collections::HashMap;
43    let mut scripts = HashMap::new();
44    scripts.insert("start".to_string(), serde_json::Value::String("npm start".to_string()));
45    Ok(RobinConfig { scripts, include: vec![] })
46}