use anyhow::{anyhow, Context}; use serde::Deserialize; use std::collections::HashSet; use std::env; use std::fs; use std::io; use std::path::{Path, PathBuf}; #[derive(Deserialize)] struct Preset { packages: Option>, script: Option, environment_variables: Option>, shared_directories: Option>, aur_packages: Option>, } fn visit_dirs(dir: &Path, filevec: &mut Vec) -> Result<(), io::Error> { if dir.is_dir() { for entry in fs::read_dir(dir)? { let entry = entry?; let path = entry.path(); if path.is_dir() { visit_dirs(&path, filevec)?; } else if entry.path().extension() == Some(&std::ffi::OsString::from("toml")) { filevec.push(entry.path()); } } } Ok(()) } impl Preset { fn load(path: &Path) -> anyhow::Result { let data = fs::read_to_string(path).with_context(|| format!("{}", path.display()))?; Ok(toml::from_str(&data).with_context(|| format!("{}", path.display()))?) } fn process( &self, packages: &mut HashSet, scripts: &mut Vec