2026-02-14 13:31:21 -05:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
|
|
use crate::error::CustomError;
|
|
|
|
|
|
|
|
|
|
use super::Config;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Default)]
|
|
|
|
|
pub(crate) struct TargetConfig {
|
|
|
|
|
pub(super) name: String,
|
|
|
|
|
|
2026-02-14 16:00:37 -05:00
|
|
|
pub(super) repo: String,
|
|
|
|
|
|
2026-02-14 13:31:21 -05:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub(super) branch: Option<String>,
|
2026-02-14 16:00:37 -05:00
|
|
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub(super) revision: Option<String>,
|
|
|
|
|
|
2026-02-14 13:31:21 -05:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub(super) path: Option<String>,
|
2026-02-14 16:00:37 -05:00
|
|
|
|
2026-02-14 13:31:21 -05:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub(super) attr: Option<String>,
|
2026-02-14 16:00:37 -05:00
|
|
|
|
2026-02-14 13:31:21 -05:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub(super) update: Option<bool>,
|
2026-02-14 16:00:37 -05:00
|
|
|
|
2026-02-14 13:31:21 -05:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub(super) update_branch: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TargetConfig {
|
|
|
|
|
pub(crate) fn get_target_directory<'target, 'root>(
|
|
|
|
|
&'target self,
|
|
|
|
|
config_root: &'root Config,
|
|
|
|
|
) -> Result<Cow<'target, Path>, CustomError> {
|
|
|
|
|
let work_directory = config_root.get_work_directory()?;
|
|
|
|
|
Ok(Cow::Owned(work_directory.join(&self.name)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_flake_directory<'target, 'root>(
|
|
|
|
|
&'target self,
|
|
|
|
|
config_root: &'root Config,
|
|
|
|
|
) -> Result<Cow<'target, Path>, CustomError> {
|
|
|
|
|
let target_directory = self.get_target_directory(config_root)?;
|
|
|
|
|
Ok(Cow::Owned(target_directory.join("flake")))
|
|
|
|
|
}
|
2026-02-14 16:00:37 -05:00
|
|
|
|
|
|
|
|
pub(crate) fn get_repo(&'_ self) -> Result<&String, CustomError> {
|
|
|
|
|
Ok(&self.repo)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_branch(&'_ self) -> Result<Cow<'_, str>, CustomError> {
|
|
|
|
|
if let Some(b) = &self.branch {
|
|
|
|
|
Ok(Cow::Borrowed(b))
|
|
|
|
|
} else {
|
|
|
|
|
Ok(Cow::Borrowed("main"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_revision(&self) -> Result<&Option<String>, CustomError> {
|
|
|
|
|
Ok(&self.revision)
|
|
|
|
|
}
|
2026-02-14 13:31:21 -05:00
|
|
|
}
|