mirror of
https://github.com/philmmanjaro/alma.git
synced 2025-07-26 06:59:28 +02:00
Add the "environment" key to presets
This commit is contained in:
parent
ffbd34e14f
commit
7dcff2a019
@ -77,6 +77,9 @@ pub enum ErrorKind {
|
||||
#[fail(display = "Error loading preset \"{}\"", _0)]
|
||||
Preset(String),
|
||||
|
||||
#[fail(display = "Missing environment variables \"{:?}\"", _0)]
|
||||
MissingEnvironmentVariables(Vec<String>),
|
||||
|
||||
#[fail(display = "Error executing preset script")]
|
||||
PresetScript,
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ use crate::error::{Error, ErrorKind};
|
||||
use failure::ResultExt;
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use toml;
|
||||
@ -11,6 +12,7 @@ use toml;
|
||||
struct Preset {
|
||||
packages: Option<Vec<String>>,
|
||||
script: Option<String>,
|
||||
environment_variables: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl Preset {
|
||||
@ -31,20 +33,35 @@ impl Presets {
|
||||
pub fn load(list: &[PathBuf]) -> Result<Self, Error> {
|
||||
let mut packages = HashSet::new();
|
||||
let mut scripts = Vec::new();
|
||||
let mut environment_variables = HashSet::new();
|
||||
|
||||
for preset in list {
|
||||
let Preset {
|
||||
script,
|
||||
packages: preset_packages,
|
||||
environment_variables: preset_environment_variables,
|
||||
} = Preset::load(&preset)?;
|
||||
|
||||
if let Some(preset_packages) = preset_packages {
|
||||
packages.extend(preset_packages);
|
||||
}
|
||||
|
||||
if let Some(preset_environment_variables) = preset_environment_variables {
|
||||
environment_variables.extend(preset_environment_variables);
|
||||
}
|
||||
|
||||
scripts.extend(script);
|
||||
}
|
||||
|
||||
let missing_envrionments: Vec<String> = environment_variables
|
||||
.into_iter()
|
||||
.filter(|var| env::var(var).is_err())
|
||||
.collect();
|
||||
|
||||
if !missing_envrionments.is_empty() {
|
||||
Err(ErrorKind::MissingEnvironmentVariables(missing_envrionments))?
|
||||
}
|
||||
|
||||
Ok(Self { packages, scripts })
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user