use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
use std::path::{Path, PathBuf};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RivoxManifest {
pub project: ProjectConfig,
pub ecosystems: HashMap<String, EcosystemConfig>,
#[serde(default)]
pub cross_refs: Vec<CrossRefConfig>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ProjectConfig {
pub name: String,
pub version: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct EcosystemConfig {
pub path: PathBuf,
pub tool: String,
#[serde(default)]
pub allow_network: Vec<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CrossRefConfig {
pub consumer: String,
pub dependency: String,
pub r#type: String,
}
impl RivoxManifest {
pub fn load_from_file(path: &Path) -> Result<Self> {
let content = fs::read_to_string(path)
.with_context(|| format!("Failed to read manifest at {}", path.display()))?;
let manifest: RivoxManifest = toml::from_str(&content)
.with_context(|| format!("Failed to parse TOML manifest at {}", path.display()))?;
Ok(manifest)
}
}