use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct Manifest {
pub version: Option<u32>,
pub tools: BTreeMap<String, ToolSpec>,
pub env: BTreeMap<String, EnvValue>,
pub tasks: BTreeMap<String, Task>,
pub settings: Settings,
pub registries: BTreeMap<String, Registry>,
pub workspace: Option<Workspace>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ToolSpec {
Version(String),
Detailed(ToolDetail),
}
impl ToolSpec {
pub fn version(&self) -> &str {
match self {
ToolSpec::Version(v) => v,
ToolSpec::Detailed(d) => &d.version,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ToolDetail {
pub version: String,
#[serde(default)]
pub channel: Option<String>,
#[serde(default)]
pub registry: Option<String>,
#[serde(default)]
pub provider: Option<String>,
#[serde(default)]
pub os: Option<Vec<String>>,
#[serde(default)]
pub optional: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EnvValue {
Plain(String),
Path(PathEdit),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PathEdit {
#[serde(default)]
pub prepend: Vec<String>,
#[serde(default)]
pub append: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Task {
Command(String),
Detailed(TaskDetail),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TaskDetail {
pub run: String,
#[serde(default)]
pub description: Option<String>,
#[serde(default)]
pub depends: Vec<String>,
#[serde(default)]
pub cwd: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct Settings {
pub auto_install: Option<bool>,
pub verify: Option<String>,
pub jobs: Option<u32>,
pub link_strategy: Option<String>,
pub shims: Option<bool>,
pub offline: Option<bool>,
pub mirror: Option<String>,
pub targets: Option<Vec<String>>,
pub retain_generations: Option<u32>,
pub gc_keep_days: Option<u32>,
pub color: Option<String>,
pub telemetry: Option<bool>,
pub read_foreign_versions: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Registry {
pub url: String,
#[serde(default)]
pub priority: Option<i32>,
#[serde(default)]
pub auth: Option<String>,
#[serde(default)]
pub public_key: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Workspace {
pub members: Vec<String>,
#[serde(default)]
pub inherit: Option<bool>,
}