From da0cd2fe49a4fba917516fd637fef6be6c304896 Mon Sep 17 00:00:00 2001 From: Guillaume Pasquet Date: Fri, 19 Nov 2021 22:33:56 +0000 Subject: Added Context structure. --- src/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index b6255d7..81cb18d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,33 @@ mod barbfile; use jsonformat::{format_json, Indentation}; +use std::collections::HashMap; +use std::env; use std::fs; use std::str::FromStr; use ureq; +struct Context { + vars: HashMap, +} + +impl Context { + pub fn new() -> Context { + Context { + vars: HashMap::new(), + } + } + + pub fn get_var(&self, name: String) -> Option { + self.vars + .get(&name) + .map(|val| val.clone()) + .or_else(|| env::var(name).ok()) + } +} + fn main() { + let mut context = Context::new(); let bfile = barbfile::BarbFile::from_str( fs::read_to_string("test.barb") .expect("Failed to read file") -- cgit v1.2.3