mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Extract ps and sys subcrates. Move helper methods to UntaggedValue
This commit is contained in:
parent
a4bb5d4ff5
commit
d12c16a331
84 changed files with 673 additions and 600 deletions
38
Cargo.lock
generated
38
Cargo.lock
generated
|
@ -1884,7 +1884,6 @@ dependencies = [
|
||||||
"app_dirs",
|
"app_dirs",
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"base64 0.11.0",
|
"base64 0.11.0",
|
||||||
"battery",
|
|
||||||
"bigdecimal",
|
"bigdecimal",
|
||||||
"bson",
|
"bson",
|
||||||
"byte-unit",
|
"byte-unit",
|
||||||
|
@ -1903,13 +1902,11 @@ dependencies = [
|
||||||
"dirs 2.0.2",
|
"dirs 2.0.2",
|
||||||
"dunce",
|
"dunce",
|
||||||
"futures-preview",
|
"futures-preview",
|
||||||
"futures-timer",
|
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"futures_codec",
|
"futures_codec",
|
||||||
"getset",
|
"getset",
|
||||||
"git2",
|
"git2",
|
||||||
"glob",
|
"glob",
|
||||||
"heim",
|
|
||||||
"hex 0.4.0",
|
"hex 0.4.0",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"itertools 0.8.2",
|
"itertools 0.8.2",
|
||||||
|
@ -1926,10 +1923,11 @@ dependencies = [
|
||||||
"nu-protocol",
|
"nu-protocol",
|
||||||
"nu-source",
|
"nu-source",
|
||||||
"nu_plugin_binaryview",
|
"nu_plugin_binaryview",
|
||||||
|
"nu_plugin_ps",
|
||||||
|
"nu_plugin_sys",
|
||||||
"nu_plugin_textview",
|
"nu_plugin_textview",
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
"num-traits 0.2.10",
|
"num-traits 0.2.10",
|
||||||
"onig_sys",
|
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
"pretty",
|
"pretty",
|
||||||
"pretty-hex",
|
"pretty-hex",
|
||||||
|
@ -1956,7 +1954,6 @@ dependencies = [
|
||||||
"sublime_fuzzy",
|
"sublime_fuzzy",
|
||||||
"subprocess",
|
"subprocess",
|
||||||
"surf",
|
"surf",
|
||||||
"syntect",
|
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"term",
|
"term",
|
||||||
"termcolor",
|
"termcolor",
|
||||||
|
@ -2091,8 +2088,35 @@ dependencies = [
|
||||||
"nu-source",
|
"nu-source",
|
||||||
"pretty-hex",
|
"pretty-hex",
|
||||||
"rawkey",
|
"rawkey",
|
||||||
"syntect",
|
]
|
||||||
"url",
|
|
||||||
|
[[package]]
|
||||||
|
name = "nu_plugin_ps"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"futures-preview",
|
||||||
|
"futures-timer",
|
||||||
|
"heim",
|
||||||
|
"nu-build",
|
||||||
|
"nu-errors",
|
||||||
|
"nu-protocol",
|
||||||
|
"nu-source",
|
||||||
|
"pin-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nu_plugin_sys"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"battery",
|
||||||
|
"futures-preview",
|
||||||
|
"futures-timer",
|
||||||
|
"heim",
|
||||||
|
"nu-build",
|
||||||
|
"nu-errors",
|
||||||
|
"nu-protocol",
|
||||||
|
"nu-source",
|
||||||
|
"pin-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
23
Cargo.toml
23
Cargo.toml
|
@ -18,6 +18,8 @@ members = [
|
||||||
"crates/nu-source",
|
"crates/nu-source",
|
||||||
"crates/nu_plugin_textview",
|
"crates/nu_plugin_textview",
|
||||||
"crates/nu_plugin_binaryview",
|
"crates/nu_plugin_binaryview",
|
||||||
|
"crates/nu_plugin_ps",
|
||||||
|
"crates/nu_plugin_sys",
|
||||||
"crates/nu-protocol",
|
"crates/nu-protocol",
|
||||||
"crates/nu-parser",
|
"crates/nu-parser",
|
||||||
"crates/nu-build"
|
"crates/nu-build"
|
||||||
|
@ -32,6 +34,8 @@ nu-errors = { version = "0.1.0", path = "./crates/nu-errors" }
|
||||||
nu-parser = { version = "0.1.0", path = "./crates/nu-parser" }
|
nu-parser = { version = "0.1.0", path = "./crates/nu-parser" }
|
||||||
nu_plugin_textview = {version = "0.1.0", path = "./crates/nu_plugin_textview", optional=true}
|
nu_plugin_textview = {version = "0.1.0", path = "./crates/nu_plugin_textview", optional=true}
|
||||||
nu_plugin_binaryview = {version = "0.1.0", path = "./crates/nu_plugin_binaryview", optional=true}
|
nu_plugin_binaryview = {version = "0.1.0", path = "./crates/nu_plugin_binaryview", optional=true}
|
||||||
|
nu_plugin_ps = {version = "0.1.0", path = "./crates/nu_plugin_ps", optional=true}
|
||||||
|
nu_plugin_sys = {version = "0.1.0", path = "./crates/nu_plugin_sys", optional=true}
|
||||||
|
|
||||||
query_interface = "0.3.5"
|
query_interface = "0.3.5"
|
||||||
typetag = "0.1.4"
|
typetag = "0.1.4"
|
||||||
|
@ -87,7 +91,6 @@ semver = "0.9.0"
|
||||||
which = "3.1"
|
which = "3.1"
|
||||||
textwrap = {version = "0.11.0", features = ["term_size"]}
|
textwrap = {version = "0.11.0", features = ["term_size"]}
|
||||||
shellexpand = "1.0.0"
|
shellexpand = "1.0.0"
|
||||||
futures-timer = "2.0.0"
|
|
||||||
pin-utils = "0.1.0-alpha.4"
|
pin-utils = "0.1.0-alpha.4"
|
||||||
num-bigint = { version = "0.2.3", features = ["serde"] }
|
num-bigint = { version = "0.2.3", features = ["serde"] }
|
||||||
bigdecimal = { version = "0.1.0", features = ["serde"] }
|
bigdecimal = { version = "0.1.0", features = ["serde"] }
|
||||||
|
@ -106,21 +109,17 @@ termcolor = "1.0.5"
|
||||||
console = "0.9.1"
|
console = "0.9.1"
|
||||||
|
|
||||||
crossterm = { version = "0.10.2", optional = true }
|
crossterm = { version = "0.10.2", optional = true }
|
||||||
syntect = {version = "3.2.0", optional = true }
|
|
||||||
onig_sys = {version = "=69.1.0", optional = true }
|
|
||||||
heim = {version = "0.0.8", optional = true }
|
|
||||||
battery = {version = "0.7.4", optional = true }
|
|
||||||
clipboard = {version = "0.5", optional = true }
|
clipboard = {version = "0.5", optional = true }
|
||||||
ptree = {version = "0.2" }
|
ptree = {version = "0.2" }
|
||||||
starship = { version = "0.26.4", optional = true}
|
starship = { version = "0.26.4", optional = true}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["sys", "ps"]
|
default = ["sys", "ps"]
|
||||||
sys = ["heim", "battery"]
|
sys = ["nu_plugin_ps"]
|
||||||
ps = ["heim"]
|
|
||||||
starship-prompt = ["starship"]
|
starship-prompt = ["starship"]
|
||||||
textview = ["nu_plugin_textview"]
|
textview = ["nu_plugin_textview"]
|
||||||
binaryview = ["nu_plugin_binaryview"]
|
binaryview = ["nu_plugin_binaryview"]
|
||||||
|
ps = ["nu_plugin_ps"]
|
||||||
#trace = ["nu-parser/trace"]
|
#trace = ["nu-parser/trace"]
|
||||||
|
|
||||||
[dependencies.rusqlite]
|
[dependencies.rusqlite]
|
||||||
|
@ -183,16 +182,6 @@ path = "src/plugins/skip.rs"
|
||||||
name = "nu_plugin_match"
|
name = "nu_plugin_match"
|
||||||
path = "src/plugins/match.rs"
|
path = "src/plugins/match.rs"
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "nu_plugin_sys"
|
|
||||||
path = "src/plugins/sys.rs"
|
|
||||||
required-features = ["sys"]
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "nu_plugin_ps"
|
|
||||||
path = "src/plugins/ps.rs"
|
|
||||||
required-features = ["ps"]
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "nu_plugin_tree"
|
name = "nu_plugin_tree"
|
||||||
path = "src/plugins/tree.rs"
|
path = "src/plugins/tree.rs"
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub use crate::signature::{NamedType, PositionalType, Signature};
|
||||||
pub use crate::syntax_shape::SyntaxShape;
|
pub use crate::syntax_shape::SyntaxShape;
|
||||||
pub use crate::type_name::{PrettyType, ShellTypeName, SpannedTypeName};
|
pub use crate::type_name::{PrettyType, ShellTypeName, SpannedTypeName};
|
||||||
pub use crate::value::column_path::{ColumnPath, PathMember, UnspannedPathMember};
|
pub use crate::value::column_path::{ColumnPath, PathMember, UnspannedPathMember};
|
||||||
pub use crate::value::dict::Dictionary;
|
pub use crate::value::dict::{Dictionary, TaggedDictBuilder};
|
||||||
pub use crate::value::evaluate::{Evaluate, EvaluateTrait, Scope};
|
pub use crate::value::evaluate::{Evaluate, EvaluateTrait, Scope};
|
||||||
pub use crate::value::primitive::Primitive;
|
pub use crate::value::primitive::Primitive;
|
||||||
pub use crate::value::{UntaggedValue, Value};
|
pub use crate::value::{UntaggedValue, Value};
|
||||||
|
|
|
@ -11,10 +11,15 @@ use crate::type_name::{ShellTypeName, SpannedTypeName};
|
||||||
use crate::value::dict::Dictionary;
|
use crate::value::dict::Dictionary;
|
||||||
use crate::value::evaluate::Evaluate;
|
use crate::value::evaluate::Evaluate;
|
||||||
use crate::value::primitive::Primitive;
|
use crate::value::primitive::Primitive;
|
||||||
|
use crate::{ColumnPath, PathMember};
|
||||||
|
use bigdecimal::BigDecimal;
|
||||||
|
use indexmap::IndexMap;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_source::{AnchorLocation, HasSpan, Span, Tag};
|
use nu_source::{AnchorLocation, HasSpan, Span, Tag};
|
||||||
|
use num_bigint::BigInt;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Serialize, Deserialize)]
|
||||||
pub enum UntaggedValue {
|
pub enum UntaggedValue {
|
||||||
|
@ -103,6 +108,69 @@ impl UntaggedValue {
|
||||||
_ => panic!("expect_string assumes that the value must be a string"),
|
_ => panic!("expect_string assumes that the value must be a string"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn row(entries: IndexMap<String, Value>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Row(entries.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn table(list: &Vec<Value>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Table(list.to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn string(s: impl Into<String>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::String(s.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn line(s: impl Into<String>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Line(s.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn column_path(s: Vec<impl Into<PathMember>>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::new(
|
||||||
|
s.into_iter().map(|p| p.into()).collect(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn int(i: impl Into<BigInt>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Int(i.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pattern(s: impl Into<String>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::String(s.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn path(s: impl Into<PathBuf>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Path(s.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bytes(s: impl Into<u64>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Bytes(s.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn decimal(s: impl Into<BigDecimal>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Decimal(s.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn binary(binary: Vec<u8>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Binary(binary))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn boolean(s: impl Into<bool>) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Boolean(s.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn duration(secs: u64) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Duration(secs))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn system_date(s: SystemTime) -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Date(s.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn nothing() -> UntaggedValue {
|
||||||
|
UntaggedValue::Primitive(Primitive::Nothing)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialOrd, PartialEq, Ord, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialOrd, PartialEq, Ord, Eq, Serialize, Deserialize)]
|
||||||
|
|
|
@ -138,3 +138,59 @@ impl Dictionary {
|
||||||
self.entries.insert(name.to_string(), value);
|
self.entries.insert(name.to_string(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct TaggedDictBuilder {
|
||||||
|
tag: Tag,
|
||||||
|
dict: IndexMap<String, Value>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TaggedDictBuilder {
|
||||||
|
pub fn new(tag: impl Into<Tag>) -> TaggedDictBuilder {
|
||||||
|
TaggedDictBuilder {
|
||||||
|
tag: tag.into(),
|
||||||
|
dict: IndexMap::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build(tag: impl Into<Tag>, block: impl FnOnce(&mut TaggedDictBuilder)) -> Value {
|
||||||
|
let mut builder = TaggedDictBuilder::new(tag);
|
||||||
|
block(&mut builder);
|
||||||
|
builder.into_value()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_capacity(tag: impl Into<Tag>, n: usize) -> TaggedDictBuilder {
|
||||||
|
TaggedDictBuilder {
|
||||||
|
tag: tag.into(),
|
||||||
|
dict: IndexMap::with_capacity(n),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn insert_untagged(&mut self, key: impl Into<String>, value: impl Into<UntaggedValue>) {
|
||||||
|
self.dict
|
||||||
|
.insert(key.into(), value.into().into_value(&self.tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn insert_value(&mut self, key: impl Into<String>, value: impl Into<Value>) {
|
||||||
|
self.dict.insert(key.into(), value.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn into_value(self) -> Value {
|
||||||
|
let tag = self.tag.clone();
|
||||||
|
self.into_untagged_value().into_value(tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn into_untagged_value(self) -> UntaggedValue {
|
||||||
|
UntaggedValue::Row(Dictionary { entries: self.dict })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.dict.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TaggedDictBuilder> for Value {
|
||||||
|
fn from(input: TaggedDictBuilder) -> Value {
|
||||||
|
input.into_value()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,13 +7,11 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syntect = { version = "3.2.0" }
|
|
||||||
ansi_term = "0.12.1"
|
ansi_term = "0.12.1"
|
||||||
crossterm = { version = "0.10.2" }
|
crossterm = { version = "0.10.2" }
|
||||||
nu-protocol = { path = "../nu-protocol" }
|
nu-protocol = { path = "../nu-protocol" }
|
||||||
nu-source = { path = "../nu-source" }
|
nu-source = { path = "../nu-source" }
|
||||||
nu-errors = { path = "../nu-errors" }
|
nu-errors = { path = "../nu-errors" }
|
||||||
url = "2.1.0"
|
|
||||||
pretty-hex = "0.1.1"
|
pretty-hex = "0.1.1"
|
||||||
image = { version = "0.22.2", default_features = false, features = ["png_codec", "jpeg"] }
|
image = { version = "0.22.2", default_features = false, features = ["png_codec", "jpeg"] }
|
||||||
rawkey = "0.1.2"
|
rawkey = "0.1.2"
|
||||||
|
|
19
crates/nu_plugin_ps/Cargo.toml
Normal file
19
crates/nu_plugin_ps/Cargo.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[package]
|
||||||
|
name = "nu_plugin_ps"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nu-protocol = { path = "../nu-protocol" }
|
||||||
|
nu-source = { path = "../nu-source" }
|
||||||
|
nu-errors = { path = "../nu-errors" }
|
||||||
|
futures-preview = { version = "=0.3.0-alpha.19", features = ["compat", "io-compat"] }
|
||||||
|
heim = "0.0.8"
|
||||||
|
futures-timer = "2.0.0"
|
||||||
|
pin-utils = "0.1.0-alpha.4"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
nu-build = { version = "0.1.0", path = "../nu-build" }
|
3
crates/nu_plugin_ps/build.rs
Normal file
3
crates/nu_plugin_ps/build.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
nu_build::build()
|
||||||
|
}
|
|
@ -5,9 +5,11 @@ use heim::process::{self as process, Process, ProcessResult};
|
||||||
use heim::units::{ratio, Ratio};
|
use heim::units::{ratio, Ratio};
|
||||||
use std::usize;
|
use std::usize;
|
||||||
|
|
||||||
use nu::{serve_plugin, value, Plugin, TaggedDictBuilder};
|
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{CallInfo, ReturnSuccess, ReturnValue, Signature, Value};
|
use nu_protocol::{
|
||||||
|
serve_plugin, CallInfo, Plugin, ReturnSuccess, ReturnValue, Signature, TaggedDictBuilder,
|
||||||
|
UntaggedValue, Value,
|
||||||
|
};
|
||||||
use nu_source::Tag;
|
use nu_source::Tag;
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -42,14 +44,14 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||||
while let Some(res) = processes.next().await {
|
while let Some(res) = processes.next().await {
|
||||||
if let Ok((process, usage)) = res {
|
if let Ok((process, usage)) = res {
|
||||||
let mut dict = TaggedDictBuilder::new(&tag);
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
dict.insert_untagged("pid", value::int(process.pid()));
|
dict.insert_untagged("pid", UntaggedValue::int(process.pid()));
|
||||||
if let Ok(name) = process.name().await {
|
if let Ok(name) = process.name().await {
|
||||||
dict.insert_untagged("name", value::string(name));
|
dict.insert_untagged("name", UntaggedValue::string(name));
|
||||||
}
|
}
|
||||||
if let Ok(status) = process.status().await {
|
if let Ok(status) = process.status().await {
|
||||||
dict.insert_untagged("status", value::string(format!("{:?}", status)));
|
dict.insert_untagged("status", UntaggedValue::string(format!("{:?}", status)));
|
||||||
}
|
}
|
||||||
dict.insert_untagged("cpu", value::number(usage.get::<ratio::percent>()));
|
dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::<ratio::percent>()));
|
||||||
output.push(dict.into_value());
|
output.push(dict.into_value());
|
||||||
}
|
}
|
||||||
}
|
}
|
20
crates/nu_plugin_sys/Cargo.toml
Normal file
20
crates/nu_plugin_sys/Cargo.toml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
[package]
|
||||||
|
name = "nu_plugin_sys"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nu-protocol = { path = "../nu-protocol" }
|
||||||
|
nu-source = { path = "../nu-source" }
|
||||||
|
nu-errors = { path = "../nu-errors" }
|
||||||
|
futures-preview = { version = "=0.3.0-alpha.19", features = ["compat", "io-compat"] }
|
||||||
|
heim = "0.0.8"
|
||||||
|
futures-timer = "2.0.0"
|
||||||
|
pin-utils = "0.1.0-alpha.4"
|
||||||
|
battery = "0.7.4"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
nu-build = { version = "0.1.0", path = "../nu-build" }
|
3
crates/nu_plugin_sys/build.rs
Normal file
3
crates/nu_plugin_sys/build.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
nu_build::build()
|
||||||
|
}
|
|
@ -4,9 +4,11 @@ use futures::executor::block_on;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use heim::units::{frequency, information, thermodynamic_temperature, time};
|
use heim::units::{frequency, information, thermodynamic_temperature, time};
|
||||||
use heim::{disk, host, memory, net, sensors};
|
use heim::{disk, host, memory, net, sensors};
|
||||||
use nu::{primitive, serve_plugin, value, Plugin, TaggedDictBuilder};
|
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{CallInfo, ReturnSuccess, ReturnValue, Signature, UntaggedValue, Value};
|
use nu_protocol::{
|
||||||
|
serve_plugin, CallInfo, Plugin, ReturnSuccess, ReturnValue, Signature, TaggedDictBuilder,
|
||||||
|
UntaggedValue, Value,
|
||||||
|
};
|
||||||
use nu_source::Tag;
|
use nu_source::Tag;
|
||||||
|
|
||||||
struct Sys;
|
struct Sys;
|
||||||
|
@ -20,26 +22,26 @@ async fn cpu(tag: Tag) -> Option<Value> {
|
||||||
match futures::future::try_join(heim::cpu::logical_count(), heim::cpu::frequency()).await {
|
match futures::future::try_join(heim::cpu::logical_count(), heim::cpu::frequency()).await {
|
||||||
Ok((num_cpu, cpu_speed)) => {
|
Ok((num_cpu, cpu_speed)) => {
|
||||||
let mut cpu_idx = TaggedDictBuilder::with_capacity(tag, 4);
|
let mut cpu_idx = TaggedDictBuilder::with_capacity(tag, 4);
|
||||||
cpu_idx.insert_untagged("cores", primitive::number(num_cpu));
|
cpu_idx.insert_untagged("cores", UntaggedValue::int(num_cpu));
|
||||||
|
|
||||||
let current_speed =
|
let current_speed =
|
||||||
(cpu_speed.current().get::<frequency::hertz>() as f64 / 1_000_000_000.0 * 100.0)
|
(cpu_speed.current().get::<frequency::hertz>() as f64 / 1_000_000_000.0 * 100.0)
|
||||||
.round()
|
.round()
|
||||||
/ 100.0;
|
/ 100.0;
|
||||||
cpu_idx.insert_untagged("current ghz", primitive::number(current_speed));
|
cpu_idx.insert_untagged("current ghz", UntaggedValue::decimal(current_speed));
|
||||||
|
|
||||||
if let Some(min_speed) = cpu_speed.min() {
|
if let Some(min_speed) = cpu_speed.min() {
|
||||||
let min_speed =
|
let min_speed =
|
||||||
(min_speed.get::<frequency::hertz>() as f64 / 1_000_000_000.0 * 100.0).round()
|
(min_speed.get::<frequency::hertz>() as f64 / 1_000_000_000.0 * 100.0).round()
|
||||||
/ 100.0;
|
/ 100.0;
|
||||||
cpu_idx.insert_untagged("min ghz", primitive::number(min_speed));
|
cpu_idx.insert_untagged("min ghz", UntaggedValue::decimal(min_speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(max_speed) = cpu_speed.max() {
|
if let Some(max_speed) = cpu_speed.max() {
|
||||||
let max_speed =
|
let max_speed =
|
||||||
(max_speed.get::<frequency::hertz>() as f64 / 1_000_000_000.0 * 100.0).round()
|
(max_speed.get::<frequency::hertz>() as f64 / 1_000_000_000.0 * 100.0).round()
|
||||||
/ 100.0;
|
/ 100.0;
|
||||||
cpu_idx.insert_untagged("max ghz", primitive::number(max_speed));
|
cpu_idx.insert_untagged("max ghz", UntaggedValue::decimal(max_speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(cpu_idx.into_value())
|
Some(cpu_idx.into_value())
|
||||||
|
@ -57,22 +59,22 @@ async fn mem(tag: Tag) -> Value {
|
||||||
if let Ok(memory) = memory_result {
|
if let Ok(memory) = memory_result {
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"total",
|
"total",
|
||||||
value::bytes(memory.total().get::<information::byte>()),
|
UntaggedValue::bytes(memory.total().get::<information::byte>()),
|
||||||
);
|
);
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"free",
|
"free",
|
||||||
value::bytes(memory.free().get::<information::byte>()),
|
UntaggedValue::bytes(memory.free().get::<information::byte>()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(swap) = swap_result {
|
if let Ok(swap) = swap_result {
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"swap total",
|
"swap total",
|
||||||
value::bytes(swap.total().get::<information::byte>()),
|
UntaggedValue::bytes(swap.total().get::<information::byte>()),
|
||||||
);
|
);
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"swap free",
|
"swap free",
|
||||||
value::bytes(swap.free().get::<information::byte>()),
|
UntaggedValue::bytes(swap.free().get::<information::byte>()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,10 +89,13 @@ async fn host(tag: Tag) -> Value {
|
||||||
|
|
||||||
// OS
|
// OS
|
||||||
if let Ok(platform) = platform_result {
|
if let Ok(platform) = platform_result {
|
||||||
dict.insert_untagged("name", value::string(platform.system()));
|
dict.insert_untagged("name", UntaggedValue::string(platform.system()));
|
||||||
dict.insert_untagged("release", value::string(platform.release()));
|
dict.insert_untagged("release", UntaggedValue::string(platform.release()));
|
||||||
dict.insert_untagged("hostname", value::string(platform.hostname()));
|
dict.insert_untagged("hostname", UntaggedValue::string(platform.hostname()));
|
||||||
dict.insert_untagged("arch", value::string(platform.architecture().as_str()));
|
dict.insert_untagged(
|
||||||
|
"arch",
|
||||||
|
UntaggedValue::string(platform.architecture().as_str()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uptime
|
// Uptime
|
||||||
|
@ -103,10 +108,10 @@ async fn host(tag: Tag) -> Value {
|
||||||
let minutes = (uptime - days * 60 * 60 * 24 - hours * 60 * 60) / 60;
|
let minutes = (uptime - days * 60 * 60 * 24 - hours * 60 * 60) / 60;
|
||||||
let seconds = uptime % 60;
|
let seconds = uptime % 60;
|
||||||
|
|
||||||
uptime_dict.insert_untagged("days", value::int(days));
|
uptime_dict.insert_untagged("days", UntaggedValue::int(days));
|
||||||
uptime_dict.insert_untagged("hours", value::int(hours));
|
uptime_dict.insert_untagged("hours", UntaggedValue::int(hours));
|
||||||
uptime_dict.insert_untagged("mins", value::int(minutes));
|
uptime_dict.insert_untagged("mins", UntaggedValue::int(minutes));
|
||||||
uptime_dict.insert_untagged("secs", value::int(seconds));
|
uptime_dict.insert_untagged("secs", UntaggedValue::int(seconds));
|
||||||
|
|
||||||
dict.insert_value("uptime", uptime_dict);
|
dict.insert_value("uptime", uptime_dict);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +122,7 @@ async fn host(tag: Tag) -> Value {
|
||||||
while let Some(user) = users.next().await {
|
while let Some(user) = users.next().await {
|
||||||
if let Ok(user) = user {
|
if let Ok(user) = user {
|
||||||
user_vec.push(Value {
|
user_vec.push(Value {
|
||||||
value: value::string(user.username()),
|
value: UntaggedValue::string(user.username()),
|
||||||
tag: tag.clone(),
|
tag: tag.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -136,28 +141,31 @@ async fn disks(tag: Tag) -> Option<UntaggedValue> {
|
||||||
let mut dict = TaggedDictBuilder::with_capacity(&tag, 6);
|
let mut dict = TaggedDictBuilder::with_capacity(&tag, 6);
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"device",
|
"device",
|
||||||
value::string(
|
UntaggedValue::string(
|
||||||
part.device()
|
part.device()
|
||||||
.unwrap_or_else(|| OsStr::new("N/A"))
|
.unwrap_or_else(|| OsStr::new("N/A"))
|
||||||
.to_string_lossy(),
|
.to_string_lossy(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
dict.insert_untagged("type", value::string(part.file_system().as_str()));
|
dict.insert_untagged("type", UntaggedValue::string(part.file_system().as_str()));
|
||||||
dict.insert_untagged("mount", value::string(part.mount_point().to_string_lossy()));
|
dict.insert_untagged(
|
||||||
|
"mount",
|
||||||
|
UntaggedValue::string(part.mount_point().to_string_lossy()),
|
||||||
|
);
|
||||||
|
|
||||||
if let Ok(usage) = disk::usage(part.mount_point().to_path_buf()).await {
|
if let Ok(usage) = disk::usage(part.mount_point().to_path_buf()).await {
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"total",
|
"total",
|
||||||
value::bytes(usage.total().get::<information::byte>()),
|
UntaggedValue::bytes(usage.total().get::<information::byte>()),
|
||||||
);
|
);
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"used",
|
"used",
|
||||||
value::bytes(usage.used().get::<information::byte>()),
|
UntaggedValue::bytes(usage.used().get::<information::byte>()),
|
||||||
);
|
);
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"free",
|
"free",
|
||||||
value::bytes(usage.free().get::<information::byte>()),
|
UntaggedValue::bytes(usage.free().get::<information::byte>()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,24 +189,28 @@ async fn battery(tag: Tag) -> Option<UntaggedValue> {
|
||||||
if let Ok(battery) = battery {
|
if let Ok(battery) = battery {
|
||||||
let mut dict = TaggedDictBuilder::new(&tag);
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
if let Some(vendor) = battery.vendor() {
|
if let Some(vendor) = battery.vendor() {
|
||||||
dict.insert_untagged("vendor", value::string(vendor));
|
dict.insert_untagged("vendor", UntaggedValue::string(vendor));
|
||||||
}
|
}
|
||||||
if let Some(model) = battery.model() {
|
if let Some(model) = battery.model() {
|
||||||
dict.insert_untagged("model", value::string(model));
|
dict.insert_untagged("model", UntaggedValue::string(model));
|
||||||
}
|
}
|
||||||
if let Some(cycles) = battery.cycle_count() {
|
if let Some(cycles) = battery.cycle_count() {
|
||||||
dict.insert_untagged("cycles", value::int(cycles));
|
dict.insert_untagged("cycles", UntaggedValue::int(cycles));
|
||||||
}
|
}
|
||||||
if let Some(time_to_full) = battery.time_to_full() {
|
if let Some(time_to_full) = battery.time_to_full() {
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"mins to full",
|
"mins to full",
|
||||||
value::number(time_to_full.get::<battery::units::time::minute>()),
|
UntaggedValue::decimal(
|
||||||
|
time_to_full.get::<battery::units::time::minute>(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(time_to_empty) = battery.time_to_empty() {
|
if let Some(time_to_empty) = battery.time_to_empty() {
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"mins to empty",
|
"mins to empty",
|
||||||
value::number(time_to_empty.get::<battery::units::time::minute>()),
|
UntaggedValue::decimal(
|
||||||
|
time_to_empty.get::<battery::units::time::minute>(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
output.push(dict.into_value());
|
output.push(dict.into_value());
|
||||||
|
@ -221,13 +233,13 @@ async fn temp(tag: Tag) -> Option<UntaggedValue> {
|
||||||
while let Some(sensor) = sensors.next().await {
|
while let Some(sensor) = sensors.next().await {
|
||||||
if let Ok(sensor) = sensor {
|
if let Ok(sensor) = sensor {
|
||||||
let mut dict = TaggedDictBuilder::new(&tag);
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
dict.insert_untagged("unit", value::string(sensor.unit()));
|
dict.insert_untagged("unit", UntaggedValue::string(sensor.unit()));
|
||||||
if let Some(label) = sensor.label() {
|
if let Some(label) = sensor.label() {
|
||||||
dict.insert_untagged("label", value::string(label));
|
dict.insert_untagged("label", UntaggedValue::string(label));
|
||||||
}
|
}
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"temp",
|
"temp",
|
||||||
value::number(
|
UntaggedValue::decimal(
|
||||||
sensor
|
sensor
|
||||||
.current()
|
.current()
|
||||||
.get::<thermodynamic_temperature::degree_celsius>(),
|
.get::<thermodynamic_temperature::degree_celsius>(),
|
||||||
|
@ -236,13 +248,15 @@ async fn temp(tag: Tag) -> Option<UntaggedValue> {
|
||||||
if let Some(high) = sensor.high() {
|
if let Some(high) = sensor.high() {
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"high",
|
"high",
|
||||||
value::number(high.get::<thermodynamic_temperature::degree_celsius>()),
|
UntaggedValue::decimal(high.get::<thermodynamic_temperature::degree_celsius>()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(critical) = sensor.critical() {
|
if let Some(critical) = sensor.critical() {
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"critical",
|
"critical",
|
||||||
value::number(critical.get::<thermodynamic_temperature::degree_celsius>()),
|
UntaggedValue::decimal(
|
||||||
|
critical.get::<thermodynamic_temperature::degree_celsius>(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,14 +277,14 @@ async fn net(tag: Tag) -> Option<UntaggedValue> {
|
||||||
while let Some(nic) = io_counters.next().await {
|
while let Some(nic) = io_counters.next().await {
|
||||||
if let Ok(nic) = nic {
|
if let Ok(nic) = nic {
|
||||||
let mut network_idx = TaggedDictBuilder::with_capacity(&tag, 3);
|
let mut network_idx = TaggedDictBuilder::with_capacity(&tag, 3);
|
||||||
network_idx.insert_untagged("name", value::string(nic.interface()));
|
network_idx.insert_untagged("name", UntaggedValue::string(nic.interface()));
|
||||||
network_idx.insert_untagged(
|
network_idx.insert_untagged(
|
||||||
"sent",
|
"sent",
|
||||||
value::bytes(nic.bytes_sent().get::<information::byte>()),
|
UntaggedValue::bytes(nic.bytes_sent().get::<information::byte>()),
|
||||||
);
|
);
|
||||||
network_idx.insert_untagged(
|
network_idx.insert_untagged(
|
||||||
"recv",
|
"recv",
|
||||||
value::bytes(nic.bytes_recv().get::<information::byte>()),
|
UntaggedValue::bytes(nic.bytes_recv().get::<information::byte>()),
|
||||||
);
|
);
|
||||||
output.push(network_idx.into_value());
|
output.push(network_idx.into_value());
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::commands::{RawCommandArgs, WholeStreamCommand};
|
use crate::commands::{RawCommandArgs, WholeStreamCommand};
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
|
@ -139,7 +138,7 @@ pub fn autoview(
|
||||||
} if anchor.is_some() => {
|
} if anchor.is_some() => {
|
||||||
if let Some(text) = text {
|
if let Some(text) = text {
|
||||||
let mut stream = VecDeque::new();
|
let mut stream = VecDeque::new();
|
||||||
stream.push_back(value::string(s).into_value(Tag { anchor, span }));
|
stream.push_back(UntaggedValue::string(s).into_value(Tag { anchor, span }));
|
||||||
let result = text.run(raw.with_input(stream.into()), &context.commands);
|
let result = text.run(raw.with_input(stream.into()), &context.commands);
|
||||||
result.collect::<Vec<_>>().await;
|
result.collect::<Vec<_>>().await;
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,7 +157,7 @@ pub fn autoview(
|
||||||
} if anchor.is_some() => {
|
} if anchor.is_some() => {
|
||||||
if let Some(text) = text {
|
if let Some(text) = text {
|
||||||
let mut stream = VecDeque::new();
|
let mut stream = VecDeque::new();
|
||||||
stream.push_back(value::string(s).into_value(Tag { anchor, span }));
|
stream.push_back(UntaggedValue::string(s).into_value(Tag { anchor, span }));
|
||||||
let result = text.run(raw.with_input(stream.into()), &context.commands);
|
let result = text.run(raw.with_input(stream.into()), &context.commands);
|
||||||
result.collect::<Vec<_>>().await;
|
result.collect::<Vec<_>>().await;
|
||||||
} else {
|
} else {
|
||||||
|
@ -227,7 +226,7 @@ pub fn autoview(
|
||||||
|
|
||||||
// Needed for async_stream to type check
|
// Needed for async_stream to type check
|
||||||
if false {
|
if false {
|
||||||
yield ReturnSuccess::value(value::nothing().into_untagged_value());
|
yield ReturnSuccess::value(UntaggedValue::nothing().into_untagged_value());
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use futures_codec::{Decoder, Encoder, Framed};
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_parser::ExternalCommand;
|
use nu_parser::ExternalCommand;
|
||||||
use nu_protocol::Value;
|
use nu_protocol::{UntaggedValue, Value};
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use subprocess::Exec;
|
use subprocess::Exec;
|
||||||
|
|
||||||
|
@ -33,14 +33,14 @@ impl Decoder for LinesCodec {
|
||||||
Some(pos) if !src.is_empty() => {
|
Some(pos) if !src.is_empty() => {
|
||||||
let buf = src.split_to(pos + 1);
|
let buf = src.split_to(pos + 1);
|
||||||
String::from_utf8(buf.to_vec())
|
String::from_utf8(buf.to_vec())
|
||||||
.map(value::line)
|
.map(UntaggedValue::line)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(|e| Error::new(ErrorKind::InvalidData, e))
|
.map_err(|e| Error::new(ErrorKind::InvalidData, e))
|
||||||
}
|
}
|
||||||
_ if !src.is_empty() => {
|
_ if !src.is_empty() => {
|
||||||
let drained = src.take();
|
let drained = src.take();
|
||||||
String::from_utf8(drained.to_vec())
|
String::from_utf8(drained.to_vec())
|
||||||
.map(value::string)
|
.map(UntaggedValue::string)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(|e| Error::new(ErrorKind::InvalidData, e))
|
.map_err(|e| Error::new(ErrorKind::InvalidData, e))
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub(crate) async fn run_internal_command(
|
||||||
} => {
|
} => {
|
||||||
context.shell_manager.insert_at_current(Box::new(
|
context.shell_manager.insert_at_current(Box::new(
|
||||||
HelpShell::for_command(
|
HelpShell::for_command(
|
||||||
value::string(cmd).into_value(tag),
|
UntaggedValue::string(cmd).into_value(tag),
|
||||||
&context.registry(),
|
&context.registry(),
|
||||||
).unwrap(),
|
).unwrap(),
|
||||||
));
|
));
|
||||||
|
@ -114,7 +114,7 @@ pub(crate) async fn run_internal_command(
|
||||||
|
|
||||||
let value = String::from_utf8_lossy(buffer.as_slice());
|
let value = String::from_utf8_lossy(buffer.as_slice());
|
||||||
|
|
||||||
yield Ok(value::string(value).into_untagged_value())
|
yield Ok(UntaggedValue::string(value).into_untagged_value())
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use nu_protocol::UntaggedValue;
|
||||||
|
|
||||||
mod dynamic;
|
mod dynamic;
|
||||||
pub(crate) mod external;
|
pub(crate) mod external;
|
||||||
|
@ -17,7 +17,7 @@ pub(crate) struct ClassifiedInputStream {
|
||||||
impl ClassifiedInputStream {
|
impl ClassifiedInputStream {
|
||||||
pub(crate) fn new() -> ClassifiedInputStream {
|
pub(crate) fn new() -> ClassifiedInputStream {
|
||||||
ClassifiedInputStream {
|
ClassifiedInputStream {
|
||||||
objects: vec![value::nothing().into_value(Tag::unknown())].into(),
|
objects: vec![UntaggedValue::nothing().into_value(Tag::unknown())].into(),
|
||||||
stdin: None,
|
stdin: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, Value};
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct Count;
|
pub struct Count;
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ pub fn count(
|
||||||
let stream = async_stream! {
|
let stream = async_stream! {
|
||||||
let rows: Vec<Value> = input.values.collect().await;
|
let rows: Vec<Value> = input.values.collect().await;
|
||||||
|
|
||||||
yield ReturnSuccess::value(value::int(rows.len()).into_value(name))
|
yield ReturnSuccess::value(UntaggedValue::int(rows.len()).into_value(name))
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(stream.to_output_stream())
|
Ok(stream.to_output_stream())
|
||||||
|
|
|
@ -4,7 +4,6 @@ use nu_errors::ShellError;
|
||||||
use nu_protocol::{Dictionary, Value};
|
use nu_protocol::{Dictionary, Value};
|
||||||
|
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use chrono::{Datelike, TimeZone, Timelike};
|
use chrono::{Datelike, TimeZone, Timelike};
|
||||||
use core::fmt::Display;
|
use core::fmt::Display;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
@ -42,23 +41,35 @@ where
|
||||||
{
|
{
|
||||||
let mut indexmap = IndexMap::new();
|
let mut indexmap = IndexMap::new();
|
||||||
|
|
||||||
indexmap.insert("year".to_string(), value::int(dt.year()).into_value(&tag));
|
indexmap.insert(
|
||||||
indexmap.insert("month".to_string(), value::int(dt.month()).into_value(&tag));
|
"year".to_string(),
|
||||||
indexmap.insert("day".to_string(), value::int(dt.day()).into_value(&tag));
|
UntaggedValue::int(dt.year()).into_value(&tag),
|
||||||
indexmap.insert("hour".to_string(), value::int(dt.hour()).into_value(&tag));
|
);
|
||||||
|
indexmap.insert(
|
||||||
|
"month".to_string(),
|
||||||
|
UntaggedValue::int(dt.month()).into_value(&tag),
|
||||||
|
);
|
||||||
|
indexmap.insert(
|
||||||
|
"day".to_string(),
|
||||||
|
UntaggedValue::int(dt.day()).into_value(&tag),
|
||||||
|
);
|
||||||
|
indexmap.insert(
|
||||||
|
"hour".to_string(),
|
||||||
|
UntaggedValue::int(dt.hour()).into_value(&tag),
|
||||||
|
);
|
||||||
indexmap.insert(
|
indexmap.insert(
|
||||||
"minute".to_string(),
|
"minute".to_string(),
|
||||||
value::int(dt.minute()).into_value(&tag),
|
UntaggedValue::int(dt.minute()).into_value(&tag),
|
||||||
);
|
);
|
||||||
indexmap.insert(
|
indexmap.insert(
|
||||||
"second".to_string(),
|
"second".to_string(),
|
||||||
value::int(dt.second()).into_value(&tag),
|
UntaggedValue::int(dt.second()).into_value(&tag),
|
||||||
);
|
);
|
||||||
|
|
||||||
let tz = dt.offset();
|
let tz = dt.offset();
|
||||||
indexmap.insert(
|
indexmap.insert(
|
||||||
"timezone".to_string(),
|
"timezone".to_string(),
|
||||||
value::string(format!("{}", tz)).into_value(&tag),
|
UntaggedValue::string(format!("{}", tz)).into_value(&tag),
|
||||||
);
|
);
|
||||||
|
|
||||||
UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag)
|
UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature};
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
||||||
|
|
||||||
pub struct Debug;
|
pub struct Debug;
|
||||||
|
|
||||||
|
@ -37,6 +36,8 @@ fn debug_value(
|
||||||
) -> Result<impl ToOutputStream, ShellError> {
|
) -> Result<impl ToOutputStream, ShellError> {
|
||||||
Ok(input
|
Ok(input
|
||||||
.values
|
.values
|
||||||
.map(|v| ReturnSuccess::value(value::string(format!("{:?}", v)).into_untagged_value()))
|
.map(|v| {
|
||||||
|
ReturnSuccess::value(UntaggedValue::string(format!("{:?}", v)).into_untagged_value())
|
||||||
|
})
|
||||||
.to_output_stream())
|
.to_output_stream())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{CallInfo, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{CallInfo, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
|
@ -41,7 +40,7 @@ fn run(
|
||||||
match i.as_string() {
|
match i.as_string() {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
output.push(Ok(ReturnSuccess::Value(
|
output.push(Ok(ReturnSuccess::Value(
|
||||||
value::string(s).into_value(i.tag.clone()),
|
UntaggedValue::string(s).into_value(i.tag.clone()),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
_ => match i {
|
_ => match i {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::commands::PerItemCommand;
|
use crate::commands::PerItemCommand;
|
||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
|
@ -54,12 +53,12 @@ impl PerItemCommand for Enter {
|
||||||
|
|
||||||
if registry.has(command) {
|
if registry.has(command) {
|
||||||
Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell(
|
Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell(
|
||||||
value::string(command).into_value(Tag::unknown()),
|
UntaggedValue::string(command).into_value(Tag::unknown()),
|
||||||
)))]
|
)))]
|
||||||
.into())
|
.into())
|
||||||
} else {
|
} else {
|
||||||
Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell(
|
Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell(
|
||||||
value::nothing().into_value(Tag::unknown()),
|
UntaggedValue::nothing().into_value(Tag::unknown()),
|
||||||
)))]
|
)))]
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use crate::cli::History;
|
use crate::cli::History;
|
||||||
use crate::data::{config, value};
|
use crate::data::config;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::TaggedDictBuilder;
|
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Dictionary, Signature, UntaggedValue, Value};
|
use nu_protocol::{Dictionary, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
@ -36,24 +35,39 @@ pub fn get_environment(tag: Tag) -> Result<Value, Box<dyn std::error::Error>> {
|
||||||
let mut indexmap = IndexMap::new();
|
let mut indexmap = IndexMap::new();
|
||||||
|
|
||||||
let path = std::env::current_dir()?;
|
let path = std::env::current_dir()?;
|
||||||
indexmap.insert("cwd".to_string(), value::path(path).into_value(&tag));
|
indexmap.insert(
|
||||||
|
"cwd".to_string(),
|
||||||
|
UntaggedValue::path(path).into_value(&tag),
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(home) = dirs::home_dir() {
|
if let Some(home) = dirs::home_dir() {
|
||||||
indexmap.insert("home".to_string(), value::path(home).into_value(&tag));
|
indexmap.insert(
|
||||||
|
"home".to_string(),
|
||||||
|
UntaggedValue::path(home).into_value(&tag),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = config::default_path()?;
|
let config = config::default_path()?;
|
||||||
indexmap.insert("config".to_string(), value::path(config).into_value(&tag));
|
indexmap.insert(
|
||||||
|
"config".to_string(),
|
||||||
|
UntaggedValue::path(config).into_value(&tag),
|
||||||
|
);
|
||||||
|
|
||||||
let history = History::path();
|
let history = History::path();
|
||||||
indexmap.insert("history".to_string(), value::path(history).into_value(&tag));
|
indexmap.insert(
|
||||||
|
"history".to_string(),
|
||||||
|
UntaggedValue::path(history).into_value(&tag),
|
||||||
|
);
|
||||||
|
|
||||||
let temp = std::env::temp_dir();
|
let temp = std::env::temp_dir();
|
||||||
indexmap.insert("temp".to_string(), value::path(temp).into_value(&tag));
|
indexmap.insert(
|
||||||
|
"temp".to_string(),
|
||||||
|
UntaggedValue::path(temp).into_value(&tag),
|
||||||
|
);
|
||||||
|
|
||||||
let mut dict = TaggedDictBuilder::new(&tag);
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
for v in std::env::vars() {
|
for v in std::env::vars() {
|
||||||
dict.insert_untagged(v.0, value::string(v.1));
|
dict.insert_untagged(v.0, UntaggedValue::string(v.1));
|
||||||
}
|
}
|
||||||
if !dict.is_empty() {
|
if !dict.is_empty() {
|
||||||
indexmap.insert("vars".to_string(), dict.into_value());
|
indexmap.insert("vars".to_string(), dict.into_value());
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
|
@ -73,7 +72,7 @@ pub fn evaluate_by(
|
||||||
fn fetch(key: Option<String>) -> Box<dyn Fn(Value, Tag) -> Option<Value> + 'static> {
|
fn fetch(key: Option<String>) -> Box<dyn Fn(Value, Tag) -> Option<Value> + 'static> {
|
||||||
Box::new(move |value: Value, tag| match &key {
|
Box::new(move |value: Value, tag| match &key {
|
||||||
Some(key_given) => value.get_data_by_key(key_given[..].spanned(tag.span)),
|
Some(key_given) => value.get_data_by_key(key_given[..].spanned(tag.span)),
|
||||||
None => Some(value::int(1).into_value(tag)),
|
None => Some(UntaggedValue::int(1).into_value(tag)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,19 +144,19 @@ mod tests {
|
||||||
use nu_source::TaggedItem;
|
use nu_source::TaggedItem;
|
||||||
|
|
||||||
fn int(s: impl Into<BigInt>) -> Value {
|
fn int(s: impl Into<BigInt>) -> Value {
|
||||||
value::int(s).into_untagged_value()
|
UntaggedValue::int(s).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
value::string(input.into()).into_untagged_value()
|
UntaggedValue::string(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row(entries: IndexMap<String, Value>) -> Value {
|
fn row(entries: IndexMap<String, Value>) -> Value {
|
||||||
value::row(entries).into_untagged_value()
|
UntaggedValue::row(entries).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table(list: &Vec<Value>) -> Value {
|
fn table(list: &Vec<Value>) -> Value {
|
||||||
value::table(list).into_untagged_value()
|
UntaggedValue::table(list).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nu_releases_sorted_by_date() -> Value {
|
fn nu_releases_sorted_by_date() -> Value {
|
||||||
|
@ -225,7 +224,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
evaluator(subject, Tag::unknown()),
|
evaluator(subject, Tag::unknown()),
|
||||||
Some(value::int(1).into_untagged_value())
|
Some(UntaggedValue::int(1).into_untagged_value())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
|
@ -146,7 +145,7 @@ pub async fn fetch(
|
||||||
match (content_type.type_(), content_type.subtype()) {
|
match (content_type.type_(), content_type.subtype()) {
|
||||||
(mime::APPLICATION, mime::XML) => Ok((
|
(mime::APPLICATION, mime::XML) => Ok((
|
||||||
Some("xml".to_string()),
|
Some("xml".to_string()),
|
||||||
value::string(r.body_string().await.map_err(|_| {
|
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load text from remote url",
|
"Could not load text from remote url",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -160,7 +159,7 @@ pub async fn fetch(
|
||||||
)),
|
)),
|
||||||
(mime::APPLICATION, mime::JSON) => Ok((
|
(mime::APPLICATION, mime::JSON) => Ok((
|
||||||
Some("json".to_string()),
|
Some("json".to_string()),
|
||||||
value::string(r.body_string().await.map_err(|_| {
|
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load text from remote url",
|
"Could not load text from remote url",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -182,7 +181,7 @@ pub async fn fetch(
|
||||||
})?;
|
})?;
|
||||||
Ok((
|
Ok((
|
||||||
None,
|
None,
|
||||||
value::binary(buf),
|
UntaggedValue::binary(buf),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::Url(location.to_string())),
|
anchor: Some(AnchorLocation::Url(location.to_string())),
|
||||||
|
@ -191,7 +190,7 @@ pub async fn fetch(
|
||||||
}
|
}
|
||||||
(mime::IMAGE, mime::SVG) => Ok((
|
(mime::IMAGE, mime::SVG) => Ok((
|
||||||
Some("svg".to_string()),
|
Some("svg".to_string()),
|
||||||
value::string(r.body_string().await.map_err(|_| {
|
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load svg from remote url",
|
"Could not load svg from remote url",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -213,7 +212,7 @@ pub async fn fetch(
|
||||||
})?;
|
})?;
|
||||||
Ok((
|
Ok((
|
||||||
Some(image_ty.to_string()),
|
Some(image_ty.to_string()),
|
||||||
value::binary(buf),
|
UntaggedValue::binary(buf),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::Url(location.to_string())),
|
anchor: Some(AnchorLocation::Url(location.to_string())),
|
||||||
|
@ -222,7 +221,7 @@ pub async fn fetch(
|
||||||
}
|
}
|
||||||
(mime::TEXT, mime::HTML) => Ok((
|
(mime::TEXT, mime::HTML) => Ok((
|
||||||
Some("html".to_string()),
|
Some("html".to_string()),
|
||||||
value::string(r.body_string().await.map_err(|_| {
|
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load text from remote url",
|
"Could not load text from remote url",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -248,7 +247,7 @@ pub async fn fetch(
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
path_extension,
|
path_extension,
|
||||||
value::string(r.body_string().await.map_err(|_| {
|
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load text from remote url",
|
"Could not load text from remote url",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -263,7 +262,10 @@ pub async fn fetch(
|
||||||
}
|
}
|
||||||
(ty, sub_ty) => Ok((
|
(ty, sub_ty) => Ok((
|
||||||
None,
|
None,
|
||||||
value::string(format!("Not yet supported MIME type: {} {}", ty, sub_ty)),
|
UntaggedValue::string(format!(
|
||||||
|
"Not yet supported MIME type: {} {}",
|
||||||
|
ty, sub_ty
|
||||||
|
)),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::Url(location.to_string())),
|
anchor: Some(AnchorLocation::Url(location.to_string())),
|
||||||
|
@ -273,7 +275,7 @@ pub async fn fetch(
|
||||||
}
|
}
|
||||||
None => Ok((
|
None => Ok((
|
||||||
None,
|
None,
|
||||||
value::string(format!("No content type found")),
|
UntaggedValue::string(format!("No content type found")),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::Url(location.to_string())),
|
anchor: Some(AnchorLocation::Url(location.to_string())),
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use bson::{decode_document, spec::BinarySubtype, Bson};
|
use bson::{decode_document, spec::BinarySubtype, Bson};
|
||||||
use nu_errors::{ExpectedRange, ShellError};
|
use nu_errors::{ExpectedRange, ShellError};
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use nu_source::SpannedItem;
|
use nu_source::SpannedItem;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -74,8 +72,8 @@ fn convert_bson_value_to_nu_value(v: &Bson, tag: impl Into<Tag>) -> Result<Value
|
||||||
);
|
);
|
||||||
collected.into_value()
|
collected.into_value()
|
||||||
}
|
}
|
||||||
Bson::I32(n) => value::number(n).into_value(&tag),
|
Bson::I32(n) => UntaggedValue::int(*n).into_value(&tag),
|
||||||
Bson::I64(n) => value::number(n).into_value(&tag),
|
Bson::I64(n) => UntaggedValue::int(*n).into_value(&tag),
|
||||||
Bson::Decimal128(n) => {
|
Bson::Decimal128(n) => {
|
||||||
// TODO: this really isn't great, and we should update this to do a higher
|
// TODO: this really isn't great, and we should update this to do a higher
|
||||||
// fidelity translation
|
// fidelity translation
|
||||||
|
@ -110,7 +108,10 @@ fn convert_bson_value_to_nu_value(v: &Bson, tag: impl Into<Tag>) -> Result<Value
|
||||||
}
|
}
|
||||||
Bson::TimeStamp(ts) => {
|
Bson::TimeStamp(ts) => {
|
||||||
let mut collected = TaggedDictBuilder::new(tag.clone());
|
let mut collected = TaggedDictBuilder::new(tag.clone());
|
||||||
collected.insert_value("$timestamp".to_string(), value::number(ts).into_value(&tag));
|
collected.insert_value(
|
||||||
|
"$timestamp".to_string(),
|
||||||
|
UntaggedValue::int(*ts).into_value(&tag),
|
||||||
|
);
|
||||||
collected.into_value()
|
collected.into_value()
|
||||||
}
|
}
|
||||||
Bson::Binary(bst, bytes) => {
|
Bson::Binary(bst, bytes) => {
|
||||||
|
@ -118,7 +119,7 @@ fn convert_bson_value_to_nu_value(v: &Bson, tag: impl Into<Tag>) -> Result<Value
|
||||||
collected.insert_value(
|
collected.insert_value(
|
||||||
"$binary_subtype".to_string(),
|
"$binary_subtype".to_string(),
|
||||||
match bst {
|
match bst {
|
||||||
BinarySubtype::UserDefined(u) => value::number(u),
|
BinarySubtype::UserDefined(u) => UntaggedValue::int(*u),
|
||||||
_ => {
|
_ => {
|
||||||
UntaggedValue::Primitive(Primitive::String(binary_subtype_to_string(*bst)))
|
UntaggedValue::Primitive(Primitive::String(binary_subtype_to_string(*bst)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use csv::ReaderBuilder;
|
use csv::ReaderBuilder;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
fn from_delimited_string_to_value(
|
fn from_delimited_string_to_value(
|
||||||
s: String,
|
s: String,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct FromINI;
|
pub struct FromINI;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromJSON;
|
pub struct FromJSON;
|
||||||
|
|
||||||
|
@ -38,10 +37,10 @@ fn convert_json_value_to_nu_value(v: &serde_hjson::Value, tag: impl Into<Tag>) -
|
||||||
|
|
||||||
match v {
|
match v {
|
||||||
serde_hjson::Value::Null => UntaggedValue::Primitive(Primitive::Nothing).into_value(&tag),
|
serde_hjson::Value::Null => UntaggedValue::Primitive(Primitive::Nothing).into_value(&tag),
|
||||||
serde_hjson::Value::Bool(b) => value::boolean(*b).into_value(&tag),
|
serde_hjson::Value::Bool(b) => UntaggedValue::boolean(*b).into_value(&tag),
|
||||||
serde_hjson::Value::F64(n) => value::number(n).into_value(&tag),
|
serde_hjson::Value::F64(n) => UntaggedValue::decimal(*n).into_value(&tag),
|
||||||
serde_hjson::Value::U64(n) => value::number(n).into_value(&tag),
|
serde_hjson::Value::U64(n) => UntaggedValue::int(*n).into_value(&tag),
|
||||||
serde_hjson::Value::I64(n) => value::number(n).into_value(&tag),
|
serde_hjson::Value::I64(n) => UntaggedValue::int(*n).into_value(&tag),
|
||||||
serde_hjson::Value::String(s) => {
|
serde_hjson::Value::String(s) => {
|
||||||
UntaggedValue::Primitive(Primitive::String(String::from(s))).into_value(&tag)
|
UntaggedValue::Primitive(Primitive::String(String::from(s))).into_value(&tag)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use rusqlite::{types::ValueRef, Connection, Row, NO_PARAMS};
|
use rusqlite::{types::ValueRef, Connection, Row, NO_PARAMS};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -106,14 +105,14 @@ fn convert_sqlite_value_to_nu_value(value: ValueRef, tag: impl Into<Tag> + Clone
|
||||||
ValueRef::Null => {
|
ValueRef::Null => {
|
||||||
UntaggedValue::Primitive(Primitive::String(String::from(""))).into_value(tag)
|
UntaggedValue::Primitive(Primitive::String(String::from(""))).into_value(tag)
|
||||||
}
|
}
|
||||||
ValueRef::Integer(i) => value::number(i).into_value(tag),
|
ValueRef::Integer(i) => UntaggedValue::int(i).into_value(tag),
|
||||||
ValueRef::Real(f) => value::number(f).into_value(tag),
|
ValueRef::Real(f) => UntaggedValue::decimal(f).into_value(tag),
|
||||||
t @ ValueRef::Text(_) => {
|
t @ ValueRef::Text(_) => {
|
||||||
// this unwrap is safe because we know the ValueRef is Text.
|
// this unwrap is safe because we know the ValueRef is Text.
|
||||||
UntaggedValue::Primitive(Primitive::String(t.as_str().unwrap().to_string()))
|
UntaggedValue::Primitive(Primitive::String(t.as_str().unwrap().to_string()))
|
||||||
.into_value(tag)
|
.into_value(tag)
|
||||||
}
|
}
|
||||||
ValueRef::Blob(u) => value::binary(u.to_owned()).into_value(tag),
|
ValueRef::Blob(u) => UntaggedValue::binary(u.to_owned()).into_value(tag),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{
|
||||||
|
Primitive, ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue, Value,
|
||||||
|
};
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
|
|
||||||
pub struct FromSSV;
|
pub struct FromSSV;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromTOML;
|
pub struct FromTOML;
|
||||||
|
|
||||||
|
@ -32,9 +31,9 @@ pub fn convert_toml_value_to_nu_value(v: &toml::Value, tag: impl Into<Tag>) -> V
|
||||||
let tag = tag.into();
|
let tag = tag.into();
|
||||||
|
|
||||||
match v {
|
match v {
|
||||||
toml::Value::Boolean(b) => value::boolean(*b).into_value(tag),
|
toml::Value::Boolean(b) => UntaggedValue::boolean(*b).into_value(tag),
|
||||||
toml::Value::Integer(n) => value::number(n).into_value(tag),
|
toml::Value::Integer(n) => UntaggedValue::int(*n).into_value(tag),
|
||||||
toml::Value::Float(n) => value::number(n).into_value(tag),
|
toml::Value::Float(n) => UntaggedValue::decimal(*n).into_value(tag),
|
||||||
toml::Value::String(s) => {
|
toml::Value::String(s) => {
|
||||||
UntaggedValue::Primitive(Primitive::String(String::from(s))).into_value(tag)
|
UntaggedValue::Primitive(Primitive::String(String::from(s))).into_value(tag)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, Value};
|
use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromURL;
|
pub struct FromURL;
|
||||||
|
|
||||||
|
@ -64,7 +62,7 @@ fn from_url(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
|
||||||
let mut row = TaggedDictBuilder::new(tag);
|
let mut row = TaggedDictBuilder::new(tag);
|
||||||
|
|
||||||
for (k,v) in result {
|
for (k,v) in result {
|
||||||
row.insert_untagged(k, value::string(v));
|
row.insert_untagged(k, UntaggedValue::string(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
yield ReturnSuccess::value(row.into_value());
|
yield ReturnSuccess::value(row.into_value());
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::{TaggedDictBuilder, TaggedListBuilder};
|
use crate::TaggedListBuilder;
|
||||||
use calamine::*;
|
use calamine::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
pub struct FromXLSX;
|
pub struct FromXLSX;
|
||||||
|
@ -71,12 +70,12 @@ fn from_xlsx(
|
||||||
let mut row_output = TaggedDictBuilder::new(&tag);
|
let mut row_output = TaggedDictBuilder::new(&tag);
|
||||||
for (i, cell) in row.iter().enumerate() {
|
for (i, cell) in row.iter().enumerate() {
|
||||||
let value = match cell {
|
let value = match cell {
|
||||||
DataType::Empty => value::nothing(),
|
DataType::Empty => UntaggedValue::nothing(),
|
||||||
DataType::String(s) => value::string(s),
|
DataType::String(s) => UntaggedValue::string(s),
|
||||||
DataType::Float(f) => value::decimal(*f),
|
DataType::Float(f) => UntaggedValue::decimal(*f),
|
||||||
DataType::Int(i) => value::int(*i),
|
DataType::Int(i) => UntaggedValue::int(*i),
|
||||||
DataType::Bool(b) => value::boolean(*b),
|
DataType::Bool(b) => UntaggedValue::boolean(*b),
|
||||||
_ => value::nothing(),
|
_ => UntaggedValue::nothing(),
|
||||||
};
|
};
|
||||||
|
|
||||||
row_output.insert_untagged(&format!("Column{}", i), value);
|
row_output.insert_untagged(&format!("Column{}", i), value);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromXML;
|
pub struct FromXML;
|
||||||
|
|
||||||
|
@ -61,13 +60,13 @@ fn from_node_to_value<'a, 'd>(n: &roxmltree::Node<'a, 'd>, tag: impl Into<Tag>)
|
||||||
|
|
||||||
collected.into_value()
|
collected.into_value()
|
||||||
} else if n.is_comment() {
|
} else if n.is_comment() {
|
||||||
value::string("<comment>").into_value(tag)
|
UntaggedValue::string("<comment>").into_value(tag)
|
||||||
} else if n.is_pi() {
|
} else if n.is_pi() {
|
||||||
value::string("<processing_instruction>").into_value(tag)
|
UntaggedValue::string("<processing_instruction>").into_value(tag)
|
||||||
} else if n.is_text() {
|
} else if n.is_text() {
|
||||||
value::string(n.text().unwrap()).into_value(tag)
|
UntaggedValue::string(n.text().unwrap()).into_value(tag)
|
||||||
} else {
|
} else {
|
||||||
value::string("<unknown>").into_value(tag)
|
UntaggedValue::string("<unknown>").into_value(tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,21 +137,20 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::commands::from_xml;
|
use crate::commands::from_xml;
|
||||||
use crate::data::value;
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_protocol::Value;
|
use nu_protocol::{UntaggedValue, Value};
|
||||||
use nu_source::*;
|
use nu_source::*;
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
value::string(input.into()).into_untagged_value()
|
UntaggedValue::string(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row(entries: IndexMap<String, Value>) -> Value {
|
fn row(entries: IndexMap<String, Value>) -> Value {
|
||||||
value::row(entries).into_untagged_value()
|
UntaggedValue::row(entries).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table(list: &Vec<Value>) -> Value {
|
fn table(list: &Vec<Value>) -> Value {
|
||||||
value::table(list).into_untagged_value()
|
UntaggedValue::table(list).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(xml: &str) -> Value {
|
fn parse(xml: &str) -> Value {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromYAML;
|
pub struct FromYAML;
|
||||||
|
|
||||||
|
@ -56,14 +55,14 @@ fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, tag: impl Into<Tag>) ->
|
||||||
let tag = tag.into();
|
let tag = tag.into();
|
||||||
|
|
||||||
match v {
|
match v {
|
||||||
serde_yaml::Value::Bool(b) => value::boolean(*b).into_value(tag),
|
serde_yaml::Value::Bool(b) => UntaggedValue::boolean(*b).into_value(tag),
|
||||||
serde_yaml::Value::Number(n) if n.is_i64() => {
|
serde_yaml::Value::Number(n) if n.is_i64() => {
|
||||||
value::number(n.as_i64().unwrap()).into_value(tag)
|
UntaggedValue::int(n.as_i64().unwrap()).into_value(tag)
|
||||||
}
|
}
|
||||||
serde_yaml::Value::Number(n) if n.is_f64() => {
|
serde_yaml::Value::Number(n) if n.is_f64() => {
|
||||||
UntaggedValue::Primitive(Primitive::from(n.as_f64().unwrap())).into_value(tag)
|
UntaggedValue::decimal(n.as_f64().unwrap()).into_value(tag)
|
||||||
}
|
}
|
||||||
serde_yaml::Value::String(s) => value::string(s).into_value(tag),
|
serde_yaml::Value::String(s) => UntaggedValue::string(s).into_value(tag),
|
||||||
serde_yaml::Value::Sequence(a) => UntaggedValue::Table(
|
serde_yaml::Value::Sequence(a) => UntaggedValue::Table(
|
||||||
a.iter()
|
a.iter()
|
||||||
.map(|x| convert_yaml_value_to_nu_value(x, &tag))
|
.map(|x| convert_yaml_value_to_nu_value(x, &tag))
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::base::property_get::get_data_by_key;
|
use crate::data::base::property_get::get_data_by_key;
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, Value};
|
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
|
|
||||||
pub struct GroupBy;
|
pub struct GroupBy;
|
||||||
|
@ -108,7 +107,7 @@ pub fn group(
|
||||||
let mut out = TaggedDictBuilder::new(&tag);
|
let mut out = TaggedDictBuilder::new(&tag);
|
||||||
|
|
||||||
for (k, v) in groups.iter() {
|
for (k, v) in groups.iter() {
|
||||||
out.insert_untagged(k, value::table(v));
|
out.insert_untagged(k, UntaggedValue::table(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(out.into_value())
|
Ok(out.into_value())
|
||||||
|
@ -117,21 +116,20 @@ pub fn group(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::commands::group_by::group;
|
use crate::commands::group_by::group;
|
||||||
use crate::data::value;
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_protocol::Value;
|
use nu_protocol::{UntaggedValue, Value};
|
||||||
use nu_source::*;
|
use nu_source::*;
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
value::string(input.into()).into_untagged_value()
|
UntaggedValue::string(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row(entries: IndexMap<String, Value>) -> Value {
|
fn row(entries: IndexMap<String, Value>) -> Value {
|
||||||
value::row(entries).into_untagged_value()
|
UntaggedValue::row(entries).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table(list: &Vec<Value>) -> Value {
|
fn table(list: &Vec<Value>) -> Value {
|
||||||
value::table(list).into_untagged_value()
|
UntaggedValue::table(list).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nu_releases_commiters() -> Vec<Value> {
|
fn nu_releases_commiters() -> Vec<Value> {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::commands::PerItemCommand;
|
use crate::commands::PerItemCommand;
|
||||||
use crate::data::base::property_get::get_data_by_key;
|
use crate::data::base::property_get::get_data_by_key;
|
||||||
use crate::data::{command_dict, TaggedDictBuilder};
|
use crate::data::command_dict;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
CallInfo, NamedType, PositionalType, Primitive, ReturnSuccess, Signature, SyntaxShape,
|
CallInfo, NamedType, PositionalType, Primitive, ReturnSuccess, Signature, SyntaxShape,
|
||||||
UntaggedValue, Value,
|
TaggedDictBuilder, UntaggedValue, Value,
|
||||||
};
|
};
|
||||||
use nu_source::SpannedItem;
|
use nu_source::SpannedItem;
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ impl PerItemCommand for Help {
|
||||||
}
|
}
|
||||||
|
|
||||||
help.push_back(ReturnSuccess::value(
|
help.push_back(ReturnSuccess::value(
|
||||||
value::string(long_desc).into_value(tag.clone()),
|
UntaggedValue::string(long_desc).into_value(tag.clone()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,9 @@ You can also learn more at https://book.nushell.sh"#;
|
||||||
|
|
||||||
let mut output_stream = VecDeque::new();
|
let mut output_stream = VecDeque::new();
|
||||||
|
|
||||||
output_stream.push_back(ReturnSuccess::value(value::string(msg).into_value(tag)));
|
output_stream.push_back(ReturnSuccess::value(
|
||||||
|
UntaggedValue::string(msg).into_value(tag),
|
||||||
|
));
|
||||||
|
|
||||||
Ok(output_stream.to_output_stream())
|
Ok(output_stream.to_output_stream())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@ use crate::commands::reduce_by::reduce;
|
||||||
use crate::commands::t_sort_by::columns_sorted;
|
use crate::commands::t_sort_by::columns_sorted;
|
||||||
use crate::commands::t_sort_by::t_sort;
|
use crate::commands::t_sort_by::t_sort;
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{
|
||||||
|
Primitive, ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue, Value,
|
||||||
|
};
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
use num_traits::cast::ToPrimitive;
|
use num_traits::cast::ToPrimitive;
|
||||||
|
|
||||||
|
@ -91,11 +92,11 @@ pub fn histogram(
|
||||||
|
|
||||||
let mut fact = TaggedDictBuilder::new(&name);
|
let mut fact = TaggedDictBuilder::new(&name);
|
||||||
let value: Tagged<String> = group_labels.get(idx).unwrap().clone();
|
let value: Tagged<String> = group_labels.get(idx).unwrap().clone();
|
||||||
fact.insert_value(&column, value::string(value.item).into_value(value.tag));
|
fact.insert_value(&column, UntaggedValue::string(value.item).into_value(value.tag));
|
||||||
|
|
||||||
if let Value { value: UntaggedValue::Primitive(Primitive::Int(ref num)), .. } = percentage.clone() {
|
if let Value { value: UntaggedValue::Primitive(Primitive::Int(ref num)), .. } = percentage.clone() {
|
||||||
let string = std::iter::repeat("*").take(num.to_i32().unwrap() as usize).collect::<String>();
|
let string = std::iter::repeat("*").take(num.to_i32().unwrap() as usize).collect::<String>();
|
||||||
fact.insert_untagged(&frequency_column_name, value::string(string));
|
fact.insert_untagged(&frequency_column_name, UntaggedValue::string(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = idx + 1;
|
idx = idx + 1;
|
||||||
|
@ -146,9 +147,9 @@ fn percentages(values: &Value, max: Value, tag: impl Into<Tag>) -> Result<Value,
|
||||||
|
|
||||||
let n = { n.to_i32().unwrap() * 100 / max };
|
let n = { n.to_i32().unwrap() * 100 / max };
|
||||||
|
|
||||||
value::number(n).into_value(&tag)
|
UntaggedValue::int(n).into_value(&tag)
|
||||||
}
|
}
|
||||||
_ => value::number(0).into_value(&tag),
|
_ => UntaggedValue::int(0).into_value(&tag),
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
UntaggedValue::Table(data).into_value(&tag)
|
UntaggedValue::Table(data).into_value(&tag)
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use crate::cli::History as HistoryFile;
|
use crate::cli::History as HistoryFile;
|
||||||
use crate::commands::PerItemCommand;
|
use crate::commands::PerItemCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{CallInfo, ReturnSuccess, Signature, Value};
|
use nu_protocol::{CallInfo, ReturnSuccess, Signature, UntaggedValue, Value};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
|
|
||||||
|
@ -38,7 +37,7 @@ impl PerItemCommand for History {
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
for line in reader.lines() {
|
for line in reader.lines() {
|
||||||
if let Ok(line) = line {
|
if let Ok(line) = line {
|
||||||
yield ReturnSuccess::value(value::string(line).into_value(tag.clone()));
|
yield ReturnSuccess::value(UntaggedValue::string(line).into_value(tag.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -103,9 +103,9 @@ pub fn map_max(
|
||||||
}
|
}
|
||||||
_ => acc,
|
_ => acc,
|
||||||
});
|
});
|
||||||
value::number(data).into_value(&tag)
|
UntaggedValue::int(data).into_value(&tag)
|
||||||
}
|
}
|
||||||
_ => value::number(0).into_value(&tag),
|
_ => UntaggedValue::int(0).into_value(&tag),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -122,9 +122,9 @@ pub fn map_max(
|
||||||
}
|
}
|
||||||
_ => max,
|
_ => max,
|
||||||
});
|
});
|
||||||
value::number(datasets).into_value(&tag)
|
UntaggedValue::int(datasets).into_value(&tag)
|
||||||
}
|
}
|
||||||
_ => value::number(-1).into_value(&tag),
|
_ => UntaggedValue::int(-1).into_value(&tag),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(results)
|
Ok(results)
|
||||||
|
@ -144,15 +144,15 @@ mod tests {
|
||||||
use nu_source::*;
|
use nu_source::*;
|
||||||
|
|
||||||
fn int(s: impl Into<BigInt>) -> Value {
|
fn int(s: impl Into<BigInt>) -> Value {
|
||||||
value::int(s).into_untagged_value()
|
UntaggedValue::int(s).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
value::string(input.into()).into_untagged_value()
|
UntaggedValue::string(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row(entries: IndexMap<String, Value>) -> Value {
|
fn row(entries: IndexMap<String, Value>) -> Value {
|
||||||
value::row(entries).into_untagged_value()
|
UntaggedValue::row(entries).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nu_releases_evaluated_by_default_one() -> Value {
|
fn nu_releases_evaluated_by_default_one() -> Value {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{CallInfo, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{CallInfo, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
|
@ -140,7 +139,7 @@ pub async fn fetch(
|
||||||
Ok(s) => Ok((
|
Ok(s) => Ok((
|
||||||
cwd.extension()
|
cwd.extension()
|
||||||
.map(|name| name.to_string_lossy().to_string()),
|
.map(|name| name.to_string_lossy().to_string()),
|
||||||
value::string(s),
|
UntaggedValue::string(s),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::File(cwd.to_string_lossy().to_string())),
|
anchor: Some(AnchorLocation::File(cwd.to_string_lossy().to_string())),
|
||||||
|
@ -158,7 +157,7 @@ pub async fn fetch(
|
||||||
Ok(s) => Ok((
|
Ok(s) => Ok((
|
||||||
cwd.extension()
|
cwd.extension()
|
||||||
.map(|name| name.to_string_lossy().to_string()),
|
.map(|name| name.to_string_lossy().to_string()),
|
||||||
value::string(s),
|
UntaggedValue::string(s),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::File(
|
anchor: Some(AnchorLocation::File(
|
||||||
|
@ -168,7 +167,7 @@ pub async fn fetch(
|
||||||
)),
|
)),
|
||||||
Err(_) => Ok((
|
Err(_) => Ok((
|
||||||
None,
|
None,
|
||||||
value::binary(bytes),
|
UntaggedValue::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::File(
|
anchor: Some(AnchorLocation::File(
|
||||||
|
@ -180,7 +179,7 @@ pub async fn fetch(
|
||||||
} else {
|
} else {
|
||||||
Ok((
|
Ok((
|
||||||
None,
|
None,
|
||||||
value::binary(bytes),
|
UntaggedValue::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::File(
|
anchor: Some(AnchorLocation::File(
|
||||||
|
@ -199,7 +198,7 @@ pub async fn fetch(
|
||||||
Ok(s) => Ok((
|
Ok(s) => Ok((
|
||||||
cwd.extension()
|
cwd.extension()
|
||||||
.map(|name| name.to_string_lossy().to_string()),
|
.map(|name| name.to_string_lossy().to_string()),
|
||||||
value::string(s),
|
UntaggedValue::string(s),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::File(
|
anchor: Some(AnchorLocation::File(
|
||||||
|
@ -209,7 +208,7 @@ pub async fn fetch(
|
||||||
)),
|
)),
|
||||||
Err(_) => Ok((
|
Err(_) => Ok((
|
||||||
None,
|
None,
|
||||||
value::binary(bytes),
|
UntaggedValue::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::File(
|
anchor: Some(AnchorLocation::File(
|
||||||
|
@ -221,7 +220,7 @@ pub async fn fetch(
|
||||||
} else {
|
} else {
|
||||||
Ok((
|
Ok((
|
||||||
None,
|
None,
|
||||||
value::binary(bytes),
|
UntaggedValue::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::File(
|
anchor: Some(AnchorLocation::File(
|
||||||
|
@ -233,7 +232,7 @@ pub async fn fetch(
|
||||||
}
|
}
|
||||||
_ => Ok((
|
_ => Ok((
|
||||||
None,
|
None,
|
||||||
value::binary(bytes),
|
UntaggedValue::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
anchor: Some(AnchorLocation::File(
|
anchor: Some(AnchorLocation::File(
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::base::property_get::get_data_by_key;
|
use crate::data::base::property_get::get_data_by_key;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::TaggedDictBuilder;
|
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, Value};
|
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use nu_source::{SpannedItem, Tagged};
|
use nu_source::{SpannedItem, Tagged};
|
||||||
|
|
||||||
pub struct Pivot;
|
pub struct Pivot;
|
||||||
|
@ -114,7 +112,7 @@ pub fn pivot(args: PivotArgs, context: RunnableContext) -> Result<OutputStream,
|
||||||
let mut dict = TaggedDictBuilder::new(&context.name);
|
let mut dict = TaggedDictBuilder::new(&context.name);
|
||||||
|
|
||||||
if !args.ignore_titles && !args.header_row {
|
if !args.ignore_titles && !args.header_row {
|
||||||
dict.insert_untagged(headers[column_num].clone(), value::string(desc.clone()));
|
dict.insert_untagged(headers[column_num].clone(), UntaggedValue::string(desc.clone()));
|
||||||
column_num += 1
|
column_num += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +122,7 @@ pub fn pivot(args: PivotArgs, context: RunnableContext) -> Result<OutputStream,
|
||||||
dict.insert_value(headers[column_num].clone(), x.clone());
|
dict.insert_value(headers[column_num].clone(), x.clone());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
dict.insert_untagged(headers[column_num].clone(), value::nothing());
|
dict.insert_untagged(headers[column_num].clone(), UntaggedValue::nothing());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
column_num += 1;
|
column_num += 1;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
@ -316,7 +315,7 @@ pub fn sink_plugin(
|
||||||
|
|
||||||
// Needed for async_stream to type check
|
// Needed for async_stream to type check
|
||||||
if false {
|
if false {
|
||||||
yield ReturnSuccess::value(value::nothing().into_untagged_value());
|
yield ReturnSuccess::value(UntaggedValue::nothing().into_untagged_value());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(OutputStream::new(stream))
|
Ok(OutputStream::new(stream))
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use base64::encode;
|
use base64::encode;
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
|
@ -320,7 +319,7 @@ pub async fn post(
|
||||||
match (content_type.type_(), content_type.subtype()) {
|
match (content_type.type_(), content_type.subtype()) {
|
||||||
(mime::APPLICATION, mime::XML) => Ok((
|
(mime::APPLICATION, mime::XML) => Ok((
|
||||||
Some("xml".to_string()),
|
Some("xml".to_string()),
|
||||||
value::string(r.body_string().await.map_err(|_| {
|
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load text from remote url",
|
"Could not load text from remote url",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -334,7 +333,7 @@ pub async fn post(
|
||||||
)),
|
)),
|
||||||
(mime::APPLICATION, mime::JSON) => Ok((
|
(mime::APPLICATION, mime::JSON) => Ok((
|
||||||
Some("json".to_string()),
|
Some("json".to_string()),
|
||||||
value::string(r.body_string().await.map_err(|_| {
|
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load text from remote url",
|
"Could not load text from remote url",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -356,7 +355,7 @@ pub async fn post(
|
||||||
})?;
|
})?;
|
||||||
Ok((
|
Ok((
|
||||||
None,
|
None,
|
||||||
value::binary(buf),
|
UntaggedValue::binary(buf),
|
||||||
Tag {
|
Tag {
|
||||||
anchor: Some(AnchorLocation::Url(location.to_string())),
|
anchor: Some(AnchorLocation::Url(location.to_string())),
|
||||||
span: tag.span,
|
span: tag.span,
|
||||||
|
@ -373,7 +372,7 @@ pub async fn post(
|
||||||
})?;
|
})?;
|
||||||
Ok((
|
Ok((
|
||||||
Some(image_ty.to_string()),
|
Some(image_ty.to_string()),
|
||||||
value::binary(buf),
|
UntaggedValue::binary(buf),
|
||||||
Tag {
|
Tag {
|
||||||
anchor: Some(AnchorLocation::Url(location.to_string())),
|
anchor: Some(AnchorLocation::Url(location.to_string())),
|
||||||
span: tag.span,
|
span: tag.span,
|
||||||
|
@ -382,7 +381,7 @@ pub async fn post(
|
||||||
}
|
}
|
||||||
(mime::TEXT, mime::HTML) => Ok((
|
(mime::TEXT, mime::HTML) => Ok((
|
||||||
Some("html".to_string()),
|
Some("html".to_string()),
|
||||||
value::string(r.body_string().await.map_err(|_| {
|
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load text from remote url",
|
"Could not load text from remote url",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -408,7 +407,7 @@ pub async fn post(
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
path_extension,
|
path_extension,
|
||||||
value::string(r.body_string().await.map_err(|_| {
|
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load text from remote url",
|
"Could not load text from remote url",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -423,7 +422,7 @@ pub async fn post(
|
||||||
}
|
}
|
||||||
(ty, sub_ty) => Ok((
|
(ty, sub_ty) => Ok((
|
||||||
None,
|
None,
|
||||||
value::string(format!(
|
UntaggedValue::string(format!(
|
||||||
"Not yet supported MIME type: {} {}",
|
"Not yet supported MIME type: {} {}",
|
||||||
ty, sub_ty
|
ty, sub_ty
|
||||||
)),
|
)),
|
||||||
|
@ -436,7 +435,7 @@ pub async fn post(
|
||||||
}
|
}
|
||||||
None => Ok((
|
None => Ok((
|
||||||
None,
|
None,
|
||||||
value::string(format!("No content type found")),
|
UntaggedValue::string(format!("No content type found")),
|
||||||
Tag {
|
Tag {
|
||||||
anchor: Some(AnchorLocation::Url(location.to_string())),
|
anchor: Some(AnchorLocation::Url(location.to_string())),
|
||||||
span: tag.span,
|
span: tag.span,
|
||||||
|
|
|
@ -135,9 +135,9 @@ pub fn reduce(
|
||||||
} = d
|
} = d
|
||||||
{
|
{
|
||||||
acc = reduce_with(acc, x.clone());
|
acc = reduce_with(acc, x.clone());
|
||||||
value::number(acc).into_value(&tag)
|
UntaggedValue::int(acc).into_value(&tag)
|
||||||
} else {
|
} else {
|
||||||
value::number(0).into_value(&tag)
|
UntaggedValue::int(0).into_value(&tag)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -169,19 +169,19 @@ mod tests {
|
||||||
use nu_source::*;
|
use nu_source::*;
|
||||||
|
|
||||||
fn int(s: impl Into<BigInt>) -> Value {
|
fn int(s: impl Into<BigInt>) -> Value {
|
||||||
value::int(s).into_untagged_value()
|
UntaggedValue::int(s).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
value::string(input.into()).into_untagged_value()
|
UntaggedValue::string(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row(entries: IndexMap<String, Value>) -> Value {
|
fn row(entries: IndexMap<String, Value>) -> Value {
|
||||||
value::row(entries).into_untagged_value()
|
UntaggedValue::row(entries).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table(list: &Vec<Value>) -> Value {
|
fn table(list: &Vec<Value>) -> Value {
|
||||||
value::table(list).into_untagged_value()
|
UntaggedValue::table(list).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nu_releases_sorted_by_date() -> Value {
|
fn nu_releases_sorted_by_date() -> Value {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::Signature;
|
use nu_protocol::{Signature, TaggedDictBuilder};
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
|
|
||||||
pub struct Shells;
|
pub struct Shells;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, Value};
|
use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct Size;
|
pub struct Size;
|
||||||
|
|
||||||
|
@ -79,10 +78,10 @@ fn count(contents: &str, tag: impl Into<Tag>) -> Value {
|
||||||
let mut dict = TaggedDictBuilder::new(tag);
|
let mut dict = TaggedDictBuilder::new(tag);
|
||||||
//TODO: add back in name when we have it in the tag
|
//TODO: add back in name when we have it in the tag
|
||||||
//dict.insert("name", value::string(name));
|
//dict.insert("name", value::string(name));
|
||||||
dict.insert_untagged("lines", value::int(lines));
|
dict.insert_untagged("lines", UntaggedValue::int(lines));
|
||||||
dict.insert_untagged("words", value::int(words));
|
dict.insert_untagged("words", UntaggedValue::int(words));
|
||||||
dict.insert_untagged("chars", value::int(chars));
|
dict.insert_untagged("chars", UntaggedValue::int(chars));
|
||||||
dict.insert_untagged("max length", value::int(bytes));
|
dict.insert_untagged("max length", UntaggedValue::int(bytes));
|
||||||
|
|
||||||
dict.into_value()
|
dict.into_value()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, SpannedTypeName, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{
|
||||||
|
ReturnSuccess, Signature, SpannedTypeName, SyntaxShape, TaggedDictBuilder, UntaggedValue, Value,
|
||||||
|
};
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
|
|
||||||
pub struct SplitBy;
|
pub struct SplitBy;
|
||||||
|
@ -104,7 +105,7 @@ pub fn split(
|
||||||
.or_insert(indexmap::IndexMap::new());
|
.or_insert(indexmap::IndexMap::new());
|
||||||
s.insert(
|
s.insert(
|
||||||
group_key.clone(),
|
group_key.clone(),
|
||||||
value::table(&subset).into_value(tag),
|
UntaggedValue::table(&subset).into_value(tag),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
|
@ -144,7 +145,7 @@ pub fn split(
|
||||||
let mut out = TaggedDictBuilder::new(&origin_tag);
|
let mut out = TaggedDictBuilder::new(&origin_tag);
|
||||||
|
|
||||||
for (k, v) in splits.into_iter() {
|
for (k, v) in splits.into_iter() {
|
||||||
out.insert_untagged(k, value::row(v));
|
out.insert_untagged(k, UntaggedValue::row(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(out.into_value())
|
Ok(out.into_value())
|
||||||
|
@ -154,21 +155,20 @@ mod tests {
|
||||||
|
|
||||||
use crate::commands::group_by::group;
|
use crate::commands::group_by::group;
|
||||||
use crate::commands::split_by::split;
|
use crate::commands::split_by::split;
|
||||||
use crate::data::value;
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_protocol::Value;
|
use nu_protocol::{UntaggedValue, Value};
|
||||||
use nu_source::*;
|
use nu_source::*;
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
value::string(input.into()).into_untagged_value()
|
UntaggedValue::string(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row(entries: IndexMap<String, Value>) -> Value {
|
fn row(entries: IndexMap<String, Value>) -> Value {
|
||||||
value::row(entries).into_untagged_value()
|
UntaggedValue::row(entries).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table(list: &Vec<Value>) -> Value {
|
fn table(list: &Vec<Value>) -> Value {
|
||||||
value::table(list).into_untagged_value()
|
UntaggedValue::table(list).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nu_releases_grouped_by_date() -> Value {
|
fn nu_releases_grouped_by_date() -> Value {
|
||||||
|
@ -214,7 +214,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
split(&for_key, &nu_releases_grouped_by_date(), Tag::unknown()).unwrap(),
|
split(&for_key, &nu_releases_grouped_by_date(), Tag::unknown()).unwrap(),
|
||||||
value::row(indexmap! {
|
UntaggedValue::row(indexmap! {
|
||||||
"EC".into() => row(indexmap! {
|
"EC".into() => row(indexmap! {
|
||||||
"August 23-2019".into() => table(&vec![
|
"August 23-2019".into() => table(&vec![
|
||||||
row(indexmap!{"name".into() => string("AR"), "country".into() => string("EC"), "date".into() => string("August 23-2019")})
|
row(indexmap!{"name".into() => string("AR"), "country".into() => string("EC"), "date".into() => string("August 23-2019")})
|
||||||
|
@ -261,7 +261,7 @@ mod tests {
|
||||||
row(indexmap!{"name".into() => string("AR"), "country".into() => string("EC"), "date".into() => string("August 23-2019")})
|
row(indexmap!{"name".into() => string("AR"), "country".into() => string("EC"), "date".into() => string("August 23-2019")})
|
||||||
]),
|
]),
|
||||||
"Sept 24-2019".into() => table(&vec![
|
"Sept 24-2019".into() => table(&vec![
|
||||||
row(indexmap!{"name".into() => value::string("JT").into_value(Tag::from(Span::new(5,10))), "date".into() => string("Sept 24-2019")})
|
row(indexmap!{"name".into() => UntaggedValue::string("JT").into_value(Tag::from(Span::new(5,10))), "date".into() => string("Sept 24-2019")})
|
||||||
]),
|
]),
|
||||||
"October 10-2019".into() => table(&vec![
|
"October 10-2019".into() => table(&vec![
|
||||||
row(indexmap!{"name".into() => string("YK"), "country".into() => string("US"), "date".into() => string("October 10-2019")})
|
row(indexmap!{"name".into() => string("YK"), "country".into() => string("US"), "date".into() => string("October 10-2019")})
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue};
|
use nu_protocol::{
|
||||||
|
Primitive, ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue,
|
||||||
|
};
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::base::property_get::get_data_by_key;
|
use crate::data::base::property_get::get_data_by_key;
|
||||||
use crate::data::{value, TaggedDictBuilder, TaggedListBuilder};
|
use crate::data::TaggedListBuilder;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use chrono::{DateTime, NaiveDate, Utc};
|
use chrono::{DateTime, NaiveDate, Utc};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{
|
||||||
|
Primitive, ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue, Value,
|
||||||
|
};
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
|
|
||||||
pub struct TSortBy;
|
pub struct TSortBy;
|
||||||
|
@ -70,7 +72,7 @@ fn t_sort_by(
|
||||||
|
|
||||||
if show_columns {
|
if show_columns {
|
||||||
for label in columns_sorted(column_grouped_by_name, &values[0], &name).into_iter() {
|
for label in columns_sorted(column_grouped_by_name, &values[0], &name).into_iter() {
|
||||||
yield ReturnSuccess::value(value::string(label.item).into_value(label.tag));
|
yield ReturnSuccess::value(UntaggedValue::string(label.item).into_value(label.tag));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match t_sort(column_grouped_by_name, None, &values[0], name) {
|
match t_sort(column_grouped_by_name, None, &values[0], name) {
|
||||||
|
@ -104,7 +106,7 @@ pub fn columns_sorted(
|
||||||
Ok(parsed) => UntaggedValue::Primitive(Primitive::Date(
|
Ok(parsed) => UntaggedValue::Primitive(Primitive::Date(
|
||||||
DateTime::<Utc>::from_utc(parsed.and_hms(12, 34, 56), Utc),
|
DateTime::<Utc>::from_utc(parsed.and_hms(12, 34, 56), Utc),
|
||||||
)),
|
)),
|
||||||
Err(_) => value::string(k),
|
Err(_) => UntaggedValue::string(k),
|
||||||
};
|
};
|
||||||
|
|
||||||
date.into_untagged_value()
|
date.into_untagged_value()
|
||||||
|
@ -197,10 +199,10 @@ pub fn t_sort(
|
||||||
|
|
||||||
return Ok(UntaggedValue::Table(outer.list).into_value(&origin_tag));
|
return Ok(UntaggedValue::Table(outer.list).into_value(&origin_tag));
|
||||||
}
|
}
|
||||||
Some(_) => return Ok(value::nothing().into_value(&origin_tag)),
|
Some(_) => return Ok(UntaggedValue::nothing().into_value(&origin_tag)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => return Ok(value::nothing().into_value(&origin_tag)),
|
None => return Ok(UntaggedValue::nothing().into_value(&origin_tag)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -214,15 +216,15 @@ mod tests {
|
||||||
use nu_source::*;
|
use nu_source::*;
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
value::string(input.into()).into_untagged_value()
|
UntaggedValue::string(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row(entries: IndexMap<String, Value>) -> Value {
|
fn row(entries: IndexMap<String, Value>) -> Value {
|
||||||
value::row(entries).into_untagged_value()
|
UntaggedValue::row(entries).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table(list: &Vec<Value>) -> Value {
|
fn table(list: &Vec<Value>) -> Value {
|
||||||
value::table(list).into_untagged_value()
|
UntaggedValue::table(list).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nu_releases_grouped_by_date() -> Value {
|
fn nu_releases_grouped_by_date() -> Value {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::format::TableView;
|
use crate::format::TableView;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
|
@ -58,7 +57,7 @@ fn table(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream,
|
||||||
}
|
}
|
||||||
// Needed for async_stream to type check
|
// Needed for async_stream to type check
|
||||||
if false {
|
if false {
|
||||||
yield ReturnSuccess::value(value::nothing().into_value(Tag::unknown()));
|
yield ReturnSuccess::value(UntaggedValue::nothing().into_value(Tag::unknown()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::Signature;
|
use nu_protocol::{Signature, TaggedDictBuilder, UntaggedValue};
|
||||||
|
|
||||||
pub struct Tags;
|
pub struct Tags;
|
||||||
|
|
||||||
|
@ -38,16 +37,16 @@ fn tags(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream,
|
||||||
let anchor = v.anchor();
|
let anchor = v.anchor();
|
||||||
let span = v.tag.span;
|
let span = v.tag.span;
|
||||||
let mut dict = TaggedDictBuilder::new(v.tag());
|
let mut dict = TaggedDictBuilder::new(v.tag());
|
||||||
dict.insert_untagged("start", value::int(span.start() as i64));
|
dict.insert_untagged("start", UntaggedValue::int(span.start() as i64));
|
||||||
dict.insert_untagged("end", value::int(span.end() as i64));
|
dict.insert_untagged("end", UntaggedValue::int(span.end() as i64));
|
||||||
tags.insert_value("span", dict.into_value());
|
tags.insert_value("span", dict.into_value());
|
||||||
|
|
||||||
match anchor {
|
match anchor {
|
||||||
Some(AnchorLocation::File(source)) => {
|
Some(AnchorLocation::File(source)) => {
|
||||||
tags.insert_untagged("anchor", value::string(source));
|
tags.insert_untagged("anchor", UntaggedValue::string(source));
|
||||||
}
|
}
|
||||||
Some(AnchorLocation::Url(source)) => {
|
Some(AnchorLocation::Url(source)) => {
|
||||||
tags.insert_untagged("anchor", value::string(source));
|
tags.insert_untagged("anchor", UntaggedValue::string(source));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use bson::{encode_document, oid::ObjectId, spec::BinarySubtype, Bson, Document};
|
use bson::{encode_document, oid::ObjectId, spec::BinarySubtype, Bson, Document};
|
||||||
use nu_errors::{CoerceInto, ShellError};
|
use nu_errors::{CoerceInto, ShellError};
|
||||||
|
@ -274,7 +273,7 @@ fn to_bson(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
|
||||||
|
|
||||||
match bson_value_to_bytes(bson_value, name_tag.clone()) {
|
match bson_value_to_bytes(bson_value, name_tag.clone()) {
|
||||||
Ok(x) => yield ReturnSuccess::value(
|
Ok(x) => yield ReturnSuccess::value(
|
||||||
value::binary(x).into_value(&name_tag),
|
UntaggedValue::binary(x).into_value(&name_tag),
|
||||||
),
|
),
|
||||||
_ => yield Err(ShellError::labeled_error_with_secondary(
|
_ => yield Err(ShellError::labeled_error_with_secondary(
|
||||||
"Expected a table with BSON-compatible structure.tag() from pipeline",
|
"Expected a table with BSON-compatible structure.tag() from pipeline",
|
||||||
|
|
|
@ -197,7 +197,7 @@ fn sqlite_input_stream_to_bytes(values: Vec<Value>) -> Result<Value, std::io::Er
|
||||||
}
|
}
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
tempfile.read_to_end(&mut out)?;
|
tempfile.read_to_end(&mut out)?;
|
||||||
Ok(value::binary(out).into_value(tag))
|
Ok(UntaggedValue::binary(out).into_value(tag))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
fn to_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value};
|
||||||
|
@ -59,7 +58,7 @@ fn to_url(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream,
|
||||||
|
|
||||||
match serde_urlencoded::to_string(row_vec) {
|
match serde_urlencoded::to_string(row_vec) {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
yield ReturnSuccess::value(value::string(s).into_value(&tag));
|
yield ReturnSuccess::value(UntaggedValue::string(s).into_value(&tag));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
yield Err(ShellError::labeled_error(
|
yield Err(ShellError::labeled_error(
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::commands::WholeStreamCommand;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature};
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
||||||
|
|
||||||
pub struct Trim;
|
pub struct Trim;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ fn trim(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream,
|
||||||
.values
|
.values
|
||||||
.map(move |v| {
|
.map(move |v| {
|
||||||
let string = String::extract(&v)?;
|
let string = String::extract(&v)?;
|
||||||
ReturnSuccess::value(value::string(string.trim()).into_value(v.tag()))
|
ReturnSuccess::value(UntaggedValue::string(string.trim()).into_value(v.tag()))
|
||||||
})
|
})
|
||||||
.to_output_stream())
|
.to_output_stream())
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
|
||||||
let mut indexmap = IndexMap::new();
|
let mut indexmap = IndexMap::new();
|
||||||
indexmap.insert(
|
indexmap.insert(
|
||||||
"version".to_string(),
|
"version".to_string(),
|
||||||
value::string(clap::crate_version!()).into_value(&tag),
|
UntaggedValue::string(clap::crate_version!()).into_value(&tag),
|
||||||
);
|
);
|
||||||
|
|
||||||
let value = UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag);
|
let value = UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
|
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use futures_util::pin_mut;
|
use futures_util::pin_mut;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, ReturnValue, Signature};
|
use nu_protocol::{ReturnSuccess, ReturnValue, Signature, UntaggedValue};
|
||||||
use nu_source::PrettyDebug;
|
use nu_source::PrettyDebug;
|
||||||
|
|
||||||
pub struct What;
|
pub struct What;
|
||||||
|
@ -45,7 +44,7 @@ pub fn what(
|
||||||
|
|
||||||
while let Some(row) = values.next().await {
|
while let Some(row) = values.next().await {
|
||||||
let name = value::format_leaf(&row).plain_string(100000);
|
let name = value::format_leaf(&row).plain_string(100000);
|
||||||
yield ReturnSuccess::value(value::string(name).into_value(Tag::unknown_anchor(row.tag.span)));
|
yield ReturnSuccess::value(UntaggedValue::string(name).into_value(Tag::unknown_anchor(row.tag.span)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,5 @@ pub(crate) mod types;
|
||||||
pub mod value;
|
pub mod value;
|
||||||
|
|
||||||
pub(crate) use command::command_dict;
|
pub(crate) use command::command_dict;
|
||||||
pub(crate) use dict::{TaggedDictBuilder, TaggedListBuilder};
|
pub(crate) use dict::TaggedListBuilder;
|
||||||
pub(crate) use files::dir_entry_dict;
|
pub(crate) use files::dir_entry_dict;
|
||||||
|
|
|
@ -3,7 +3,6 @@ pub(crate) mod shape;
|
||||||
|
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
use crate::data::base::property_get::ValueExt;
|
use crate::data::base::property_get::ValueExt;
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
|
||||||
use crate::evaluate::evaluate_baseline_expr;
|
use crate::evaluate::evaluate_baseline_expr;
|
||||||
use bigdecimal::BigDecimal;
|
use bigdecimal::BigDecimal;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
@ -12,7 +11,8 @@ use log::trace;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_parser::{hir, Operator};
|
use nu_parser::{hir, Operator};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Evaluate, EvaluateTrait, Primitive, Scope, ShellTypeName, SpannedTypeName, UntaggedValue, Value,
|
Evaluate, EvaluateTrait, Primitive, Scope, ShellTypeName, SpannedTypeName, TaggedDictBuilder,
|
||||||
|
UntaggedValue, Value,
|
||||||
};
|
};
|
||||||
use nu_source::{Tag, Text};
|
use nu_source::{Tag, Text};
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
@ -41,7 +41,7 @@ interfaces!(Block: dyn ObjectHash);
|
||||||
impl EvaluateTrait for Block {
|
impl EvaluateTrait for Block {
|
||||||
fn invoke(&self, scope: &Scope) -> Result<Value, ShellError> {
|
fn invoke(&self, scope: &Scope) -> Result<Value, ShellError> {
|
||||||
if self.expressions.len() == 0 {
|
if self.expressions.len() == 0 {
|
||||||
return Ok(value::nothing().into_value(&self.tag));
|
return Ok(UntaggedValue::nothing().into_value(&self.tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut last = None;
|
let mut last = None;
|
||||||
|
@ -99,7 +99,7 @@ pub(crate) fn select_fields(obj: &Value, fields: &[String], tag: impl Into<Tag>)
|
||||||
|
|
||||||
for field in fields {
|
for field in fields {
|
||||||
match descs.iter().find(|d| *d == field) {
|
match descs.iter().find(|d| *d == field) {
|
||||||
None => out.insert_untagged(field, value::nothing()),
|
None => out.insert_untagged(field, UntaggedValue::nothing()),
|
||||||
Some(desc) => out.insert_value(desc.clone(), obj.get_data(desc).borrow().clone()),
|
Some(desc) => out.insert_value(desc.clone(), obj.get_data(desc).borrow().clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,28 +196,27 @@ fn coerce_compare_primitive(
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::value;
|
|
||||||
use crate::data::base::property_get::{as_column_path, ValueExt};
|
use crate::data::base::property_get::{as_column_path, ValueExt};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ColumnPath as ColumnPathValue, PathMember, Value};
|
use nu_protocol::{ColumnPath as ColumnPathValue, PathMember, UntaggedValue, Value};
|
||||||
use nu_source::*;
|
use nu_source::*;
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
value::string(input.into()).into_untagged_value()
|
UntaggedValue::string(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn int(input: impl Into<BigInt>) -> Value {
|
fn int(input: impl Into<BigInt>) -> Value {
|
||||||
value::int(input.into()).into_untagged_value()
|
UntaggedValue::int(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row(entries: IndexMap<String, Value>) -> Value {
|
fn row(entries: IndexMap<String, Value>) -> Value {
|
||||||
value::row(entries).into_untagged_value()
|
UntaggedValue::row(entries).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table(list: &Vec<Value>) -> Value {
|
fn table(list: &Vec<Value>) -> Value {
|
||||||
value::table(list).into_untagged_value()
|
UntaggedValue::table(list).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_callback(
|
fn error_callback(
|
||||||
|
@ -232,7 +231,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn gets_matching_field_from_a_row() {
|
fn gets_matching_field_from_a_row() {
|
||||||
let row = value::row(indexmap! {
|
let row = UntaggedValue::row(indexmap! {
|
||||||
"amigos".into() => table(&vec![string("andres"),string("jonathan"),string("yehuda")])
|
"amigos".into() => table(&vec![string("andres"),string("jonathan"),string("yehuda")])
|
||||||
})
|
})
|
||||||
.into_untagged_value();
|
.into_untagged_value();
|
||||||
|
@ -253,7 +252,7 @@ mod tests {
|
||||||
|
|
||||||
let (version, tag) = string("0.4.0").into_parts();
|
let (version, tag) = string("0.4.0").into_parts();
|
||||||
|
|
||||||
let value = value::row(indexmap! {
|
let value = UntaggedValue::row(indexmap! {
|
||||||
"package".into() =>
|
"package".into() =>
|
||||||
row(indexmap! {
|
row(indexmap! {
|
||||||
"name".into() => string("nu"),
|
"name".into() => string("nu"),
|
||||||
|
@ -276,7 +275,7 @@ mod tests {
|
||||||
|
|
||||||
let (_, tag) = string("Andrés N. Robalino").into_parts();
|
let (_, tag) = string("Andrés N. Robalino").into_parts();
|
||||||
|
|
||||||
let value = value::row(indexmap! {
|
let value = UntaggedValue::row(indexmap! {
|
||||||
"package".into() => row(indexmap! {
|
"package".into() => row(indexmap! {
|
||||||
"name".into() => string("nu"),
|
"name".into() => string("nu"),
|
||||||
"version".into() => string("0.4.0"),
|
"version".into() => string("0.4.0"),
|
||||||
|
@ -310,7 +309,7 @@ mod tests {
|
||||||
|
|
||||||
let (_, tag) = string("Andrés N. Robalino").into_parts();
|
let (_, tag) = string("Andrés N. Robalino").into_parts();
|
||||||
|
|
||||||
let value = value::row(indexmap! {
|
let value = UntaggedValue::row(indexmap! {
|
||||||
"package".into() => row(indexmap! {
|
"package".into() => row(indexmap! {
|
||||||
"name".into() => string("nu"),
|
"name".into() => string("nu"),
|
||||||
"version".into() => string("0.4.0"),
|
"version".into() => string("0.4.0"),
|
||||||
|
@ -327,7 +326,7 @@ mod tests {
|
||||||
.into_value(tag)
|
.into_value(tag)
|
||||||
.get_data_by_column_path(&field_path, Box::new(error_callback("package.authors.0")))
|
.get_data_by_column_path(&field_path, Box::new(error_callback("package.authors.0")))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
value::row(indexmap! {
|
UntaggedValue::row(indexmap! {
|
||||||
"name".into() => string("Andrés N. Robalino")
|
"name".into() => string("Andrés N. Robalino")
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -339,7 +338,7 @@ mod tests {
|
||||||
|
|
||||||
let (_, tag) = string("Andrés N. Robalino").into_parts();
|
let (_, tag) = string("Andrés N. Robalino").into_parts();
|
||||||
|
|
||||||
let value = value::row(indexmap! {
|
let value = UntaggedValue::row(indexmap! {
|
||||||
"package".into() => row(indexmap! {
|
"package".into() => row(indexmap! {
|
||||||
"name".into() => string("nu"),
|
"name".into() => string("nu"),
|
||||||
"version".into() => string("0.4.0"),
|
"version".into() => string("0.4.0"),
|
||||||
|
@ -359,7 +358,7 @@ mod tests {
|
||||||
Box::new(error_callback("package.authors.\"0\""))
|
Box::new(error_callback("package.authors.\"0\""))
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
value::row(indexmap! {
|
UntaggedValue::row(indexmap! {
|
||||||
"name".into() => string("Andrés N. Robalino")
|
"name".into() => string("Andrés N. Robalino")
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -369,7 +368,7 @@ mod tests {
|
||||||
fn replaces_matching_field_from_a_row() {
|
fn replaces_matching_field_from_a_row() {
|
||||||
let field_path = column_path(&vec![string("amigos")]);
|
let field_path = column_path(&vec![string("amigos")]);
|
||||||
|
|
||||||
let sample = value::row(indexmap! {
|
let sample = UntaggedValue::row(indexmap! {
|
||||||
"amigos".into() => table(&vec![
|
"amigos".into() => table(&vec![
|
||||||
string("andres"),
|
string("andres"),
|
||||||
string("jonathan"),
|
string("jonathan"),
|
||||||
|
@ -395,7 +394,7 @@ mod tests {
|
||||||
string("los.3.caballeros"),
|
string("los.3.caballeros"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let sample = value::row(indexmap! {
|
let sample = UntaggedValue::row(indexmap! {
|
||||||
"package".into() => row(indexmap! {
|
"package".into() => row(indexmap! {
|
||||||
"authors".into() => row(indexmap! {
|
"authors".into() => row(indexmap! {
|
||||||
"los.3.mosqueteros".into() => table(&vec![string("andres::yehuda::jonathan")]),
|
"los.3.mosqueteros".into() => table(&vec![string("andres::yehuda::jonathan")]),
|
||||||
|
@ -415,7 +414,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual,
|
actual,
|
||||||
value::row(indexmap! {
|
UntaggedValue::row(indexmap! {
|
||||||
"package".into() => row(indexmap! {
|
"package".into() => row(indexmap! {
|
||||||
"authors".into() => row(indexmap! {
|
"authors".into() => row(indexmap! {
|
||||||
"los.3.mosqueteros".into() => table(&vec![string("andres::yehuda::jonathan")]),
|
"los.3.mosqueteros".into() => table(&vec![string("andres::yehuda::jonathan")]),
|
||||||
|
@ -432,7 +431,7 @@ mod tests {
|
||||||
string("nu.version.arepa"),
|
string("nu.version.arepa"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let sample = value::row(indexmap! {
|
let sample = UntaggedValue::row(indexmap! {
|
||||||
"shell_policy".into() => row(indexmap! {
|
"shell_policy".into() => row(indexmap! {
|
||||||
"releases".into() => table(&vec![
|
"releases".into() => table(&vec![
|
||||||
row(indexmap! {
|
row(indexmap! {
|
||||||
|
@ -467,7 +466,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual,
|
actual,
|
||||||
value::row(indexmap! {
|
UntaggedValue::row(indexmap! {
|
||||||
"shell_policy".into() => row(indexmap! {
|
"shell_policy".into() => row(indexmap! {
|
||||||
"releases".into() => table(&vec![
|
"releases".into() => table(&vec![
|
||||||
row(indexmap! {
|
row(indexmap! {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::data::value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::{ExpectedRange, ShellError};
|
use nu_errors::{ExpectedRange, ShellError};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
|
@ -436,7 +435,7 @@ pub fn get_data<'value>(value: &'value Value, desc: &String) -> MaybeOwned<'valu
|
||||||
UntaggedValue::Primitive(_) => MaybeOwned::Borrowed(value),
|
UntaggedValue::Primitive(_) => MaybeOwned::Borrowed(value),
|
||||||
UntaggedValue::Row(o) => o.get_data(desc),
|
UntaggedValue::Row(o) => o.get_data(desc),
|
||||||
UntaggedValue::Block(_) | UntaggedValue::Table(_) | UntaggedValue::Error(_) => {
|
UntaggedValue::Block(_) | UntaggedValue::Table(_) | UntaggedValue::Error(_) => {
|
||||||
MaybeOwned::Owned(value::nothing().into_untagged_value())
|
MaybeOwned::Owned(UntaggedValue::nothing().into_untagged_value())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,9 +467,9 @@ pub(crate) fn get_data_by_key(value: &Value, name: Spanned<&str>) -> Option<Valu
|
||||||
..
|
..
|
||||||
} => match o.get_data_by_key(name) {
|
} => match o.get_data_by_key(name) {
|
||||||
Some(v) => out.push(v),
|
Some(v) => out.push(v),
|
||||||
None => out.push(value::nothing().into_untagged_value()),
|
None => out.push(UntaggedValue::nothing().into_untagged_value()),
|
||||||
},
|
},
|
||||||
_ => out.push(value::nothing().into_untagged_value()),
|
_ => out.push(UntaggedValue::nothing().into_untagged_value()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ use derive_new::new;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ColumnPath, Dictionary, Evaluate, Primitive, ShellTypeName, UntaggedValue, Value,
|
ColumnPath, Dictionary, Evaluate, Primitive, ShellTypeName, TaggedDictBuilder, UntaggedValue,
|
||||||
|
Value,
|
||||||
};
|
};
|
||||||
use nu_source::{b, DebugDoc, PrettyDebug};
|
use nu_source::{b, DebugDoc, PrettyDebug};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
@ -535,7 +536,7 @@ impl Shape {
|
||||||
.expect("Writing into a Vec can't fail");
|
.expect("Writing into a Vec can't fail");
|
||||||
let string = String::from_utf8_lossy(&out);
|
let string = String::from_utf8_lossy(&out);
|
||||||
|
|
||||||
value::string(string).into_untagged_value()
|
UntaggedValue::string(string).into_untagged_value()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,20 +564,22 @@ impl Shapes {
|
||||||
if self.shapes.len() == 1 {
|
if self.shapes.len() == 1 {
|
||||||
let shape = self.shapes.keys().nth(0).unwrap();
|
let shape = self.shapes.keys().nth(0).unwrap();
|
||||||
|
|
||||||
vec![dict! {
|
let mut tagged_dict = TaggedDictBuilder::new(Tag::unknown());
|
||||||
"type" => shape.to_value(),
|
tagged_dict.insert_untagged("type", shape.to_value());
|
||||||
"rows" => value::string("all")
|
tagged_dict.insert_untagged("rows", UntaggedValue::string("all"));
|
||||||
}]
|
vec![tagged_dict.into_value()]
|
||||||
} else {
|
} else {
|
||||||
self.shapes
|
self.shapes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(shape, rows)| {
|
.map(|(shape, rows)| {
|
||||||
let rows = rows.iter().map(|i| i.to_string()).join(", ");
|
let rows = rows.iter().map(|i| i.to_string()).join(", ");
|
||||||
|
|
||||||
dict! {
|
let mut tagged_dict = TaggedDictBuilder::new(Tag::unknown());
|
||||||
"type" => shape.to_value(),
|
tagged_dict.insert_untagged("type", shape.to_value());
|
||||||
"rows" => value::string(format!("[ {} ]", rows))
|
tagged_dict
|
||||||
}
|
.insert_untagged("rows", UntaggedValue::string(format!("[ {} ]", rows)));
|
||||||
|
|
||||||
|
tagged_dict.into_value()
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::commands::command::Command;
|
use crate::commands::command::Command;
|
||||||
use crate::data::{TaggedDictBuilder, TaggedListBuilder};
|
use crate::data::TaggedListBuilder;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_protocol::{NamedType, PositionalType, Signature, Value};
|
use nu_protocol::{NamedType, PositionalType, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
pub(crate) fn command_dict(command: Arc<Command>, tag: impl Into<Tag>) -> Value {
|
pub(crate) fn command_dict(command: Arc<Command>, tag: impl Into<Tag>) -> Value {
|
||||||
|
@ -9,18 +9,18 @@ pub(crate) fn command_dict(command: Arc<Command>, tag: impl Into<Tag>) -> Value
|
||||||
|
|
||||||
let mut cmd_dict = TaggedDictBuilder::new(&tag);
|
let mut cmd_dict = TaggedDictBuilder::new(&tag);
|
||||||
|
|
||||||
cmd_dict.insert_untagged("name", value::string(command.name()));
|
cmd_dict.insert_untagged("name", UntaggedValue::string(command.name()));
|
||||||
|
|
||||||
cmd_dict.insert_untagged(
|
cmd_dict.insert_untagged(
|
||||||
"type",
|
"type",
|
||||||
value::string(match command.deref() {
|
UntaggedValue::string(match command.deref() {
|
||||||
Command::WholeStream(_) => "Command",
|
Command::WholeStream(_) => "Command",
|
||||||
Command::PerItem(_) => "Filter",
|
Command::PerItem(_) => "Filter",
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
cmd_dict.insert_value("signature", signature_dict(command.signature(), tag));
|
cmd_dict.insert_value("signature", signature_dict(command.signature(), tag));
|
||||||
cmd_dict.insert_untagged("usage", value::string(command.usage()));
|
cmd_dict.insert_untagged("usage", UntaggedValue::string(command.usage()));
|
||||||
|
|
||||||
cmd_dict.into_value()
|
cmd_dict.into_value()
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,11 @@ fn for_spec(name: &str, ty: &str, required: bool, tag: impl Into<Tag>) -> Value
|
||||||
|
|
||||||
let mut spec = TaggedDictBuilder::new(tag);
|
let mut spec = TaggedDictBuilder::new(tag);
|
||||||
|
|
||||||
spec.insert_untagged("name", value::string(name));
|
spec.insert_untagged("name", UntaggedValue::string(name));
|
||||||
spec.insert_untagged("type", value::string(ty));
|
spec.insert_untagged("type", UntaggedValue::string(ty));
|
||||||
spec.insert_untagged(
|
spec.insert_untagged(
|
||||||
"required",
|
"required",
|
||||||
value::string(if required { "yes" } else { "no" }),
|
UntaggedValue::string(if required { "yes" } else { "no" }),
|
||||||
);
|
);
|
||||||
|
|
||||||
spec.into_value()
|
spec.into_value()
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use indexmap::IndexMap;
|
|
||||||
use nu_protocol::{Dictionary, Primitive, UntaggedValue, Value};
|
use nu_protocol::{Dictionary, Primitive, UntaggedValue, Value};
|
||||||
use nu_source::{b, PrettyDebug, Spanned};
|
use nu_source::{b, PrettyDebug, Spanned};
|
||||||
|
|
||||||
|
@ -106,59 +105,3 @@ impl From<TaggedListBuilder> for Value {
|
||||||
input.into_value()
|
input.into_value()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct TaggedDictBuilder {
|
|
||||||
tag: Tag,
|
|
||||||
dict: IndexMap<String, Value>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TaggedDictBuilder {
|
|
||||||
pub fn new(tag: impl Into<Tag>) -> TaggedDictBuilder {
|
|
||||||
TaggedDictBuilder {
|
|
||||||
tag: tag.into(),
|
|
||||||
dict: IndexMap::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build(tag: impl Into<Tag>, block: impl FnOnce(&mut TaggedDictBuilder)) -> Value {
|
|
||||||
let mut builder = TaggedDictBuilder::new(tag);
|
|
||||||
block(&mut builder);
|
|
||||||
builder.into_value()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_capacity(tag: impl Into<Tag>, n: usize) -> TaggedDictBuilder {
|
|
||||||
TaggedDictBuilder {
|
|
||||||
tag: tag.into(),
|
|
||||||
dict: IndexMap::with_capacity(n),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert_untagged(&mut self, key: impl Into<String>, value: impl Into<UntaggedValue>) {
|
|
||||||
self.dict
|
|
||||||
.insert(key.into(), value.into().into_value(&self.tag));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert_value(&mut self, key: impl Into<String>, value: impl Into<Value>) {
|
|
||||||
self.dict.insert(key.into(), value.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn into_value(self) -> Value {
|
|
||||||
let tag = self.tag.clone();
|
|
||||||
self.into_untagged_value().into_value(tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn into_untagged_value(self) -> UntaggedValue {
|
|
||||||
UntaggedValue::Row(Dictionary { entries: self.dict })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
|
||||||
self.dict.is_empty()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TaggedDictBuilder> for Value {
|
|
||||||
fn from(input: TaggedDictBuilder) -> Value {
|
|
||||||
input.into_value()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::data::TaggedDictBuilder;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::Value;
|
use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FileType {
|
pub enum FileType {
|
||||||
|
@ -17,7 +16,7 @@ pub(crate) fn dir_entry_dict(
|
||||||
full: bool,
|
full: bool,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
let mut dict = TaggedDictBuilder::new(tag);
|
let mut dict = TaggedDictBuilder::new(tag);
|
||||||
dict.insert_untagged("name", value::string(filename.to_string_lossy()));
|
dict.insert_untagged("name", UntaggedValue::string(filename.to_string_lossy()));
|
||||||
|
|
||||||
let kind = if metadata.is_dir() {
|
let kind = if metadata.is_dir() {
|
||||||
FileType::Directory
|
FileType::Directory
|
||||||
|
@ -27,36 +26,39 @@ pub(crate) fn dir_entry_dict(
|
||||||
FileType::Symlink
|
FileType::Symlink
|
||||||
};
|
};
|
||||||
|
|
||||||
dict.insert_untagged("type", value::string(format!("{:?}", kind)));
|
dict.insert_untagged("type", UntaggedValue::string(format!("{:?}", kind)));
|
||||||
|
|
||||||
if full {
|
if full {
|
||||||
dict.insert_untagged(
|
dict.insert_untagged(
|
||||||
"readonly",
|
"readonly",
|
||||||
value::boolean(metadata.permissions().readonly()),
|
UntaggedValue::boolean(metadata.permissions().readonly()),
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
let mode = metadata.permissions().mode();
|
let mode = metadata.permissions().mode();
|
||||||
dict.insert_untagged("mode", value::string(umask::Mode::from(mode).to_string()));
|
dict.insert_untagged(
|
||||||
|
"mode",
|
||||||
|
UntaggedValue::string(umask::Mode::from(mode).to_string()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dict.insert_untagged("size", value::bytes(metadata.len() as u64));
|
dict.insert_untagged("size", UntaggedValue::bytes(metadata.len() as u64));
|
||||||
|
|
||||||
match metadata.created() {
|
match metadata.created() {
|
||||||
Ok(c) => dict.insert_untagged("created", value::system_date(c)),
|
Ok(c) => dict.insert_untagged("created", UntaggedValue::system_date(c)),
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
match metadata.accessed() {
|
match metadata.accessed() {
|
||||||
Ok(a) => dict.insert_untagged("accessed", value::system_date(a)),
|
Ok(a) => dict.insert_untagged("accessed", UntaggedValue::system_date(a)),
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
match metadata.modified() {
|
match metadata.modified() {
|
||||||
Ok(m) => dict.insert_untagged("modified", value::system_date(m)),
|
Ok(m) => dict.insert_untagged("modified", UntaggedValue::system_date(m)),
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,86 +1,11 @@
|
||||||
use crate::data::base::coerce_compare;
|
use crate::data::base::coerce_compare;
|
||||||
use crate::data::base::shape::{Column, InlineShape, TypeShape};
|
use crate::data::base::shape::{Column, InlineShape, TypeShape};
|
||||||
use crate::data::primitive::style_primitive;
|
use crate::data::primitive::style_primitive;
|
||||||
use crate::data::value;
|
|
||||||
use bigdecimal::BigDecimal;
|
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use indexmap::IndexMap;
|
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_parser::Number;
|
|
||||||
use nu_parser::Operator;
|
use nu_parser::Operator;
|
||||||
use nu_protocol::{ColumnPath, PathMember, Primitive, UntaggedValue, Value};
|
use nu_protocol::{Primitive, UntaggedValue};
|
||||||
use nu_source::{DebugDocBuilder, PrettyDebug, Tagged};
|
use nu_source::{DebugDocBuilder, PrettyDebug, Tagged};
|
||||||
use num_bigint::BigInt;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::time::SystemTime;
|
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
pub fn row(entries: IndexMap<String, Value>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Row(entries.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn table(list: &Vec<Value>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Table(list.to_vec())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn string(s: impl Into<String>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::String(s.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn line(s: impl Into<String>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Line(s.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn column_path(s: Vec<impl Into<PathMember>>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::new(
|
|
||||||
s.into_iter().map(|p| p.into()).collect(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn int(i: impl Into<BigInt>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Int(i.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pattern(s: impl Into<String>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::String(s.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn path(s: impl Into<PathBuf>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Path(s.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bytes(s: impl Into<u64>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Bytes(s.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn decimal(s: impl Into<BigDecimal>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Decimal(s.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn binary(binary: Vec<u8>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Binary(binary))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn number(s: impl Into<Number>) -> UntaggedValue {
|
|
||||||
let num = s.into();
|
|
||||||
|
|
||||||
match num {
|
|
||||||
Number::Int(int) => value::int(int),
|
|
||||||
Number::Decimal(decimal) => value::decimal(decimal),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn boolean(s: impl Into<bool>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Boolean(s.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn duration(secs: u64) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Duration(secs))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn system_date(s: SystemTime) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Date(s.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn date_from_str(s: Tagged<&str>) -> Result<UntaggedValue, ShellError> {
|
pub fn date_from_str(s: Tagged<&str>) -> Result<UntaggedValue, ShellError> {
|
||||||
let date = DateTime::parse_from_rfc3339(s.item).map_err(|err| {
|
let date = DateTime::parse_from_rfc3339(s.item).map_err(|err| {
|
||||||
|
@ -96,10 +21,6 @@ pub fn date_from_str(s: Tagged<&str>) -> Result<UntaggedValue, ShellError> {
|
||||||
Ok(UntaggedValue::Primitive(Primitive::Date(date)))
|
Ok(UntaggedValue::Primitive(Primitive::Date(date)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nothing() -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Nothing)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compare_values(
|
pub fn compare_values(
|
||||||
operator: &Operator,
|
operator: &Operator,
|
||||||
left: &UntaggedValue,
|
left: &UntaggedValue,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::data::base::property_get::ValueExt;
|
use crate::data::base::property_get::ValueExt;
|
||||||
use crate::data::value;
|
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use nu_errors::{CoerceInto, ShellError};
|
use nu_errors::{CoerceInto, ShellError};
|
||||||
use nu_protocol::{CallInfo, ColumnPath, Evaluate, Primitive, ShellTypeName, UntaggedValue, Value};
|
use nu_protocol::{CallInfo, ColumnPath, Evaluate, Primitive, ShellTypeName, UntaggedValue, Value};
|
||||||
|
@ -56,7 +55,7 @@ impl<'de> ConfigDeserializer<'de> {
|
||||||
|
|
||||||
self.stack.push(DeserializerItem {
|
self.stack.push(DeserializerItem {
|
||||||
key_struct_field: Some((name.to_string(), name)),
|
key_struct_field: Some((name.to_string(), name)),
|
||||||
val: value.unwrap_or_else(|| value::nothing().into_value(&self.call.name_tag)),
|
val: value.unwrap_or_else(|| UntaggedValue::nothing().into_value(&self.call.name_tag)),
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
// TODO: Temporary redirect
|
// TODO: Temporary redirect
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
use crate::data::value;
|
|
||||||
use crate::evaluate::evaluate_baseline_expr;
|
use crate::evaluate::evaluate_baseline_expr;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_parser::hir;
|
use nu_parser::hir;
|
||||||
use nu_protocol::{EvaluatedArgs, Scope, Value};
|
use nu_protocol::{EvaluatedArgs, Scope, UntaggedValue, Value};
|
||||||
use nu_source::Text;
|
use nu_source::Text;
|
||||||
|
|
||||||
pub(crate) fn evaluate_args(
|
pub(crate) fn evaluate_args(
|
||||||
|
@ -35,7 +34,7 @@ pub(crate) fn evaluate_args(
|
||||||
for (name, value) in n.named.iter() {
|
for (name, value) in n.named.iter() {
|
||||||
match value {
|
match value {
|
||||||
hir::NamedValue::PresentSwitch(tag) => {
|
hir::NamedValue::PresentSwitch(tag) => {
|
||||||
results.insert(name.clone(), value::boolean(true).into_value(tag));
|
results.insert(name.clone(), UntaggedValue::boolean(true).into_value(tag));
|
||||||
}
|
}
|
||||||
hir::NamedValue::Value(expr) => {
|
hir::NamedValue::Value(expr) => {
|
||||||
results.insert(
|
results.insert(
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
use crate::data::base::Block;
|
use crate::data::base::Block;
|
||||||
use crate::data::value;
|
|
||||||
use crate::evaluate::operator::apply_operator;
|
use crate::evaluate::operator::apply_operator;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::TaggedDictBuilder;
|
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use nu_errors::{ArgumentError, ShellError};
|
use nu_errors::{ArgumentError, ShellError};
|
||||||
use nu_parser::hir::{self, Expression, RawExpression};
|
use nu_parser::hir::{self, Expression, RawExpression};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ColumnPath, Evaluate, Primitive, Scope, UnspannedPathMember, UntaggedValue, Value,
|
ColumnPath, Evaluate, Primitive, Scope, TaggedDictBuilder, UnspannedPathMember, UntaggedValue,
|
||||||
|
Value,
|
||||||
};
|
};
|
||||||
use nu_source::Text;
|
use nu_source::Text;
|
||||||
|
|
||||||
|
@ -28,9 +27,9 @@ pub(crate) fn evaluate_baseline_expr(
|
||||||
"Invalid external word".spanned(tag.span),
|
"Invalid external word".spanned(tag.span),
|
||||||
ArgumentError::InvalidExternalWord,
|
ArgumentError::InvalidExternalWord,
|
||||||
)),
|
)),
|
||||||
RawExpression::FilePath(path) => Ok(value::path(path.clone()).into_value(tag)),
|
RawExpression::FilePath(path) => Ok(UntaggedValue::path(path.clone()).into_value(tag)),
|
||||||
RawExpression::Synthetic(hir::Synthetic::String(s)) => {
|
RawExpression::Synthetic(hir::Synthetic::String(s)) => {
|
||||||
Ok(value::string(s).into_untagged_value())
|
Ok(UntaggedValue::string(s).into_untagged_value())
|
||||||
}
|
}
|
||||||
RawExpression::Variable(var) => evaluate_reference(var, scope, source, tag),
|
RawExpression::Variable(var) => evaluate_reference(var, scope, source, tag),
|
||||||
RawExpression::Command(_) => evaluate_command(tag, scope, source),
|
RawExpression::Command(_) => evaluate_command(tag, scope, source),
|
||||||
|
@ -118,11 +117,22 @@ fn evaluate_literal(literal: &hir::Literal, source: &Text) -> Value {
|
||||||
UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::new(members)))
|
UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::new(members)))
|
||||||
.into_value(&literal.span)
|
.into_value(&literal.span)
|
||||||
}
|
}
|
||||||
hir::RawLiteral::Number(int) => value::number(int.clone()).into_value(literal.span),
|
hir::RawLiteral::Number(int) => match int {
|
||||||
|
nu_parser::Number::Int(i) => UntaggedValue::int(i.clone()).into_value(literal.span),
|
||||||
|
nu_parser::Number::Decimal(d) => {
|
||||||
|
UntaggedValue::decimal(d.clone()).into_value(literal.span)
|
||||||
|
}
|
||||||
|
},
|
||||||
hir::RawLiteral::Size(int, unit) => unit.compute(&int).into_value(literal.span),
|
hir::RawLiteral::Size(int, unit) => unit.compute(&int).into_value(literal.span),
|
||||||
hir::RawLiteral::String(tag) => value::string(tag.slice(source)).into_value(literal.span),
|
hir::RawLiteral::String(tag) => {
|
||||||
hir::RawLiteral::GlobPattern(pattern) => value::pattern(pattern).into_value(literal.span),
|
UntaggedValue::string(tag.slice(source)).into_value(literal.span)
|
||||||
hir::RawLiteral::Bare => value::string(literal.span.slice(source)).into_value(literal.span),
|
}
|
||||||
|
hir::RawLiteral::GlobPattern(pattern) => {
|
||||||
|
UntaggedValue::pattern(pattern).into_value(literal.span)
|
||||||
|
}
|
||||||
|
hir::RawLiteral::Bare => {
|
||||||
|
UntaggedValue::string(literal.span.slice(source)).into_value(literal.span)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,32 +150,32 @@ fn evaluate_reference(
|
||||||
let mut dict = TaggedDictBuilder::new(&tag);
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
for v in std::env::vars() {
|
for v in std::env::vars() {
|
||||||
if v.0 != "PATH" && v.0 != "Path" {
|
if v.0 != "PATH" && v.0 != "Path" {
|
||||||
dict.insert_untagged(v.0, value::string(v.1));
|
dict.insert_untagged(v.0, UntaggedValue::string(v.1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(dict.into_value())
|
Ok(dict.into_value())
|
||||||
}
|
}
|
||||||
x if x == "nu:config" => {
|
x if x == "nu:config" => {
|
||||||
let config = crate::data::config::read(tag.clone(), &None)?;
|
let config = crate::data::config::read(tag.clone(), &None)?;
|
||||||
Ok(value::row(config).into_value(tag))
|
Ok(UntaggedValue::row(config).into_value(tag))
|
||||||
}
|
}
|
||||||
x if x == "nu:path" => {
|
x if x == "nu:path" => {
|
||||||
let mut table = vec![];
|
let mut table = vec![];
|
||||||
match std::env::var_os("PATH") {
|
match std::env::var_os("PATH") {
|
||||||
Some(paths) => {
|
Some(paths) => {
|
||||||
for path in std::env::split_paths(&paths) {
|
for path in std::env::split_paths(&paths) {
|
||||||
table.push(value::path(path).into_value(&tag));
|
table.push(UntaggedValue::path(path).into_value(&tag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
Ok(value::table(&table).into_value(tag))
|
Ok(UntaggedValue::table(&table).into_value(tag))
|
||||||
}
|
}
|
||||||
x => Ok(scope
|
x => Ok(scope
|
||||||
.vars
|
.vars
|
||||||
.get(x)
|
.get(x)
|
||||||
.map(|v| v.clone())
|
.map(|v| v.clone())
|
||||||
.unwrap_or_else(|| value::nothing().into_value(tag))),
|
.unwrap_or_else(|| UntaggedValue::nothing().into_value(tag))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,11 @@ pub fn apply_operator(
|
||||||
| Operator::GreaterThan
|
| Operator::GreaterThan
|
||||||
| Operator::LessThanOrEqual
|
| Operator::LessThanOrEqual
|
||||||
| Operator::GreaterThanOrEqual => {
|
| Operator::GreaterThanOrEqual => {
|
||||||
value::compare_values(op, left, right).map(value::boolean)
|
value::compare_values(op, left, right).map(UntaggedValue::boolean)
|
||||||
}
|
}
|
||||||
Operator::Dot => Ok(value::boolean(false)),
|
Operator::Dot => Ok(UntaggedValue::boolean(false)),
|
||||||
Operator::Contains => contains(left, right).map(value::boolean),
|
Operator::Contains => contains(left, right).map(UntaggedValue::boolean),
|
||||||
Operator::NotContains => contains(left, right).map(Not::not).map(value::boolean),
|
Operator::NotContains => contains(left, right).map(Not::not).map(UntaggedValue::boolean),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl RenderView for GenericView<'_> {
|
||||||
|
|
||||||
b @ UntaggedValue::Block(_) => {
|
b @ UntaggedValue::Block(_) => {
|
||||||
let printed = format_leaf(b).plain_string(host.width());
|
let printed = format_leaf(b).plain_string(host.width());
|
||||||
let view = EntriesView::from_value(&value::string(printed).into_value(tag));
|
let view = EntriesView::from_value(&UntaggedValue::string(printed).into_value(tag));
|
||||||
view.render_view(host)?;
|
view.render_view(host)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,8 @@ impl TableView {
|
||||||
value: UntaggedValue::Row(..),
|
value: UntaggedValue::Row(..),
|
||||||
..
|
..
|
||||||
} => (
|
} => (
|
||||||
format_leaf(&value::nothing()).plain_string(100000),
|
format_leaf(&UntaggedValue::nothing()).plain_string(100000),
|
||||||
style_leaf(&value::nothing()),
|
style_leaf(&UntaggedValue::nothing()),
|
||||||
),
|
),
|
||||||
_ => (format_leaf(value).plain_string(100000), style_leaf(value)),
|
_ => (format_leaf(value).plain_string(100000), style_leaf(value)),
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,8 @@ impl TableView {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => (
|
_ => (
|
||||||
format_leaf(&value::nothing()).plain_string(100000),
|
format_leaf(&UntaggedValue::nothing()).plain_string(100000),
|
||||||
style_leaf(&value::nothing()),
|
style_leaf(&UntaggedValue::nothing()),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ mod utils;
|
||||||
pub use crate::cli::cli;
|
pub use crate::cli::cli;
|
||||||
pub use crate::data::base::property_get::ValueExt;
|
pub use crate::data::base::property_get::ValueExt;
|
||||||
pub use crate::data::config::{config_path, APP_INFO};
|
pub use crate::data::config::{config_path, APP_INFO};
|
||||||
pub use crate::data::dict::{TaggedDictBuilder, TaggedListBuilder};
|
pub use crate::data::dict::TaggedListBuilder;
|
||||||
pub use crate::data::primitive;
|
pub use crate::data::primitive;
|
||||||
pub use crate::data::value;
|
pub use crate::data::value;
|
||||||
pub use crate::env::host::BasicHost;
|
pub use crate::env::host::BasicHost;
|
||||||
|
@ -32,4 +32,4 @@ pub use nu_parser::TokenTreeBuilder;
|
||||||
pub use num_traits::cast::ToPrimitive;
|
pub use num_traits::cast::ToPrimitive;
|
||||||
|
|
||||||
// TODO: Temporary redirect
|
// TODO: Temporary redirect
|
||||||
pub use nu_protocol::{serve_plugin, Plugin};
|
pub use nu_protocol::{serve_plugin, Plugin, TaggedDictBuilder};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use nu::{serve_plugin, value, Plugin};
|
use nu::{serve_plugin, Plugin};
|
||||||
use nu_errors::{CoerceInto, ShellError};
|
use nu_errors::{CoerceInto, ShellError};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, UntaggedValue, Value,
|
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, UntaggedValue, Value,
|
||||||
|
@ -27,7 +27,7 @@ impl Average {
|
||||||
value: UntaggedValue::Primitive(Primitive::Int(j)),
|
value: UntaggedValue::Primitive(Primitive::Int(j)),
|
||||||
tag,
|
tag,
|
||||||
}) => {
|
}) => {
|
||||||
self.total = Some(value::int(i + j).into_value(tag));
|
self.total = Some(UntaggedValue::int(i + j).into_value(tag));
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ impl Average {
|
||||||
value: UntaggedValue::Primitive(Primitive::Bytes(j)),
|
value: UntaggedValue::Primitive(Primitive::Bytes(j)),
|
||||||
tag,
|
tag,
|
||||||
}) => {
|
}) => {
|
||||||
self.total = Some(value::bytes(b + j).into_value(tag));
|
self.total = Some(UntaggedValue::bytes(b + j).into_value(tag));
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate indexmap;
|
extern crate indexmap;
|
||||||
|
|
||||||
use nu::{serve_plugin, value, Plugin};
|
use nu::{serve_plugin, Plugin};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, SpannedTypeName, SyntaxShape,
|
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, SpannedTypeName, SyntaxShape,
|
||||||
|
@ -35,7 +35,7 @@ impl Embed {
|
||||||
self.are_all_rows = false;
|
self.are_all_rows = false;
|
||||||
|
|
||||||
self.values.push(
|
self.values.push(
|
||||||
value::row(indexmap! {
|
UntaggedValue::row(indexmap! {
|
||||||
match &self.field {
|
match &self.field {
|
||||||
Some(key) => key.clone(),
|
Some(key) => key.clone(),
|
||||||
None => "Column".into()
|
None => "Column".into()
|
||||||
|
@ -81,11 +81,11 @@ impl Plugin for Embed {
|
||||||
|
|
||||||
fn end_filter(&mut self) -> Result<Vec<ReturnValue>, ShellError> {
|
fn end_filter(&mut self) -> Result<Vec<ReturnValue>, ShellError> {
|
||||||
if self.are_all_rows {
|
if self.are_all_rows {
|
||||||
let row = value::row(indexmap! {
|
let row = UntaggedValue::row(indexmap! {
|
||||||
match &self.field {
|
match &self.field {
|
||||||
Some(key) => key.clone(),
|
Some(key) => key.clone(),
|
||||||
None => "Column".into(),
|
None => "Column".into(),
|
||||||
} => value::table(&self.values).into_value(Tag::unknown()),
|
} => UntaggedValue::table(&self.values).into_value(Tag::unknown()),
|
||||||
})
|
})
|
||||||
.into_untagged_value();
|
.into_untagged_value();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use nu::{serve_plugin, value, Plugin};
|
use nu::{serve_plugin, Plugin};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, SyntaxShape, UntaggedValue, Value,
|
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, SyntaxShape, UntaggedValue, Value,
|
||||||
|
@ -115,7 +115,7 @@ impl Plugin for Format {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(vec![ReturnSuccess::value(
|
return Ok(vec![ReturnSuccess::value(
|
||||||
value::string(output).into_untagged_value(),
|
UntaggedValue::string(output).into_untagged_value(),
|
||||||
)]);
|
)]);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use nu::{did_you_mean, serve_plugin, value, Plugin, ValueExt};
|
use nu::{did_you_mean, serve_plugin, Plugin, ValueExt};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
CallInfo, ColumnPath, Primitive, ReturnSuccess, ReturnValue, ShellTypeName, Signature,
|
CallInfo, ColumnPath, Primitive, ReturnSuccess, ReturnValue, ShellTypeName, Signature,
|
||||||
|
@ -37,7 +37,7 @@ impl Inc {
|
||||||
Some(Action::SemVerAction(act_on)) => {
|
Some(Action::SemVerAction(act_on)) => {
|
||||||
let mut ver = match semver::Version::parse(&input) {
|
let mut ver = match semver::Version::parse(&input) {
|
||||||
Ok(parsed_ver) => parsed_ver,
|
Ok(parsed_ver) => parsed_ver,
|
||||||
Err(_) => return Ok(value::string(input.to_string())),
|
Err(_) => return Ok(UntaggedValue::string(input.to_string())),
|
||||||
};
|
};
|
||||||
|
|
||||||
match act_on {
|
match act_on {
|
||||||
|
@ -46,11 +46,11 @@ impl Inc {
|
||||||
SemVerAction::Patch => ver.increment_patch(),
|
SemVerAction::Patch => ver.increment_patch(),
|
||||||
}
|
}
|
||||||
|
|
||||||
value::string(ver.to_string())
|
UntaggedValue::string(ver.to_string())
|
||||||
}
|
}
|
||||||
Some(Action::Default) | None => match input.parse::<u64>() {
|
Some(Action::Default) | None => match input.parse::<u64>() {
|
||||||
Ok(v) => value::string(format!("{}", v + 1)),
|
Ok(v) => UntaggedValue::string(format!("{}", v + 1)),
|
||||||
Err(_) => value::string(input),
|
Err(_) => UntaggedValue::string(input),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -80,10 +80,10 @@ impl Inc {
|
||||||
fn inc(&self, value: Value) -> Result<Value, ShellError> {
|
fn inc(&self, value: Value) -> Result<Value, ShellError> {
|
||||||
match &value.value {
|
match &value.value {
|
||||||
UntaggedValue::Primitive(Primitive::Int(i)) => {
|
UntaggedValue::Primitive(Primitive::Int(i)) => {
|
||||||
Ok(value::int(i + 1).into_value(value.tag()))
|
Ok(UntaggedValue::int(i + 1).into_value(value.tag()))
|
||||||
}
|
}
|
||||||
UntaggedValue::Primitive(Primitive::Bytes(b)) => {
|
UntaggedValue::Primitive(Primitive::Bytes(b)) => {
|
||||||
Ok(value::bytes(b + 1 as u64).into_value(value.tag()))
|
Ok(UntaggedValue::bytes(b + 1 as u64).into_value(value.tag()))
|
||||||
}
|
}
|
||||||
UntaggedValue::Primitive(Primitive::String(ref s)) => {
|
UntaggedValue::Primitive(Primitive::String(ref s)) => {
|
||||||
Ok(self.apply(&s)?.into_value(value.tag()))
|
Ok(self.apply(&s)?.into_value(value.tag()))
|
||||||
|
@ -226,7 +226,7 @@ mod tests {
|
||||||
|
|
||||||
use super::{Inc, SemVerAction};
|
use super::{Inc, SemVerAction};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu::{value, Plugin, TaggedDictBuilder};
|
use nu::{Plugin, TaggedDictBuilder};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
CallInfo, EvaluatedArgs, PathMember, ReturnSuccess, UnspannedPathMember, UntaggedValue,
|
CallInfo, EvaluatedArgs, PathMember, ReturnSuccess, UnspannedPathMember, UntaggedValue,
|
||||||
Value,
|
Value,
|
||||||
|
@ -249,7 +249,7 @@ mod tests {
|
||||||
fn with_long_flag(&mut self, name: &str) -> &mut Self {
|
fn with_long_flag(&mut self, name: &str) -> &mut Self {
|
||||||
self.flags.insert(
|
self.flags.insert(
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
value::boolean(true).into_value(Tag::unknown()),
|
UntaggedValue::boolean(true).into_value(Tag::unknown()),
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ mod tests {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
self.positionals
|
self.positionals
|
||||||
.push(value::column_path(fields).into_untagged_value());
|
.push(UntaggedValue::column_path(fields).into_untagged_value());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ mod tests {
|
||||||
|
|
||||||
fn cargo_sample_record(with_version: &str) -> Value {
|
fn cargo_sample_record(with_version: &str) -> Value {
|
||||||
let mut package = TaggedDictBuilder::new(Tag::unknown());
|
let mut package = TaggedDictBuilder::new(Tag::unknown());
|
||||||
package.insert_untagged("version", value::string(with_version));
|
package.insert_untagged("version", UntaggedValue::string(with_version));
|
||||||
package.into_value()
|
package.into_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,21 +360,21 @@ mod tests {
|
||||||
fn incs_major() {
|
fn incs_major() {
|
||||||
let mut inc = Inc::new();
|
let mut inc = Inc::new();
|
||||||
inc.for_semver(SemVerAction::Major);
|
inc.for_semver(SemVerAction::Major);
|
||||||
assert_eq!(inc.apply("0.1.3").unwrap(), value::string("1.0.0"));
|
assert_eq!(inc.apply("0.1.3").unwrap(), UntaggedValue::string("1.0.0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn incs_minor() {
|
fn incs_minor() {
|
||||||
let mut inc = Inc::new();
|
let mut inc = Inc::new();
|
||||||
inc.for_semver(SemVerAction::Minor);
|
inc.for_semver(SemVerAction::Minor);
|
||||||
assert_eq!(inc.apply("0.1.3").unwrap(), value::string("0.2.0"));
|
assert_eq!(inc.apply("0.1.3").unwrap(), UntaggedValue::string("0.2.0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn incs_patch() {
|
fn incs_patch() {
|
||||||
let mut inc = Inc::new();
|
let mut inc = Inc::new();
|
||||||
inc.for_semver(SemVerAction::Patch);
|
inc.for_semver(SemVerAction::Patch);
|
||||||
assert_eq!(inc.apply("0.1.3").unwrap(), value::string("0.1.4"));
|
assert_eq!(inc.apply("0.1.3").unwrap(), UntaggedValue::string("0.1.4"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -399,7 +399,7 @@ mod tests {
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("version")).borrow(),
|
*o.get_data(&String::from("version")).borrow(),
|
||||||
value::string(String::from("1.0.0")).into_untagged_value()
|
UntaggedValue::string(String::from("1.0.0")).into_untagged_value()
|
||||||
),
|
),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -427,7 +427,7 @@ mod tests {
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("version")).borrow(),
|
*o.get_data(&String::from("version")).borrow(),
|
||||||
value::string(String::from("0.2.0")).into_untagged_value()
|
UntaggedValue::string(String::from("0.2.0")).into_untagged_value()
|
||||||
),
|
),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -456,7 +456,7 @@ mod tests {
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&field).borrow(),
|
*o.get_data(&field).borrow(),
|
||||||
value::string(String::from("0.1.4")).into_untagged_value()
|
UntaggedValue::string(String::from("0.1.4")).into_untagged_value()
|
||||||
),
|
),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use nu::{serve_plugin, value, Plugin, TaggedDictBuilder};
|
use nu::{serve_plugin, Plugin, TaggedDictBuilder};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, SyntaxShape, UntaggedValue, Value,
|
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, SyntaxShape, UntaggedValue, Value,
|
||||||
|
@ -134,7 +134,10 @@ impl Plugin for Parse {
|
||||||
let mut dict = TaggedDictBuilder::new(input.tag());
|
let mut dict = TaggedDictBuilder::new(input.tag());
|
||||||
|
|
||||||
for (idx, column_name) in self.column_names.iter().enumerate() {
|
for (idx, column_name) in self.column_names.iter().enumerate() {
|
||||||
dict.insert_untagged(column_name, value::string(&cap[idx + 1].to_string()));
|
dict.insert_untagged(
|
||||||
|
column_name,
|
||||||
|
UntaggedValue::string(&cap[idx + 1].to_string()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
results.push(ReturnSuccess::value(dict.into_value()));
|
results.push(ReturnSuccess::value(dict.into_value()));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use nu::{did_you_mean, serve_plugin, value, Plugin, ValueExt};
|
use nu::{did_you_mean, serve_plugin, Plugin, ValueExt};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
CallInfo, ColumnPath, Primitive, ReturnSuccess, ReturnValue, ShellTypeName, Signature,
|
CallInfo, ColumnPath, Primitive, ReturnSuccess, ReturnValue, ShellTypeName, Signature,
|
||||||
|
@ -41,15 +41,15 @@ impl Str {
|
||||||
|
|
||||||
fn apply(&self, input: &str) -> Result<UntaggedValue, ShellError> {
|
fn apply(&self, input: &str) -> Result<UntaggedValue, ShellError> {
|
||||||
let applied = match self.action.as_ref() {
|
let applied = match self.action.as_ref() {
|
||||||
Some(Action::Downcase) => value::string(input.to_ascii_lowercase()),
|
Some(Action::Downcase) => UntaggedValue::string(input.to_ascii_lowercase()),
|
||||||
Some(Action::Upcase) => value::string(input.to_ascii_uppercase()),
|
Some(Action::Upcase) => UntaggedValue::string(input.to_ascii_uppercase()),
|
||||||
Some(Action::Substring(s, e)) => {
|
Some(Action::Substring(s, e)) => {
|
||||||
let end: usize = cmp::min(*e, input.len());
|
let end: usize = cmp::min(*e, input.len());
|
||||||
let start: usize = *s;
|
let start: usize = *s;
|
||||||
if start > input.len() - 1 {
|
if start > input.len() - 1 {
|
||||||
value::string("")
|
UntaggedValue::string("")
|
||||||
} else {
|
} else {
|
||||||
value::string(
|
UntaggedValue::string(
|
||||||
&input
|
&input
|
||||||
.chars()
|
.chars()
|
||||||
.skip(start)
|
.skip(start)
|
||||||
|
@ -59,23 +59,25 @@ impl Str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Action::Replace(mode)) => match mode {
|
Some(Action::Replace(mode)) => match mode {
|
||||||
ReplaceAction::Direct(replacement) => value::string(replacement.as_str()),
|
ReplaceAction::Direct(replacement) => UntaggedValue::string(replacement.as_str()),
|
||||||
ReplaceAction::FindAndReplace(find, replacement) => {
|
ReplaceAction::FindAndReplace(find, replacement) => {
|
||||||
let regex = Regex::new(find.as_str());
|
let regex = Regex::new(find.as_str());
|
||||||
|
|
||||||
match regex {
|
match regex {
|
||||||
Ok(re) => value::string(re.replace(input, replacement.as_str()).to_owned()),
|
Ok(re) => UntaggedValue::string(
|
||||||
Err(_) => value::string(input),
|
re.replace(input, replacement.as_str()).to_owned(),
|
||||||
|
),
|
||||||
|
Err(_) => UntaggedValue::string(input),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(Action::ToInteger) => match input.trim() {
|
Some(Action::ToInteger) => match input.trim() {
|
||||||
other => match other.parse::<i64>() {
|
other => match other.parse::<i64>() {
|
||||||
Ok(v) => value::int(v),
|
Ok(v) => UntaggedValue::int(v),
|
||||||
Err(_) => value::string(input),
|
Err(_) => UntaggedValue::string(input),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
None => value::string(input),
|
None => UntaggedValue::string(input),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(applied)
|
Ok(applied)
|
||||||
|
@ -315,17 +317,17 @@ fn main() {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Action, ReplaceAction, Str};
|
use super::{Action, ReplaceAction, Str};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu::{value, Plugin, TaggedDictBuilder, ValueExt};
|
use nu::{Plugin, TaggedDictBuilder, ValueExt};
|
||||||
use nu_protocol::{CallInfo, EvaluatedArgs, Primitive, ReturnSuccess, UntaggedValue, Value};
|
use nu_protocol::{CallInfo, EvaluatedArgs, Primitive, ReturnSuccess, UntaggedValue, Value};
|
||||||
use nu_source::Tag;
|
use nu_source::Tag;
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
|
||||||
fn string(input: impl Into<String>) -> Value {
|
fn string(input: impl Into<String>) -> Value {
|
||||||
value::string(input.into()).into_untagged_value()
|
UntaggedValue::string(input.into()).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table(list: &Vec<Value>) -> Value {
|
fn table(list: &Vec<Value>) -> Value {
|
||||||
value::table(list).into_untagged_value()
|
UntaggedValue::table(list).into_untagged_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_path(paths: &Vec<Value>) -> Value {
|
fn column_path(paths: &Vec<Value>) -> Value {
|
||||||
|
@ -358,7 +360,7 @@ mod tests {
|
||||||
fn with_long_flag(&mut self, name: &str) -> &mut Self {
|
fn with_long_flag(&mut self, name: &str) -> &mut Self {
|
||||||
self.flags.insert(
|
self.flags.insert(
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
value::boolean(true).into_value(Tag::unknown()),
|
UntaggedValue::boolean(true).into_value(Tag::unknown()),
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -366,7 +368,7 @@ mod tests {
|
||||||
fn with_parameter(&mut self, name: &str) -> &mut Self {
|
fn with_parameter(&mut self, name: &str) -> &mut Self {
|
||||||
let fields: Vec<Value> = name
|
let fields: Vec<Value> = name
|
||||||
.split(".")
|
.split(".")
|
||||||
.map(|s| value::string(s.to_string()).into_value(Tag::unknown()))
|
.map(|s| UntaggedValue::string(s.to_string()).into_value(Tag::unknown()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
self.positionals.push(column_path(&fields));
|
self.positionals.push(column_path(&fields));
|
||||||
|
@ -383,12 +385,12 @@ mod tests {
|
||||||
|
|
||||||
fn structured_sample_record(key: &str, value: &str) -> Value {
|
fn structured_sample_record(key: &str, value: &str) -> Value {
|
||||||
let mut record = TaggedDictBuilder::new(Tag::unknown());
|
let mut record = TaggedDictBuilder::new(Tag::unknown());
|
||||||
record.insert_untagged(key.clone(), value::string(value));
|
record.insert_untagged(key.clone(), UntaggedValue::string(value));
|
||||||
record.into_value()
|
record.into_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unstructured_sample_record(value: &str) -> Value {
|
fn unstructured_sample_record(value: &str) -> Value {
|
||||||
value::string(value).into_value(Tag::unknown())
|
UntaggedValue::string(value).into_value(Tag::unknown())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -530,21 +532,30 @@ mod tests {
|
||||||
fn str_downcases() {
|
fn str_downcases() {
|
||||||
let mut strutils = Str::new();
|
let mut strutils = Str::new();
|
||||||
strutils.for_downcase();
|
strutils.for_downcase();
|
||||||
assert_eq!(strutils.apply("ANDRES").unwrap(), value::string("andres"));
|
assert_eq!(
|
||||||
|
strutils.apply("ANDRES").unwrap(),
|
||||||
|
UntaggedValue::string("andres")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn str_upcases() {
|
fn str_upcases() {
|
||||||
let mut strutils = Str::new();
|
let mut strutils = Str::new();
|
||||||
strutils.for_upcase();
|
strutils.for_upcase();
|
||||||
assert_eq!(strutils.apply("andres").unwrap(), value::string("ANDRES"));
|
assert_eq!(
|
||||||
|
strutils.apply("andres").unwrap(),
|
||||||
|
UntaggedValue::string("ANDRES")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn str_to_int() {
|
fn str_to_int() {
|
||||||
let mut strutils = Str::new();
|
let mut strutils = Str::new();
|
||||||
strutils.for_to_int();
|
strutils.for_to_int();
|
||||||
assert_eq!(strutils.apply("9999").unwrap(), value::int(9999 as i64));
|
assert_eq!(
|
||||||
|
strutils.apply("9999").unwrap(),
|
||||||
|
UntaggedValue::int(9999 as i64)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -552,7 +563,10 @@ mod tests {
|
||||||
let mut strutils = Str::new();
|
let mut strutils = Str::new();
|
||||||
strutils.for_replace(ReplaceAction::Direct("robalino".to_string()));
|
strutils.for_replace(ReplaceAction::Direct("robalino".to_string()));
|
||||||
|
|
||||||
assert_eq!(strutils.apply("andres").unwrap(), value::string("robalino"));
|
assert_eq!(
|
||||||
|
strutils.apply("andres").unwrap(),
|
||||||
|
UntaggedValue::string("robalino")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -564,7 +578,7 @@ mod tests {
|
||||||
));
|
));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
strutils.apply("wykittens").unwrap(),
|
strutils.apply("wykittens").unwrap(),
|
||||||
value::string("wyjotandrehuda")
|
UntaggedValue::string("wyjotandrehuda")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,7 +604,7 @@ mod tests {
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("name")).borrow(),
|
*o.get_data(&String::from("name")).borrow(),
|
||||||
value::string(String::from("JOTANDREHUDA")).into_untagged_value()
|
UntaggedValue::string(String::from("JOTANDREHUDA")).into_untagged_value()
|
||||||
),
|
),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -638,7 +652,7 @@ mod tests {
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("name")).borrow(),
|
*o.get_data(&String::from("name")).borrow(),
|
||||||
value::string(String::from("jotandrehuda")).into_untagged_value()
|
UntaggedValue::string(String::from("jotandrehuda")).into_untagged_value()
|
||||||
),
|
),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -686,7 +700,7 @@ mod tests {
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("Nu_birthday")).borrow(),
|
*o.get_data(&String::from("Nu_birthday")).borrow(),
|
||||||
value::int(10).into_untagged_value()
|
UntaggedValue::int(10).into_untagged_value()
|
||||||
),
|
),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -872,7 +886,7 @@ mod tests {
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("rustconf")).borrow(),
|
*o.get_data(&String::from("rustconf")).borrow(),
|
||||||
Value {
|
Value {
|
||||||
value: value::string(String::from("22nd August 2019")),
|
value: UntaggedValue::string(String::from("22nd August 2019")),
|
||||||
tag: Tag::unknown()
|
tag: Tag::unknown()
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
@ -930,7 +944,7 @@ mod tests {
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("staff")).borrow(),
|
*o.get_data(&String::from("staff")).borrow(),
|
||||||
Value {
|
Value {
|
||||||
value: value::string(String::from("wyjotandrehuda")),
|
value: UntaggedValue::string(String::from("wyjotandrehuda")),
|
||||||
tag: Tag::unknown()
|
tag: Tag::unknown()
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use nu::{serve_plugin, value, Plugin};
|
use nu::{serve_plugin, Plugin};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, UntaggedValue, Value,
|
CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, UntaggedValue, Value,
|
||||||
|
@ -22,7 +22,7 @@ impl Sum {
|
||||||
tag,
|
tag,
|
||||||
}) => {
|
}) => {
|
||||||
//TODO: handle overflow
|
//TODO: handle overflow
|
||||||
self.total = Some(value::int(i + j).into_value(tag));
|
self.total = Some(UntaggedValue::int(i + j).into_value(tag));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -43,7 +43,7 @@ impl Sum {
|
||||||
tag,
|
tag,
|
||||||
}) => {
|
}) => {
|
||||||
//TODO: handle overflow
|
//TODO: handle overflow
|
||||||
self.total = Some(value::bytes(b + j).into_value(tag));
|
self.total = Some(UntaggedValue::bytes(b + j).into_value(tag));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -68,25 +68,6 @@ macro_rules! trace_out_stream {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! dict {
|
|
||||||
($( $key:expr => $value:expr ),*) => {
|
|
||||||
$crate::data::dict::TaggedDictBuilder::build(Tag::unknown(), |d| {
|
|
||||||
$(
|
|
||||||
d.insert_untagged($key, $value);
|
|
||||||
)*
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
([tag] => $tag:expr, $( $key:expr => $value:expr ),*) => {
|
|
||||||
$crate::data::dict::TaggedDictBuilder::build($tag, |d| {
|
|
||||||
$(
|
|
||||||
d.insert_untagged($key, $value);
|
|
||||||
)*
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) use nu_protocol::{errln, outln};
|
pub(crate) use nu_protocol::{errln, outln};
|
||||||
|
|
||||||
pub(crate) use crate::commands::command::{
|
pub(crate) use crate::commands::command::{
|
||||||
|
|
|
@ -3,11 +3,11 @@ use crate::commands::cp::CopyArgs;
|
||||||
use crate::commands::mkdir::MkdirArgs;
|
use crate::commands::mkdir::MkdirArgs;
|
||||||
use crate::commands::mv::MoveArgs;
|
use crate::commands::mv::MoveArgs;
|
||||||
use crate::commands::rm::RemoveArgs;
|
use crate::commands::rm::RemoveArgs;
|
||||||
use crate::data::{command_dict, TaggedDictBuilder};
|
use crate::data::{command_dict};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::shell::shell::Shell;
|
use crate::shell::shell::Shell;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, ShellTypeName, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, ShellTypeName, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
|
@ -218,7 +218,7 @@ impl Shell for ValueShell {
|
||||||
fn pwd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
fn pwd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let mut stream = VecDeque::new();
|
let mut stream = VecDeque::new();
|
||||||
stream.push_back(ReturnSuccess::value(
|
stream.push_back(ReturnSuccess::value(
|
||||||
value::string(self.path()).into_value(&args.call_info.name_tag),
|
UntaggedValue::string(self.path()).into_value(&args.call_info.name_tag),
|
||||||
));
|
));
|
||||||
Ok(stream.into())
|
Ok(stream.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,8 +332,7 @@ impl FileStructure {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{FileStructure, Res, ValueResource, ValueStructure};
|
use super::{FileStructure, Res, ValueResource, ValueStructure};
|
||||||
use crate::data::{value, TaggedDictBuilder};
|
use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use nu_protocol::Value;
|
|
||||||
use nu_source::Tag;
|
use nu_source::Tag;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -352,7 +351,7 @@ mod tests {
|
||||||
|
|
||||||
fn structured_sample_record(key: &str, value: &str) -> Value {
|
fn structured_sample_record(key: &str, value: &str) -> Value {
|
||||||
let mut record = TaggedDictBuilder::new(Tag::unknown());
|
let mut record = TaggedDictBuilder::new(Tag::unknown());
|
||||||
record.insert_untagged(key.clone(), value::string(value));
|
record.insert_untagged(key.clone(), UntaggedValue::string(value));
|
||||||
record.into_value()
|
record.into_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue