46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
|
|
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,
|
||
|
|
|
||
|
|
#[serde(default)]
|
||
|
|
pub(super) repo: Option<String>,
|
||
|
|
#[serde(default)]
|
||
|
|
pub(super) branch: Option<String>,
|
||
|
|
#[serde(default)]
|
||
|
|
pub(super) path: Option<String>,
|
||
|
|
#[serde(default)]
|
||
|
|
pub(super) attr: Option<String>,
|
||
|
|
#[serde(default)]
|
||
|
|
pub(super) update: Option<bool>,
|
||
|
|
#[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")))
|
||
|
|
}
|
||
|
|
}
|