feat: Add validation command
This commit is contained in:
parent
1de71ab026
commit
9a3ad0ae17
35 changed files with 1666 additions and 508 deletions
|
|
@ -1,12 +1,15 @@
|
|||
use std::{collections::HashSet, fs, path::Path};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use blue_build_utils::constants::{CONFIG_PATH, RECIPE_PATH};
|
||||
use bon::Builder;
|
||||
use log::{trace, warn};
|
||||
use miette::{Context, IntoDiagnostic, Result};
|
||||
use log::trace;
|
||||
use miette::{Context, IntoDiagnostic, Report, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{AkmodsInfo, Module};
|
||||
use crate::{base_recipe_path, AkmodsInfo, FromFileList, Module};
|
||||
|
||||
#[derive(Default, Serialize, Clone, Deserialize, Debug, Builder)]
|
||||
pub struct ModuleExt<'a> {
|
||||
|
|
@ -14,22 +17,31 @@ pub struct ModuleExt<'a> {
|
|||
pub modules: Vec<Module<'a>>,
|
||||
}
|
||||
|
||||
impl ModuleExt<'_> {
|
||||
/// Parse a module file returning a [`ModuleExt`]
|
||||
///
|
||||
/// # Errors
|
||||
/// Can return an `anyhow` Error if the file cannot be read or deserialized
|
||||
/// into a [`ModuleExt`]
|
||||
pub fn parse(file_name: &Path) -> Result<Self> {
|
||||
let legacy_path = Path::new(CONFIG_PATH);
|
||||
let recipe_path = Path::new(RECIPE_PATH);
|
||||
impl FromFileList for ModuleExt<'_> {
|
||||
const LIST_KEY: &'static str = "modules";
|
||||
|
||||
let file_path = if recipe_path.exists() && recipe_path.is_dir() {
|
||||
recipe_path.join(file_name)
|
||||
} else {
|
||||
warn!("Use of {CONFIG_PATH} for recipes is deprecated, please move your recipe files into {RECIPE_PATH}");
|
||||
legacy_path.join(file_name)
|
||||
};
|
||||
#[must_use]
|
||||
fn get_from_file_paths(&self) -> Vec<PathBuf> {
|
||||
self.modules
|
||||
.iter()
|
||||
.filter_map(Module::get_from_file_path)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&PathBuf> for ModuleExt<'_> {
|
||||
type Error = Report;
|
||||
|
||||
fn try_from(value: &PathBuf) -> std::result::Result<Self, Self::Error> {
|
||||
Self::try_from(value.as_path())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&Path> for ModuleExt<'_> {
|
||||
type Error = Report;
|
||||
|
||||
fn try_from(file_name: &Path) -> Result<Self> {
|
||||
let file_path = base_recipe_path().join(file_name);
|
||||
|
||||
let file = fs::read_to_string(&file_path)
|
||||
.into_diagnostic()
|
||||
|
|
@ -45,7 +57,9 @@ impl ModuleExt<'_> {
|
|||
Ok,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ModuleExt<'_> {
|
||||
#[must_use]
|
||||
pub fn get_akmods_info_list(&self, os_version: &u64) -> Vec<AkmodsInfo> {
|
||||
trace!("get_akmods_image_list({self:#?}, {os_version})");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue