Add support for :config and :env

This commit is contained in:
Jonathan Turner 2019-10-29 06:51:08 +13:00
parent 36e40ebb85
commit 1de80aeac3

View File

@ -5,6 +5,7 @@ use crate::parser::{
CommandRegistry, Text, CommandRegistry, Text,
}; };
use crate::prelude::*; use crate::prelude::*;
use crate::TaggedDictBuilder;
use derive_new::new; use derive_new::new;
use indexmap::IndexMap; use indexmap::IndexMap;
use log::trace; use log::trace;
@ -164,11 +165,24 @@ fn evaluate_reference(
trace!("Evaluating {} with Scope {}", name, scope); trace!("Evaluating {} with Scope {}", name, scope);
match name { match name {
hir::Variable::It(_) => Ok(scope.it.item.clone().tagged(tag)), hir::Variable::It(_) => Ok(scope.it.item.clone().tagged(tag)),
hir::Variable::Other(inner) => Ok(scope hir::Variable::Other(inner) => match inner.slice(source) {
x if x == "nu:env" => {
let mut dict = TaggedDictBuilder::new(&tag);
for v in std::env::vars() {
dict.insert(v.0, Value::string(v.1));
}
Ok(dict.into_tagged_value())
}
x if x == "nu:config" => {
let config = crate::data::config::read(tag.clone(), &None)?;
Ok(Value::row(config).tagged(tag))
}
x => Ok(scope
.vars .vars
.get(inner.slice(source)) .get(x)
.map(|v| v.clone()) .map(|v| v.clone())
.unwrap_or_else(|| Value::nothing().tagged(tag))), .unwrap_or_else(|| Value::nothing().tagged(tag))),
},
} }
} }