genpac 0.1.0

Sandbox for Gentoo ebuild development using bubblewrap
// Copyright (C) 2023 Gokul Das B
// SPDX-License-Identifier: GPL-3.0-or-later
//! Config processing for snapshot module

use crate::GlobalsFinal;
use anyhow::Result as AResult;
use serde::Deserialize;
use std::path::{Path, PathBuf};

#[derive(Deserialize)]
struct Config {
    snapshot: ModConfig,
}

#[derive(Deserialize)]
pub(super) struct ModConfig {
    template: Option<PathBuf>,
}

impl ModConfig {
    pub(super) fn new(globals: &GlobalsFinal) -> AResult<Self> {
        let cfg: Config = toml::from_str(globals.text())?;
        Ok(cfg.snapshot)
    }

    #[inline]
    pub(super) fn template(&self) -> Option<&Path> {
        self.template.as_deref()
    }
}