mirror of
https://github.com/nushell/nushell.git
synced 2025-02-25 15:01:45 +01:00
Add support for :config and :env
This commit is contained in:
parent
36e40ebb85
commit
1de80aeac3
@ -5,6 +5,7 @@ use crate::parser::{
|
||||
CommandRegistry, Text,
|
||||
};
|
||||
use crate::prelude::*;
|
||||
use crate::TaggedDictBuilder;
|
||||
use derive_new::new;
|
||||
use indexmap::IndexMap;
|
||||
use log::trace;
|
||||
@ -164,11 +165,24 @@ fn evaluate_reference(
|
||||
trace!("Evaluating {} with Scope {}", name, scope);
|
||||
match name {
|
||||
hir::Variable::It(_) => Ok(scope.it.item.clone().tagged(tag)),
|
||||
hir::Variable::Other(inner) => Ok(scope
|
||||
.vars
|
||||
.get(inner.slice(source))
|
||||
.map(|v| v.clone())
|
||||
.unwrap_or_else(|| Value::nothing().tagged(tag))),
|
||||
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
|
||||
.get(x)
|
||||
.map(|v| v.clone())
|
||||
.unwrap_or_else(|| Value::nothing().tagged(tag))),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user