mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
change $scope.variables output to a table (#3323)
This commit is contained in:
parent
f73732bf1e
commit
528c1c5fd8
1 changed files with 22 additions and 11 deletions
|
@ -2,7 +2,7 @@ use crate::{evaluate::scope::Scope, EvaluationContext};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_data::config::path::{default_history_path, history_path};
|
use nu_data::config::path::{default_history_path, history_path};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ShellTypeName, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
use nu_protocol::{Dictionary, ShellTypeName, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use nu_source::{Spanned, Tag};
|
use nu_source::{Spanned, Tag};
|
||||||
|
|
||||||
pub fn nu(
|
pub fn nu(
|
||||||
|
@ -110,21 +110,32 @@ pub fn scope(
|
||||||
commands_dict.insert_untagged(name, UntaggedValue::string(&signature.allowed().join(" ")))
|
commands_dict.insert_untagged(name, UntaggedValue::string(&signature.allowed().join(" ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut vars_dict = TaggedDictBuilder::new(&tag);
|
let var_list: Vec<Value> = variables
|
||||||
for (name, val) in variables.iter() {
|
.iter()
|
||||||
let val_type = UntaggedValue::string(format!(
|
.map(|var| {
|
||||||
"{} ({})",
|
let mut entries: IndexMap<String, Value> = IndexMap::new();
|
||||||
val.convert_to_string(),
|
let name = var.0.trim_start_matches('$');
|
||||||
ShellTypeName::type_name(&val.clone())
|
entries.insert(
|
||||||
));
|
"name".to_string(),
|
||||||
vars_dict.insert_value(name, val_type)
|
UntaggedValue::string(name).into_value(&tag),
|
||||||
}
|
);
|
||||||
|
entries.insert(
|
||||||
|
"value".to_string(),
|
||||||
|
UntaggedValue::string(var.1.convert_to_string()).into_value(&tag),
|
||||||
|
);
|
||||||
|
entries.insert(
|
||||||
|
"type".to_string(),
|
||||||
|
UntaggedValue::string(ShellTypeName::type_name(&var.1)).into_value(&tag),
|
||||||
|
);
|
||||||
|
UntaggedValue::Row(Dictionary { entries }).into_value(&tag)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
scope_dict.insert_value("aliases", aliases_dict.into_value());
|
scope_dict.insert_value("aliases", aliases_dict.into_value());
|
||||||
|
|
||||||
scope_dict.insert_value("commands", commands_dict.into_value());
|
scope_dict.insert_value("commands", commands_dict.into_value());
|
||||||
|
|
||||||
scope_dict.insert_value("variables", vars_dict.into_value());
|
scope_dict.insert_value("variables", UntaggedValue::Table(var_list).into_value(&tag));
|
||||||
|
|
||||||
Ok(scope_dict.into_value())
|
Ok(scope_dict.into_value())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue