diff --git a/Cargo.lock b/Cargo.lock index 844fa247bf..9ff004f6fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1884,7 +1884,6 @@ dependencies = [ "app_dirs", "async-stream", "base64 0.11.0", - "battery", "bigdecimal", "bson", "byte-unit", @@ -1903,13 +1902,11 @@ dependencies = [ "dirs 2.0.2", "dunce", "futures-preview", - "futures-timer", "futures-util", "futures_codec", "getset", "git2", "glob", - "heim", "hex 0.4.0", "indexmap", "itertools 0.8.2", @@ -1926,10 +1923,11 @@ dependencies = [ "nu-protocol", "nu-source", "nu_plugin_binaryview", + "nu_plugin_ps", + "nu_plugin_sys", "nu_plugin_textview", "num-bigint", "num-traits 0.2.10", - "onig_sys", "pin-utils", "pretty", "pretty-hex", @@ -1956,7 +1954,6 @@ dependencies = [ "sublime_fuzzy", "subprocess", "surf", - "syntect", "tempfile", "term", "termcolor", @@ -2091,8 +2088,35 @@ dependencies = [ "nu-source", "pretty-hex", "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]] diff --git a/Cargo.toml b/Cargo.toml index f0d1f68492..4ec79ea426 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,8 @@ members = [ "crates/nu-source", "crates/nu_plugin_textview", "crates/nu_plugin_binaryview", + "crates/nu_plugin_ps", + "crates/nu_plugin_sys", "crates/nu-protocol", "crates/nu-parser", "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_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_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" typetag = "0.1.4" @@ -87,7 +91,6 @@ semver = "0.9.0" which = "3.1" textwrap = {version = "0.11.0", features = ["term_size"]} shellexpand = "1.0.0" -futures-timer = "2.0.0" pin-utils = "0.1.0-alpha.4" num-bigint = { version = "0.2.3", features = ["serde"] } bigdecimal = { version = "0.1.0", features = ["serde"] } @@ -106,21 +109,17 @@ termcolor = "1.0.5" console = "0.9.1" 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 } ptree = {version = "0.2" } starship = { version = "0.26.4", optional = true} [features] default = ["sys", "ps"] -sys = ["heim", "battery"] -ps = ["heim"] +sys = ["nu_plugin_ps"] starship-prompt = ["starship"] textview = ["nu_plugin_textview"] binaryview = ["nu_plugin_binaryview"] +ps = ["nu_plugin_ps"] #trace = ["nu-parser/trace"] [dependencies.rusqlite] @@ -183,16 +182,6 @@ path = "src/plugins/skip.rs" name = "nu_plugin_match" 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]] name = "nu_plugin_tree" path = "src/plugins/tree.rs" diff --git a/crates/nu-protocol/src/lib.rs b/crates/nu-protocol/src/lib.rs index 8aa60ea695..69412b4b19 100644 --- a/crates/nu-protocol/src/lib.rs +++ b/crates/nu-protocol/src/lib.rs @@ -18,7 +18,7 @@ pub use crate::signature::{NamedType, PositionalType, Signature}; pub use crate::syntax_shape::SyntaxShape; pub use crate::type_name::{PrettyType, ShellTypeName, SpannedTypeName}; 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::primitive::Primitive; pub use crate::value::{UntaggedValue, Value}; diff --git a/crates/nu-protocol/src/value.rs b/crates/nu-protocol/src/value.rs index fbbc10304d..c5c6c47368 100644 --- a/crates/nu-protocol/src/value.rs +++ b/crates/nu-protocol/src/value.rs @@ -11,10 +11,15 @@ use crate::type_name::{ShellTypeName, SpannedTypeName}; use crate::value::dict::Dictionary; use crate::value::evaluate::Evaluate; use crate::value::primitive::Primitive; +use crate::{ColumnPath, PathMember}; +use bigdecimal::BigDecimal; +use indexmap::IndexMap; use nu_errors::ShellError; use nu_source::{AnchorLocation, HasSpan, Span, Tag}; +use num_bigint::BigInt; use serde::{Deserialize, Serialize}; use std::path::PathBuf; +use std::time::SystemTime; #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Serialize, Deserialize)] pub enum UntaggedValue { @@ -103,6 +108,69 @@ impl UntaggedValue { _ => panic!("expect_string assumes that the value must be a string"), } } + + #[allow(unused)] + pub fn row(entries: IndexMap) -> UntaggedValue { + UntaggedValue::Row(entries.into()) + } + + pub fn table(list: &Vec) -> UntaggedValue { + UntaggedValue::Table(list.to_vec()) + } + + pub fn string(s: impl Into) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::String(s.into())) + } + + pub fn line(s: impl Into) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::Line(s.into())) + } + + pub fn column_path(s: Vec>) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::new( + s.into_iter().map(|p| p.into()).collect(), + ))) + } + + pub fn int(i: impl Into) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::Int(i.into())) + } + + pub fn pattern(s: impl Into) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::String(s.into())) + } + + pub fn path(s: impl Into) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::Path(s.into())) + } + + pub fn bytes(s: impl Into) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::Bytes(s.into())) + } + + pub fn decimal(s: impl Into) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::Decimal(s.into())) + } + + pub fn binary(binary: Vec) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::Binary(binary)) + } + + pub fn boolean(s: impl Into) -> 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)] diff --git a/crates/nu-protocol/src/value/dict.rs b/crates/nu-protocol/src/value/dict.rs index d8c588803d..6524fc5d9a 100644 --- a/crates/nu-protocol/src/value/dict.rs +++ b/crates/nu-protocol/src/value/dict.rs @@ -138,3 +138,59 @@ impl Dictionary { self.entries.insert(name.to_string(), value); } } + +#[derive(Debug)] +pub struct TaggedDictBuilder { + tag: Tag, + dict: IndexMap, +} + +impl TaggedDictBuilder { + pub fn new(tag: impl Into) -> TaggedDictBuilder { + TaggedDictBuilder { + tag: tag.into(), + dict: IndexMap::default(), + } + } + + pub fn build(tag: impl Into, 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, n: usize) -> TaggedDictBuilder { + TaggedDictBuilder { + tag: tag.into(), + dict: IndexMap::with_capacity(n), + } + } + + pub fn insert_untagged(&mut self, key: impl Into, value: impl Into) { + self.dict + .insert(key.into(), value.into().into_value(&self.tag)); + } + + pub fn insert_value(&mut self, key: impl Into, value: impl Into) { + 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 for Value { + fn from(input: TaggedDictBuilder) -> Value { + input.into_value() + } +} diff --git a/crates/nu_plugin_binaryview/Cargo.toml b/crates/nu_plugin_binaryview/Cargo.toml index 626eeb99b0..d704fdcb2e 100644 --- a/crates/nu_plugin_binaryview/Cargo.toml +++ b/crates/nu_plugin_binaryview/Cargo.toml @@ -7,13 +7,11 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -syntect = { version = "3.2.0" } ansi_term = "0.12.1" crossterm = { version = "0.10.2" } nu-protocol = { path = "../nu-protocol" } nu-source = { path = "../nu-source" } nu-errors = { path = "../nu-errors" } -url = "2.1.0" pretty-hex = "0.1.1" image = { version = "0.22.2", default_features = false, features = ["png_codec", "jpeg"] } rawkey = "0.1.2" diff --git a/crates/nu_plugin_ps/Cargo.toml b/crates/nu_plugin_ps/Cargo.toml new file mode 100644 index 0000000000..d21db319b5 --- /dev/null +++ b/crates/nu_plugin_ps/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "nu_plugin_ps" +version = "0.1.0" +authors = ["Yehuda Katz ", "Jonathan Turner ", "Andrés N. Robalino "] +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" } diff --git a/crates/nu_plugin_ps/build.rs b/crates/nu_plugin_ps/build.rs new file mode 100644 index 0000000000..b7511cfc6a --- /dev/null +++ b/crates/nu_plugin_ps/build.rs @@ -0,0 +1,3 @@ +fn main() -> Result<(), Box> { + nu_build::build() +} diff --git a/src/plugins/ps.rs b/crates/nu_plugin_ps/src/main.rs similarity index 80% rename from src/plugins/ps.rs rename to crates/nu_plugin_ps/src/main.rs index 3c3d7f4644..0abfee2b40 100644 --- a/src/plugins/ps.rs +++ b/crates/nu_plugin_ps/src/main.rs @@ -5,9 +5,11 @@ use heim::process::{self as process, Process, ProcessResult}; use heim::units::{ratio, Ratio}; use std::usize; -use nu::{serve_plugin, value, Plugin, TaggedDictBuilder}; 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 std::time::Duration; @@ -42,14 +44,14 @@ async fn ps(tag: Tag) -> Vec { while let Some(res) = processes.next().await { if let Ok((process, usage)) = res { 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 { - dict.insert_untagged("name", value::string(name)); + dict.insert_untagged("name", UntaggedValue::string(name)); } 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::())); + dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::())); output.push(dict.into_value()); } } diff --git a/crates/nu_plugin_sys/Cargo.toml b/crates/nu_plugin_sys/Cargo.toml new file mode 100644 index 0000000000..caf9a9d47b --- /dev/null +++ b/crates/nu_plugin_sys/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "nu_plugin_sys" +version = "0.1.0" +authors = ["Yehuda Katz ", "Jonathan Turner ", "Andrés N. Robalino "] +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" } diff --git a/crates/nu_plugin_sys/build.rs b/crates/nu_plugin_sys/build.rs new file mode 100644 index 0000000000..b7511cfc6a --- /dev/null +++ b/crates/nu_plugin_sys/build.rs @@ -0,0 +1,3 @@ +fn main() -> Result<(), Box> { + nu_build::build() +} diff --git a/src/plugins/sys.rs b/crates/nu_plugin_sys/src/main.rs similarity index 72% rename from src/plugins/sys.rs rename to crates/nu_plugin_sys/src/main.rs index c4816e6adc..769c9bc2f9 100644 --- a/src/plugins/sys.rs +++ b/crates/nu_plugin_sys/src/main.rs @@ -4,9 +4,11 @@ use futures::executor::block_on; use futures::stream::StreamExt; use heim::units::{frequency, information, thermodynamic_temperature, time}; use heim::{disk, host, memory, net, sensors}; -use nu::{primitive, serve_plugin, value, Plugin, TaggedDictBuilder}; 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; struct Sys; @@ -20,26 +22,26 @@ async fn cpu(tag: Tag) -> Option { match futures::future::try_join(heim::cpu::logical_count(), heim::cpu::frequency()).await { Ok((num_cpu, cpu_speed)) => { 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 = (cpu_speed.current().get::() as f64 / 1_000_000_000.0 * 100.0) .round() / 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() { let min_speed = (min_speed.get::() as f64 / 1_000_000_000.0 * 100.0).round() / 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() { let max_speed = (max_speed.get::() as f64 / 1_000_000_000.0 * 100.0).round() / 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()) @@ -57,22 +59,22 @@ async fn mem(tag: Tag) -> Value { if let Ok(memory) = memory_result { dict.insert_untagged( "total", - value::bytes(memory.total().get::()), + UntaggedValue::bytes(memory.total().get::()), ); dict.insert_untagged( "free", - value::bytes(memory.free().get::()), + UntaggedValue::bytes(memory.free().get::()), ); } if let Ok(swap) = swap_result { dict.insert_untagged( "swap total", - value::bytes(swap.total().get::()), + UntaggedValue::bytes(swap.total().get::()), ); dict.insert_untagged( "swap free", - value::bytes(swap.free().get::()), + UntaggedValue::bytes(swap.free().get::()), ); } @@ -87,10 +89,13 @@ async fn host(tag: Tag) -> Value { // OS if let Ok(platform) = platform_result { - dict.insert_untagged("name", value::string(platform.system())); - dict.insert_untagged("release", value::string(platform.release())); - dict.insert_untagged("hostname", value::string(platform.hostname())); - dict.insert_untagged("arch", value::string(platform.architecture().as_str())); + dict.insert_untagged("name", UntaggedValue::string(platform.system())); + dict.insert_untagged("release", UntaggedValue::string(platform.release())); + dict.insert_untagged("hostname", UntaggedValue::string(platform.hostname())); + dict.insert_untagged( + "arch", + UntaggedValue::string(platform.architecture().as_str()), + ); } // Uptime @@ -103,10 +108,10 @@ async fn host(tag: Tag) -> Value { let minutes = (uptime - days * 60 * 60 * 24 - hours * 60 * 60) / 60; let seconds = uptime % 60; - uptime_dict.insert_untagged("days", value::int(days)); - uptime_dict.insert_untagged("hours", value::int(hours)); - uptime_dict.insert_untagged("mins", value::int(minutes)); - uptime_dict.insert_untagged("secs", value::int(seconds)); + uptime_dict.insert_untagged("days", UntaggedValue::int(days)); + uptime_dict.insert_untagged("hours", UntaggedValue::int(hours)); + uptime_dict.insert_untagged("mins", UntaggedValue::int(minutes)); + uptime_dict.insert_untagged("secs", UntaggedValue::int(seconds)); dict.insert_value("uptime", uptime_dict); } @@ -117,7 +122,7 @@ async fn host(tag: Tag) -> Value { while let Some(user) = users.next().await { if let Ok(user) = user { user_vec.push(Value { - value: value::string(user.username()), + value: UntaggedValue::string(user.username()), tag: tag.clone(), }); } @@ -136,28 +141,31 @@ async fn disks(tag: Tag) -> Option { let mut dict = TaggedDictBuilder::with_capacity(&tag, 6); dict.insert_untagged( "device", - value::string( + UntaggedValue::string( part.device() .unwrap_or_else(|| OsStr::new("N/A")) .to_string_lossy(), ), ); - dict.insert_untagged("type", value::string(part.file_system().as_str())); - dict.insert_untagged("mount", value::string(part.mount_point().to_string_lossy())); + dict.insert_untagged("type", UntaggedValue::string(part.file_system().as_str())); + 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 { dict.insert_untagged( "total", - value::bytes(usage.total().get::()), + UntaggedValue::bytes(usage.total().get::()), ); dict.insert_untagged( "used", - value::bytes(usage.used().get::()), + UntaggedValue::bytes(usage.used().get::()), ); dict.insert_untagged( "free", - value::bytes(usage.free().get::()), + UntaggedValue::bytes(usage.free().get::()), ); } @@ -181,24 +189,28 @@ async fn battery(tag: Tag) -> Option { if let Ok(battery) = battery { let mut dict = TaggedDictBuilder::new(&tag); 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() { - dict.insert_untagged("model", value::string(model)); + dict.insert_untagged("model", UntaggedValue::string(model)); } 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() { dict.insert_untagged( "mins to full", - value::number(time_to_full.get::()), + UntaggedValue::decimal( + time_to_full.get::(), + ), ); } if let Some(time_to_empty) = battery.time_to_empty() { dict.insert_untagged( "mins to empty", - value::number(time_to_empty.get::()), + UntaggedValue::decimal( + time_to_empty.get::(), + ), ); } output.push(dict.into_value()); @@ -221,13 +233,13 @@ async fn temp(tag: Tag) -> Option { while let Some(sensor) = sensors.next().await { if let Ok(sensor) = sensor { 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() { - dict.insert_untagged("label", value::string(label)); + dict.insert_untagged("label", UntaggedValue::string(label)); } dict.insert_untagged( "temp", - value::number( + UntaggedValue::decimal( sensor .current() .get::(), @@ -236,13 +248,15 @@ async fn temp(tag: Tag) -> Option { if let Some(high) = sensor.high() { dict.insert_untagged( "high", - value::number(high.get::()), + UntaggedValue::decimal(high.get::()), ); } if let Some(critical) = sensor.critical() { dict.insert_untagged( "critical", - value::number(critical.get::()), + UntaggedValue::decimal( + critical.get::(), + ), ); } @@ -263,14 +277,14 @@ async fn net(tag: Tag) -> Option { while let Some(nic) = io_counters.next().await { if let Ok(nic) = nic { 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( "sent", - value::bytes(nic.bytes_sent().get::()), + UntaggedValue::bytes(nic.bytes_sent().get::()), ); network_idx.insert_untagged( "recv", - value::bytes(nic.bytes_recv().get::()), + UntaggedValue::bytes(nic.bytes_recv().get::()), ); output.push(network_idx.into_value()); } diff --git a/src/commands/autoview.rs b/src/commands/autoview.rs index 06f69f4ec1..b81a343532 100644 --- a/src/commands/autoview.rs +++ b/src/commands/autoview.rs @@ -1,5 +1,4 @@ use crate::commands::{RawCommandArgs, WholeStreamCommand}; -use crate::data::value; use crate::prelude::*; use futures::stream::TryStreamExt; use nu_errors::ShellError; @@ -139,7 +138,7 @@ pub fn autoview( } if anchor.is_some() => { if let Some(text) = text { 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); result.collect::>().await; } else { @@ -158,7 +157,7 @@ pub fn autoview( } if anchor.is_some() => { if let Some(text) = text { 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); result.collect::>().await; } else { @@ -227,7 +226,7 @@ pub fn autoview( // Needed for async_stream to type check if false { - yield ReturnSuccess::value(value::nothing().into_untagged_value()); + yield ReturnSuccess::value(UntaggedValue::nothing().into_untagged_value()); } })) } diff --git a/src/commands/classified/external.rs b/src/commands/classified/external.rs index e56bfa7e1b..9211b20dda 100644 --- a/src/commands/classified/external.rs +++ b/src/commands/classified/external.rs @@ -5,7 +5,7 @@ use futures_codec::{Decoder, Encoder, Framed}; use log::trace; use nu_errors::ShellError; use nu_parser::ExternalCommand; -use nu_protocol::Value; +use nu_protocol::{UntaggedValue, Value}; use std::io::{Error, ErrorKind}; use subprocess::Exec; @@ -33,14 +33,14 @@ impl Decoder for LinesCodec { Some(pos) if !src.is_empty() => { let buf = src.split_to(pos + 1); String::from_utf8(buf.to_vec()) - .map(value::line) + .map(UntaggedValue::line) .map(Some) .map_err(|e| Error::new(ErrorKind::InvalidData, e)) } _ if !src.is_empty() => { let drained = src.take(); String::from_utf8(drained.to_vec()) - .map(value::string) + .map(UntaggedValue::string) .map(Some) .map_err(|e| Error::new(ErrorKind::InvalidData, e)) } diff --git a/src/commands/classified/internal.rs b/src/commands/classified/internal.rs index ee928bf7a5..fb0add5ec8 100644 --- a/src/commands/classified/internal.rs +++ b/src/commands/classified/internal.rs @@ -60,7 +60,7 @@ pub(crate) async fn run_internal_command( } => { context.shell_manager.insert_at_current(Box::new( HelpShell::for_command( - value::string(cmd).into_value(tag), + UntaggedValue::string(cmd).into_value(tag), &context.registry(), ).unwrap(), )); @@ -114,7 +114,7 @@ pub(crate) async fn run_internal_command( 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) => { diff --git a/src/commands/classified/mod.rs b/src/commands/classified/mod.rs index f786c8dabd..5e5d5b95ff 100644 --- a/src/commands/classified/mod.rs +++ b/src/commands/classified/mod.rs @@ -1,5 +1,5 @@ -use crate::data::value; use crate::prelude::*; +use nu_protocol::UntaggedValue; mod dynamic; pub(crate) mod external; @@ -17,7 +17,7 @@ pub(crate) struct ClassifiedInputStream { impl ClassifiedInputStream { pub(crate) fn new() -> ClassifiedInputStream { ClassifiedInputStream { - objects: vec![value::nothing().into_value(Tag::unknown())].into(), + objects: vec![UntaggedValue::nothing().into_value(Tag::unknown())].into(), stdin: None, } } diff --git a/src/commands/count.rs b/src/commands/count.rs index f6b7b78cb4..1c2f439f5c 100644 --- a/src/commands/count.rs +++ b/src/commands/count.rs @@ -1,10 +1,9 @@ use crate::commands::WholeStreamCommand; use crate::context::CommandRegistry; -use crate::data::value; use crate::prelude::*; use futures::stream::StreamExt; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature, Value}; +use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value}; pub struct Count; @@ -40,7 +39,7 @@ pub fn count( let stream = async_stream! { let rows: Vec = 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()) diff --git a/src/commands/date.rs b/src/commands/date.rs index 438939daca..e0bae5ff89 100644 --- a/src/commands/date.rs +++ b/src/commands/date.rs @@ -4,7 +4,6 @@ use nu_errors::ShellError; use nu_protocol::{Dictionary, Value}; use crate::commands::WholeStreamCommand; -use crate::data::value; use chrono::{Datelike, TimeZone, Timelike}; use core::fmt::Display; use indexmap::IndexMap; @@ -42,23 +41,35 @@ where { let mut indexmap = IndexMap::new(); - indexmap.insert("year".to_string(), value::int(dt.year()).into_value(&tag)); - indexmap.insert("month".to_string(), value::int(dt.month()).into_value(&tag)); - indexmap.insert("day".to_string(), value::int(dt.day()).into_value(&tag)); - indexmap.insert("hour".to_string(), value::int(dt.hour()).into_value(&tag)); + indexmap.insert( + "year".to_string(), + UntaggedValue::int(dt.year()).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( "minute".to_string(), - value::int(dt.minute()).into_value(&tag), + UntaggedValue::int(dt.minute()).into_value(&tag), ); indexmap.insert( "second".to_string(), - value::int(dt.second()).into_value(&tag), + UntaggedValue::int(dt.second()).into_value(&tag), ); let tz = dt.offset(); indexmap.insert( "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) diff --git a/src/commands/debug.rs b/src/commands/debug.rs index e19995e6b1..740ef4cf24 100644 --- a/src/commands/debug.rs +++ b/src/commands/debug.rs @@ -1,8 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::value; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature}; +use nu_protocol::{ReturnSuccess, Signature, UntaggedValue}; pub struct Debug; @@ -37,6 +36,8 @@ fn debug_value( ) -> Result { Ok(input .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()) } diff --git a/src/commands/echo.rs b/src/commands/echo.rs index 50a995ae9d..3732696886 100644 --- a/src/commands/echo.rs +++ b/src/commands/echo.rs @@ -1,4 +1,3 @@ -use crate::data::value; use crate::prelude::*; use nu_errors::ShellError; use nu_protocol::{CallInfo, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value}; @@ -41,7 +40,7 @@ fn run( match i.as_string() { Ok(s) => { output.push(Ok(ReturnSuccess::Value( - value::string(s).into_value(i.tag.clone()), + UntaggedValue::string(s).into_value(i.tag.clone()), ))); } _ => match i { diff --git a/src/commands/enter.rs b/src/commands/enter.rs index 26e55291ff..bbd9ceac0f 100644 --- a/src/commands/enter.rs +++ b/src/commands/enter.rs @@ -1,7 +1,6 @@ use crate::commands::PerItemCommand; use crate::commands::UnevaluatedCallInfo; use crate::context::CommandRegistry; -use crate::data::value; use crate::prelude::*; use nu_errors::ShellError; use nu_protocol::{ @@ -54,12 +53,12 @@ impl PerItemCommand for Enter { if registry.has(command) { Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell( - value::string(command).into_value(Tag::unknown()), + UntaggedValue::string(command).into_value(Tag::unknown()), )))] .into()) } else { Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell( - value::nothing().into_value(Tag::unknown()), + UntaggedValue::nothing().into_value(Tag::unknown()), )))] .into()) } diff --git a/src/commands/env.rs b/src/commands/env.rs index e7385c3202..5ad28f355f 100644 --- a/src/commands/env.rs +++ b/src/commands/env.rs @@ -1,9 +1,8 @@ use crate::cli::History; -use crate::data::{config, value}; +use crate::data::config; use crate::prelude::*; -use crate::TaggedDictBuilder; use nu_errors::ShellError; -use nu_protocol::{Dictionary, Signature, UntaggedValue, Value}; +use nu_protocol::{Dictionary, Signature, TaggedDictBuilder, UntaggedValue, Value}; use crate::commands::WholeStreamCommand; use indexmap::IndexMap; @@ -36,24 +35,39 @@ pub fn get_environment(tag: Tag) -> Result> { let mut indexmap = IndexMap::new(); 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() { - 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()?; - 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(); - 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(); - 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); 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() { indexmap.insert("vars".to_string(), dict.into_value()); diff --git a/src/commands/evaluate_by.rs b/src/commands/evaluate_by.rs index 08559758e0..2b77cca808 100644 --- a/src/commands/evaluate_by.rs +++ b/src/commands/evaluate_by.rs @@ -1,5 +1,4 @@ use crate::commands::WholeStreamCommand; -use crate::data::value; use crate::prelude::*; use nu_errors::ShellError; use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value}; @@ -73,7 +72,7 @@ pub fn evaluate_by( fn fetch(key: Option) -> Box Option + 'static> { Box::new(move |value: Value, tag| match &key { 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; fn int(s: impl Into) -> Value { - value::int(s).into_untagged_value() + UntaggedValue::int(s).into_untagged_value() } fn string(input: impl Into) -> Value { - value::string(input.into()).into_untagged_value() + UntaggedValue::string(input.into()).into_untagged_value() } fn row(entries: IndexMap) -> Value { - value::row(entries).into_untagged_value() + UntaggedValue::row(entries).into_untagged_value() } fn table(list: &Vec) -> Value { - value::table(list).into_untagged_value() + UntaggedValue::table(list).into_untagged_value() } fn nu_releases_sorted_by_date() -> Value { @@ -225,7 +224,7 @@ mod tests { assert_eq!( evaluator(subject, Tag::unknown()), - Some(value::int(1).into_untagged_value()) + Some(UntaggedValue::int(1).into_untagged_value()) ); } diff --git a/src/commands/fetch.rs b/src/commands/fetch.rs index 451a5085e0..ddb0587a13 100644 --- a/src/commands/fetch.rs +++ b/src/commands/fetch.rs @@ -1,5 +1,4 @@ use crate::commands::UnevaluatedCallInfo; -use crate::data::value; use crate::prelude::*; use mime::Mime; use nu_errors::ShellError; @@ -146,7 +145,7 @@ pub async fn fetch( match (content_type.type_(), content_type.subtype()) { (mime::APPLICATION, mime::XML) => Ok(( Some("xml".to_string()), - value::string(r.body_string().await.map_err(|_| { + UntaggedValue::string(r.body_string().await.map_err(|_| { ShellError::labeled_error( "Could not load text from remote url", "could not load", @@ -160,7 +159,7 @@ pub async fn fetch( )), (mime::APPLICATION, mime::JSON) => Ok(( Some("json".to_string()), - value::string(r.body_string().await.map_err(|_| { + UntaggedValue::string(r.body_string().await.map_err(|_| { ShellError::labeled_error( "Could not load text from remote url", "could not load", @@ -182,7 +181,7 @@ pub async fn fetch( })?; Ok(( None, - value::binary(buf), + UntaggedValue::binary(buf), Tag { span, anchor: Some(AnchorLocation::Url(location.to_string())), @@ -191,7 +190,7 @@ pub async fn fetch( } (mime::IMAGE, mime::SVG) => Ok(( Some("svg".to_string()), - value::string(r.body_string().await.map_err(|_| { + UntaggedValue::string(r.body_string().await.map_err(|_| { ShellError::labeled_error( "Could not load svg from remote url", "could not load", @@ -213,7 +212,7 @@ pub async fn fetch( })?; Ok(( Some(image_ty.to_string()), - value::binary(buf), + UntaggedValue::binary(buf), Tag { span, anchor: Some(AnchorLocation::Url(location.to_string())), @@ -222,7 +221,7 @@ pub async fn fetch( } (mime::TEXT, mime::HTML) => Ok(( Some("html".to_string()), - value::string(r.body_string().await.map_err(|_| { + UntaggedValue::string(r.body_string().await.map_err(|_| { ShellError::labeled_error( "Could not load text from remote url", "could not load", @@ -248,7 +247,7 @@ pub async fn fetch( Ok(( path_extension, - value::string(r.body_string().await.map_err(|_| { + UntaggedValue::string(r.body_string().await.map_err(|_| { ShellError::labeled_error( "Could not load text from remote url", "could not load", @@ -263,7 +262,10 @@ pub async fn fetch( } (ty, sub_ty) => Ok(( None, - value::string(format!("Not yet supported MIME type: {} {}", ty, sub_ty)), + UntaggedValue::string(format!( + "Not yet supported MIME type: {} {}", + ty, sub_ty + )), Tag { span, anchor: Some(AnchorLocation::Url(location.to_string())), @@ -273,7 +275,7 @@ pub async fn fetch( } None => Ok(( None, - value::string(format!("No content type found")), + UntaggedValue::string(format!("No content type found")), Tag { span, anchor: Some(AnchorLocation::Url(location.to_string())), diff --git a/src/commands/from_bson.rs b/src/commands/from_bson.rs index e0de2dfeab..1ad11f44c3 100644 --- a/src/commands/from_bson.rs +++ b/src/commands/from_bson.rs @@ -1,10 +1,8 @@ use crate::commands::WholeStreamCommand; -use crate::data::value; -use crate::data::TaggedDictBuilder; use crate::prelude::*; use bson::{decode_document, spec::BinarySubtype, Bson}; 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 std::str::FromStr; @@ -74,8 +72,8 @@ fn convert_bson_value_to_nu_value(v: &Bson, tag: impl Into) -> Result value::number(n).into_value(&tag), - Bson::I64(n) => value::number(n).into_value(&tag), + Bson::I32(n) => UntaggedValue::int(*n).into_value(&tag), + Bson::I64(n) => UntaggedValue::int(*n).into_value(&tag), Bson::Decimal128(n) => { // TODO: this really isn't great, and we should update this to do a higher // fidelity translation @@ -110,7 +108,10 @@ fn convert_bson_value_to_nu_value(v: &Bson, tag: impl Into) -> Result { 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() } Bson::Binary(bst, bytes) => { @@ -118,7 +119,7 @@ fn convert_bson_value_to_nu_value(v: &Bson, tag: impl Into) -> Result value::number(u), + BinarySubtype::UserDefined(u) => UntaggedValue::int(*u), _ => { UntaggedValue::Primitive(Primitive::String(binary_subtype_to_string(*bst))) } diff --git a/src/commands/from_delimited_data.rs b/src/commands/from_delimited_data.rs index 970085ccac..47787fa001 100644 --- a/src/commands/from_delimited_data.rs +++ b/src/commands/from_delimited_data.rs @@ -1,8 +1,7 @@ -use crate::data::TaggedDictBuilder; use crate::prelude::*; use csv::ReaderBuilder; 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( s: String, diff --git a/src/commands/from_ini.rs b/src/commands/from_ini.rs index 0be687e6d3..36e7fb72d1 100644 --- a/src/commands/from_ini.rs +++ b/src/commands/from_ini.rs @@ -1,8 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::TaggedDictBuilder; use crate::prelude::*; 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; pub struct FromINI; diff --git a/src/commands/from_json.rs b/src/commands/from_json.rs index 40ba10d2f6..2ed1febfb2 100644 --- a/src/commands/from_json.rs +++ b/src/commands/from_json.rs @@ -1,8 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::{value, TaggedDictBuilder}; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value}; +use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value}; pub struct FromJSON; @@ -38,10 +37,10 @@ fn convert_json_value_to_nu_value(v: &serde_hjson::Value, tag: impl Into) - match v { 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::F64(n) => value::number(n).into_value(&tag), - serde_hjson::Value::U64(n) => value::number(n).into_value(&tag), - serde_hjson::Value::I64(n) => value::number(n).into_value(&tag), + serde_hjson::Value::Bool(b) => UntaggedValue::boolean(*b).into_value(&tag), + serde_hjson::Value::F64(n) => UntaggedValue::decimal(*n).into_value(&tag), + serde_hjson::Value::U64(n) => UntaggedValue::int(*n).into_value(&tag), + serde_hjson::Value::I64(n) => UntaggedValue::int(*n).into_value(&tag), serde_hjson::Value::String(s) => { UntaggedValue::Primitive(Primitive::String(String::from(s))).into_value(&tag) } diff --git a/src/commands/from_sqlite.rs b/src/commands/from_sqlite.rs index 5c65e4ccc4..0bd1bd51d9 100644 --- a/src/commands/from_sqlite.rs +++ b/src/commands/from_sqlite.rs @@ -1,8 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::{value, TaggedDictBuilder}; use crate::prelude::*; 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 std::io::Write; use std::path::Path; @@ -106,14 +105,14 @@ fn convert_sqlite_value_to_nu_value(value: ValueRef, tag: impl Into + Clone ValueRef::Null => { UntaggedValue::Primitive(Primitive::String(String::from(""))).into_value(tag) } - ValueRef::Integer(i) => value::number(i).into_value(tag), - ValueRef::Real(f) => value::number(f).into_value(tag), + ValueRef::Integer(i) => UntaggedValue::int(i).into_value(tag), + ValueRef::Real(f) => UntaggedValue::decimal(f).into_value(tag), t @ ValueRef::Text(_) => { // this unwrap is safe because we know the ValueRef is Text. UntaggedValue::Primitive(Primitive::String(t.as_str().unwrap().to_string())) .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), } } diff --git a/src/commands/from_ssv.rs b/src/commands/from_ssv.rs index 2752531111..bd4a8679ba 100644 --- a/src/commands/from_ssv.rs +++ b/src/commands/from_ssv.rs @@ -1,8 +1,9 @@ use crate::commands::WholeStreamCommand; -use crate::data::TaggedDictBuilder; use crate::prelude::*; 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; pub struct FromSSV; diff --git a/src/commands/from_toml.rs b/src/commands/from_toml.rs index 9b488b7907..acc035f408 100644 --- a/src/commands/from_toml.rs +++ b/src/commands/from_toml.rs @@ -1,8 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::{value, TaggedDictBuilder}; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value}; +use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value}; pub struct FromTOML; @@ -32,9 +31,9 @@ pub fn convert_toml_value_to_nu_value(v: &toml::Value, tag: impl Into) -> V let tag = tag.into(); match v { - toml::Value::Boolean(b) => value::boolean(*b).into_value(tag), - toml::Value::Integer(n) => value::number(n).into_value(tag), - toml::Value::Float(n) => value::number(n).into_value(tag), + toml::Value::Boolean(b) => UntaggedValue::boolean(*b).into_value(tag), + toml::Value::Integer(n) => UntaggedValue::int(*n).into_value(tag), + toml::Value::Float(n) => UntaggedValue::decimal(*n).into_value(tag), toml::Value::String(s) => { UntaggedValue::Primitive(Primitive::String(String::from(s))).into_value(tag) } diff --git a/src/commands/from_url.rs b/src/commands/from_url.rs index 91ca18fef9..439d2f00b0 100644 --- a/src/commands/from_url.rs +++ b/src/commands/from_url.rs @@ -1,9 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::value; -use crate::data::TaggedDictBuilder; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature, Value}; +use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value}; pub struct FromURL; @@ -64,7 +62,7 @@ fn from_url(args: CommandArgs, registry: &CommandRegistry) -> Result value::nothing(), - DataType::String(s) => value::string(s), - DataType::Float(f) => value::decimal(*f), - DataType::Int(i) => value::int(*i), - DataType::Bool(b) => value::boolean(*b), - _ => value::nothing(), + DataType::Empty => UntaggedValue::nothing(), + DataType::String(s) => UntaggedValue::string(s), + DataType::Float(f) => UntaggedValue::decimal(*f), + DataType::Int(i) => UntaggedValue::int(*i), + DataType::Bool(b) => UntaggedValue::boolean(*b), + _ => UntaggedValue::nothing(), }; row_output.insert_untagged(&format!("Column{}", i), value); diff --git a/src/commands/from_xml.rs b/src/commands/from_xml.rs index 9d54f25684..83e8edd6bb 100644 --- a/src/commands/from_xml.rs +++ b/src/commands/from_xml.rs @@ -1,8 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::{value, TaggedDictBuilder}; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value}; +use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value}; pub struct FromXML; @@ -61,13 +60,13 @@ fn from_node_to_value<'a, 'd>(n: &roxmltree::Node<'a, 'd>, tag: impl Into) collected.into_value() } else if n.is_comment() { - value::string("").into_value(tag) + UntaggedValue::string("").into_value(tag) } else if n.is_pi() { - value::string("").into_value(tag) + UntaggedValue::string("").into_value(tag) } else if n.is_text() { - value::string(n.text().unwrap()).into_value(tag) + UntaggedValue::string(n.text().unwrap()).into_value(tag) } else { - value::string("").into_value(tag) + UntaggedValue::string("").into_value(tag) } } @@ -138,21 +137,20 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result) -> Value { - value::string(input.into()).into_untagged_value() + UntaggedValue::string(input.into()).into_untagged_value() } fn row(entries: IndexMap) -> Value { - value::row(entries).into_untagged_value() + UntaggedValue::row(entries).into_untagged_value() } fn table(list: &Vec) -> Value { - value::table(list).into_untagged_value() + UntaggedValue::table(list).into_untagged_value() } fn parse(xml: &str) -> Value { diff --git a/src/commands/from_yaml.rs b/src/commands/from_yaml.rs index 2b253c2e5f..915c9fa081 100644 --- a/src/commands/from_yaml.rs +++ b/src/commands/from_yaml.rs @@ -1,8 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::{value, TaggedDictBuilder}; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value}; +use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value}; pub struct FromYAML; @@ -56,14 +55,14 @@ fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, tag: impl Into) -> let tag = tag.into(); 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() => { - 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() => { - 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( a.iter() .map(|x| convert_yaml_value_to_nu_value(x, &tag)) diff --git a/src/commands/group_by.rs b/src/commands/group_by.rs index 71e0d2e2e6..60ad2875ea 100644 --- a/src/commands/group_by.rs +++ b/src/commands/group_by.rs @@ -1,9 +1,8 @@ use crate::commands::WholeStreamCommand; use crate::data::base::property_get::get_data_by_key; -use crate::data::{value, TaggedDictBuilder}; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, Value}; +use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue, Value}; use nu_source::Tagged; pub struct GroupBy; @@ -108,7 +107,7 @@ pub fn group( let mut out = TaggedDictBuilder::new(&tag); for (k, v) in groups.iter() { - out.insert_untagged(k, value::table(v)); + out.insert_untagged(k, UntaggedValue::table(v)); } Ok(out.into_value()) @@ -117,21 +116,20 @@ pub fn group( #[cfg(test)] mod tests { use crate::commands::group_by::group; - use crate::data::value; use indexmap::IndexMap; - use nu_protocol::Value; + use nu_protocol::{UntaggedValue, Value}; use nu_source::*; fn string(input: impl Into) -> Value { - value::string(input.into()).into_untagged_value() + UntaggedValue::string(input.into()).into_untagged_value() } fn row(entries: IndexMap) -> Value { - value::row(entries).into_untagged_value() + UntaggedValue::row(entries).into_untagged_value() } fn table(list: &Vec) -> Value { - value::table(list).into_untagged_value() + UntaggedValue::table(list).into_untagged_value() } fn nu_releases_commiters() -> Vec { diff --git a/src/commands/help.rs b/src/commands/help.rs index cc44442d97..0d438acd27 100644 --- a/src/commands/help.rs +++ b/src/commands/help.rs @@ -1,11 +1,11 @@ use crate::commands::PerItemCommand; 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 nu_errors::ShellError; use nu_protocol::{ CallInfo, NamedType, PositionalType, Primitive, ReturnSuccess, Signature, SyntaxShape, - UntaggedValue, Value, + TaggedDictBuilder, UntaggedValue, Value, }; use nu_source::SpannedItem; @@ -152,7 +152,7 @@ impl PerItemCommand for Help { } 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(); - 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()) } diff --git a/src/commands/histogram.rs b/src/commands/histogram.rs index 38c2fa0c44..da550fbeeb 100644 --- a/src/commands/histogram.rs +++ b/src/commands/histogram.rs @@ -5,10 +5,11 @@ use crate::commands::reduce_by::reduce; use crate::commands::t_sort_by::columns_sorted; use crate::commands::t_sort_by::t_sort; use crate::commands::WholeStreamCommand; -use crate::data::{value, TaggedDictBuilder}; use crate::prelude::*; 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 num_traits::cast::ToPrimitive; @@ -91,11 +92,11 @@ pub fn histogram( let mut fact = TaggedDictBuilder::new(&name); let value: Tagged = 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() { let string = std::iter::repeat("*").take(num.to_i32().unwrap() as usize).collect::(); - fact.insert_untagged(&frequency_column_name, value::string(string)); + fact.insert_untagged(&frequency_column_name, UntaggedValue::string(string)); } idx = idx + 1; @@ -146,9 +147,9 @@ fn percentages(values: &Value, max: Value, tag: impl Into) -> Result value::number(0).into_value(&tag), + _ => UntaggedValue::int(0).into_value(&tag), }) .collect::>(); UntaggedValue::Table(data).into_value(&tag) diff --git a/src/commands/history.rs b/src/commands/history.rs index 11b7896582..c029ac16b8 100644 --- a/src/commands/history.rs +++ b/src/commands/history.rs @@ -1,9 +1,8 @@ use crate::cli::History as HistoryFile; use crate::commands::PerItemCommand; -use crate::data::value; use crate::prelude::*; 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::io::{BufRead, BufReader}; @@ -38,7 +37,7 @@ impl PerItemCommand for History { let reader = BufReader::new(file); for line in reader.lines() { 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 { diff --git a/src/commands/map_max_by.rs b/src/commands/map_max_by.rs index 416d5f56e4..f2aa3650ab 100644 --- a/src/commands/map_max_by.rs +++ b/src/commands/map_max_by.rs @@ -103,9 +103,9 @@ pub fn map_max( } _ => 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(); @@ -122,9 +122,9 @@ pub fn map_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) @@ -144,15 +144,15 @@ mod tests { use nu_source::*; fn int(s: impl Into) -> Value { - value::int(s).into_untagged_value() + UntaggedValue::int(s).into_untagged_value() } fn string(input: impl Into) -> Value { - value::string(input.into()).into_untagged_value() + UntaggedValue::string(input.into()).into_untagged_value() } fn row(entries: IndexMap) -> Value { - value::row(entries).into_untagged_value() + UntaggedValue::row(entries).into_untagged_value() } fn nu_releases_evaluated_by_default_one() -> Value { diff --git a/src/commands/open.rs b/src/commands/open.rs index 63b02355cb..7b504e9ab8 100644 --- a/src/commands/open.rs +++ b/src/commands/open.rs @@ -1,5 +1,4 @@ use crate::commands::UnevaluatedCallInfo; -use crate::data::value; use crate::prelude::*; use nu_errors::ShellError; use nu_protocol::{CallInfo, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value}; @@ -140,7 +139,7 @@ pub async fn fetch( Ok(s) => Ok(( cwd.extension() .map(|name| name.to_string_lossy().to_string()), - value::string(s), + UntaggedValue::string(s), Tag { span, anchor: Some(AnchorLocation::File(cwd.to_string_lossy().to_string())), @@ -158,7 +157,7 @@ pub async fn fetch( Ok(s) => Ok(( cwd.extension() .map(|name| name.to_string_lossy().to_string()), - value::string(s), + UntaggedValue::string(s), Tag { span, anchor: Some(AnchorLocation::File( @@ -168,7 +167,7 @@ pub async fn fetch( )), Err(_) => Ok(( None, - value::binary(bytes), + UntaggedValue::binary(bytes), Tag { span, anchor: Some(AnchorLocation::File( @@ -180,7 +179,7 @@ pub async fn fetch( } else { Ok(( None, - value::binary(bytes), + UntaggedValue::binary(bytes), Tag { span, anchor: Some(AnchorLocation::File( @@ -199,7 +198,7 @@ pub async fn fetch( Ok(s) => Ok(( cwd.extension() .map(|name| name.to_string_lossy().to_string()), - value::string(s), + UntaggedValue::string(s), Tag { span, anchor: Some(AnchorLocation::File( @@ -209,7 +208,7 @@ pub async fn fetch( )), Err(_) => Ok(( None, - value::binary(bytes), + UntaggedValue::binary(bytes), Tag { span, anchor: Some(AnchorLocation::File( @@ -221,7 +220,7 @@ pub async fn fetch( } else { Ok(( None, - value::binary(bytes), + UntaggedValue::binary(bytes), Tag { span, anchor: Some(AnchorLocation::File( @@ -233,7 +232,7 @@ pub async fn fetch( } _ => Ok(( None, - value::binary(bytes), + UntaggedValue::binary(bytes), Tag { span, anchor: Some(AnchorLocation::File( diff --git a/src/commands/pivot.rs b/src/commands/pivot.rs index 586fb71d0e..14373bd4c8 100644 --- a/src/commands/pivot.rs +++ b/src/commands/pivot.rs @@ -1,10 +1,8 @@ use crate::commands::WholeStreamCommand; use crate::data::base::property_get::get_data_by_key; -use crate::data::value; use crate::prelude::*; -use crate::TaggedDictBuilder; 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}; pub struct Pivot; @@ -114,7 +112,7 @@ pub fn pivot(args: PivotArgs, context: RunnableContext) -> Result Result { - dict.insert_untagged(headers[column_num].clone(), value::nothing()); + dict.insert_untagged(headers[column_num].clone(), UntaggedValue::nothing()); } } column_num += 1; diff --git a/src/commands/plugin.rs b/src/commands/plugin.rs index 6c37b321a2..c0051731f8 100644 --- a/src/commands/plugin.rs +++ b/src/commands/plugin.rs @@ -1,5 +1,4 @@ use crate::commands::WholeStreamCommand; -use crate::data::value; use crate::prelude::*; use derive_new::new; use log::trace; @@ -316,7 +315,7 @@ pub fn sink_plugin( // Needed for async_stream to type check if false { - yield ReturnSuccess::value(value::nothing().into_untagged_value()); + yield ReturnSuccess::value(UntaggedValue::nothing().into_untagged_value()); } }; Ok(OutputStream::new(stream)) diff --git a/src/commands/post.rs b/src/commands/post.rs index 63c445b6ee..b76ff76f69 100644 --- a/src/commands/post.rs +++ b/src/commands/post.rs @@ -1,5 +1,4 @@ use crate::commands::UnevaluatedCallInfo; -use crate::data::value; use crate::prelude::*; use base64::encode; use mime::Mime; @@ -320,7 +319,7 @@ pub async fn post( match (content_type.type_(), content_type.subtype()) { (mime::APPLICATION, mime::XML) => Ok(( Some("xml".to_string()), - value::string(r.body_string().await.map_err(|_| { + UntaggedValue::string(r.body_string().await.map_err(|_| { ShellError::labeled_error( "Could not load text from remote url", "could not load", @@ -334,7 +333,7 @@ pub async fn post( )), (mime::APPLICATION, mime::JSON) => Ok(( Some("json".to_string()), - value::string(r.body_string().await.map_err(|_| { + UntaggedValue::string(r.body_string().await.map_err(|_| { ShellError::labeled_error( "Could not load text from remote url", "could not load", @@ -356,7 +355,7 @@ pub async fn post( })?; Ok(( None, - value::binary(buf), + UntaggedValue::binary(buf), Tag { anchor: Some(AnchorLocation::Url(location.to_string())), span: tag.span, @@ -373,7 +372,7 @@ pub async fn post( })?; Ok(( Some(image_ty.to_string()), - value::binary(buf), + UntaggedValue::binary(buf), Tag { anchor: Some(AnchorLocation::Url(location.to_string())), span: tag.span, @@ -382,7 +381,7 @@ pub async fn post( } (mime::TEXT, mime::HTML) => Ok(( Some("html".to_string()), - value::string(r.body_string().await.map_err(|_| { + UntaggedValue::string(r.body_string().await.map_err(|_| { ShellError::labeled_error( "Could not load text from remote url", "could not load", @@ -408,7 +407,7 @@ pub async fn post( Ok(( path_extension, - value::string(r.body_string().await.map_err(|_| { + UntaggedValue::string(r.body_string().await.map_err(|_| { ShellError::labeled_error( "Could not load text from remote url", "could not load", @@ -423,7 +422,7 @@ pub async fn post( } (ty, sub_ty) => Ok(( None, - value::string(format!( + UntaggedValue::string(format!( "Not yet supported MIME type: {} {}", ty, sub_ty )), @@ -436,7 +435,7 @@ pub async fn post( } None => Ok(( None, - value::string(format!("No content type found")), + UntaggedValue::string(format!("No content type found")), Tag { anchor: Some(AnchorLocation::Url(location.to_string())), span: tag.span, diff --git a/src/commands/reduce_by.rs b/src/commands/reduce_by.rs index 3992276e12..81afc3d822 100644 --- a/src/commands/reduce_by.rs +++ b/src/commands/reduce_by.rs @@ -135,9 +135,9 @@ pub fn reduce( } = d { acc = reduce_with(acc, x.clone()); - value::number(acc).into_value(&tag) + UntaggedValue::int(acc).into_value(&tag) } else { - value::number(0).into_value(&tag) + UntaggedValue::int(0).into_value(&tag) } }) .collect::>(); @@ -169,19 +169,19 @@ mod tests { use nu_source::*; fn int(s: impl Into) -> Value { - value::int(s).into_untagged_value() + UntaggedValue::int(s).into_untagged_value() } fn string(input: impl Into) -> Value { - value::string(input.into()).into_untagged_value() + UntaggedValue::string(input.into()).into_untagged_value() } fn row(entries: IndexMap) -> Value { - value::row(entries).into_untagged_value() + UntaggedValue::row(entries).into_untagged_value() } fn table(list: &Vec) -> Value { - value::table(list).into_untagged_value() + UntaggedValue::table(list).into_untagged_value() } fn nu_releases_sorted_by_date() -> Value { diff --git a/src/commands/shells.rs b/src/commands/shells.rs index 7112237f0e..7faf9f6e7e 100644 --- a/src/commands/shells.rs +++ b/src/commands/shells.rs @@ -1,8 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::TaggedDictBuilder; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::Signature; +use nu_protocol::{Signature, TaggedDictBuilder}; use std::sync::atomic::Ordering; pub struct Shells; diff --git a/src/commands/size.rs b/src/commands/size.rs index 4687563b4a..f0eba32016 100644 --- a/src/commands/size.rs +++ b/src/commands/size.rs @@ -1,8 +1,7 @@ use crate::commands::WholeStreamCommand; -use crate::data::{value, TaggedDictBuilder}; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature, Value}; +use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value}; pub struct Size; @@ -79,10 +78,10 @@ fn count(contents: &str, tag: impl Into) -> Value { let mut dict = TaggedDictBuilder::new(tag); //TODO: add back in name when we have it in the tag //dict.insert("name", value::string(name)); - dict.insert_untagged("lines", value::int(lines)); - dict.insert_untagged("words", value::int(words)); - dict.insert_untagged("chars", value::int(chars)); - dict.insert_untagged("max length", value::int(bytes)); + dict.insert_untagged("lines", UntaggedValue::int(lines)); + dict.insert_untagged("words", UntaggedValue::int(words)); + dict.insert_untagged("chars", UntaggedValue::int(chars)); + dict.insert_untagged("max length", UntaggedValue::int(bytes)); dict.into_value() } diff --git a/src/commands/split_by.rs b/src/commands/split_by.rs index 876550db5e..a21246d895 100644 --- a/src/commands/split_by.rs +++ b/src/commands/split_by.rs @@ -1,8 +1,9 @@ use crate::commands::WholeStreamCommand; -use crate::data::TaggedDictBuilder; use crate::prelude::*; 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; pub struct SplitBy; @@ -104,7 +105,7 @@ pub fn split( .or_insert(indexmap::IndexMap::new()); s.insert( group_key.clone(), - value::table(&subset).into_value(tag), + UntaggedValue::table(&subset).into_value(tag), ); } other => { @@ -144,7 +145,7 @@ pub fn split( let mut out = TaggedDictBuilder::new(&origin_tag); 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()) @@ -154,21 +155,20 @@ mod tests { use crate::commands::group_by::group; use crate::commands::split_by::split; - use crate::data::value; use indexmap::IndexMap; - use nu_protocol::Value; + use nu_protocol::{UntaggedValue, Value}; use nu_source::*; fn string(input: impl Into) -> Value { - value::string(input.into()).into_untagged_value() + UntaggedValue::string(input.into()).into_untagged_value() } fn row(entries: IndexMap) -> Value { - value::row(entries).into_untagged_value() + UntaggedValue::row(entries).into_untagged_value() } fn table(list: &Vec) -> Value { - value::table(list).into_untagged_value() + UntaggedValue::table(list).into_untagged_value() } fn nu_releases_grouped_by_date() -> Value { @@ -214,7 +214,7 @@ mod tests { assert_eq!( split(&for_key, &nu_releases_grouped_by_date(), Tag::unknown()).unwrap(), - value::row(indexmap! { + UntaggedValue::row(indexmap! { "EC".into() => row(indexmap! { "August 23-2019".into() => table(&vec![ 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")}) ]), "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![ row(indexmap!{"name".into() => string("YK"), "country".into() => string("US"), "date".into() => string("October 10-2019")}) diff --git a/src/commands/split_column.rs b/src/commands/split_column.rs index f856c109c0..1773dc937e 100644 --- a/src/commands/split_column.rs +++ b/src/commands/split_column.rs @@ -1,9 +1,10 @@ use crate::commands::WholeStreamCommand; -use crate::data::TaggedDictBuilder; use crate::prelude::*; use log::trace; 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; #[derive(Deserialize)] diff --git a/src/commands/t_sort_by.rs b/src/commands/t_sort_by.rs index 70bd635475..99b780d143 100644 --- a/src/commands/t_sort_by.rs +++ b/src/commands/t_sort_by.rs @@ -1,10 +1,12 @@ use crate::commands::WholeStreamCommand; use crate::data::base::property_get::get_data_by_key; -use crate::data::{value, TaggedDictBuilder, TaggedListBuilder}; +use crate::data::TaggedListBuilder; use crate::prelude::*; use chrono::{DateTime, NaiveDate, Utc}; 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; pub struct TSortBy; @@ -70,7 +72,7 @@ fn t_sort_by( if show_columns { 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 { 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( DateTime::::from_utc(parsed.and_hms(12, 34, 56), Utc), )), - Err(_) => value::string(k), + Err(_) => UntaggedValue::string(k), }; date.into_untagged_value() @@ -197,10 +199,10 @@ pub fn t_sort( 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)] @@ -214,15 +216,15 @@ mod tests { use nu_source::*; fn string(input: impl Into) -> Value { - value::string(input.into()).into_untagged_value() + UntaggedValue::string(input.into()).into_untagged_value() } fn row(entries: IndexMap) -> Value { - value::row(entries).into_untagged_value() + UntaggedValue::row(entries).into_untagged_value() } fn table(list: &Vec) -> Value { - value::table(list).into_untagged_value() + UntaggedValue::table(list).into_untagged_value() } fn nu_releases_grouped_by_date() -> Value { diff --git a/src/commands/table.rs b/src/commands/table.rs index 4fce36e437..22f9082529 100644 --- a/src/commands/table.rs +++ b/src/commands/table.rs @@ -1,5 +1,4 @@ use crate::commands::WholeStreamCommand; -use crate::data::value; use crate::format::TableView; use crate::prelude::*; use nu_errors::ShellError; @@ -58,7 +57,7 @@ fn table(args: CommandArgs, registry: &CommandRegistry) -> Result Result { - tags.insert_untagged("anchor", value::string(source)); + tags.insert_untagged("anchor", UntaggedValue::string(source)); } Some(AnchorLocation::Url(source)) => { - tags.insert_untagged("anchor", value::string(source)); + tags.insert_untagged("anchor", UntaggedValue::string(source)); } _ => {} } diff --git a/src/commands/to_bson.rs b/src/commands/to_bson.rs index 8a21c796b3..a21c96a98b 100644 --- a/src/commands/to_bson.rs +++ b/src/commands/to_bson.rs @@ -1,5 +1,4 @@ use crate::commands::WholeStreamCommand; -use crate::data::value; use crate::prelude::*; use bson::{encode_document, oid::ObjectId, spec::BinarySubtype, Bson, Document}; use nu_errors::{CoerceInto, ShellError}; @@ -274,7 +273,7 @@ fn to_bson(args: CommandArgs, registry: &CommandRegistry) -> Result yield ReturnSuccess::value( - value::binary(x).into_value(&name_tag), + UntaggedValue::binary(x).into_value(&name_tag), ), _ => yield Err(ShellError::labeled_error_with_secondary( "Expected a table with BSON-compatible structure.tag() from pipeline", diff --git a/src/commands/to_sqlite.rs b/src/commands/to_sqlite.rs index 3a6a37012c..3b4d84dbb6 100644 --- a/src/commands/to_sqlite.rs +++ b/src/commands/to_sqlite.rs @@ -197,7 +197,7 @@ fn sqlite_input_stream_to_bytes(values: Vec) -> Result Result { diff --git a/src/commands/to_url.rs b/src/commands/to_url.rs index 71f5db1554..65ff01aa12 100644 --- a/src/commands/to_url.rs +++ b/src/commands/to_url.rs @@ -1,5 +1,4 @@ use crate::commands::WholeStreamCommand; -use crate::data::value; use crate::prelude::*; use nu_errors::ShellError; use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value}; @@ -59,7 +58,7 @@ fn to_url(args: CommandArgs, registry: &CommandRegistry) -> Result { - yield ReturnSuccess::value(value::string(s).into_value(&tag)); + yield ReturnSuccess::value(UntaggedValue::string(s).into_value(&tag)); } _ => { yield Err(ShellError::labeled_error( diff --git a/src/commands/trim.rs b/src/commands/trim.rs index 3119fe511d..67cf0f98ab 100644 --- a/src/commands/trim.rs +++ b/src/commands/trim.rs @@ -2,7 +2,7 @@ use crate::commands::WholeStreamCommand; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::{ReturnSuccess, Signature}; +use nu_protocol::{ReturnSuccess, Signature, UntaggedValue}; pub struct Trim; @@ -35,7 +35,7 @@ fn trim(args: CommandArgs, _registry: &CommandRegistry) -> Result Result Result { 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; @@ -99,7 +99,7 @@ pub(crate) fn select_fields(obj: &Value, fields: &[String], tag: impl Into) for field in fields { 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()), } } @@ -196,28 +196,27 @@ fn coerce_compare_primitive( } #[cfg(test)] mod tests { - use super::value; use crate::data::base::property_get::{as_column_path, ValueExt}; use indexmap::IndexMap; 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 num_bigint::BigInt; fn string(input: impl Into) -> Value { - value::string(input.into()).into_untagged_value() + UntaggedValue::string(input.into()).into_untagged_value() } fn int(input: impl Into) -> Value { - value::int(input.into()).into_untagged_value() + UntaggedValue::int(input.into()).into_untagged_value() } fn row(entries: IndexMap) -> Value { - value::row(entries).into_untagged_value() + UntaggedValue::row(entries).into_untagged_value() } fn table(list: &Vec) -> Value { - value::table(list).into_untagged_value() + UntaggedValue::table(list).into_untagged_value() } fn error_callback( @@ -232,7 +231,7 @@ mod tests { #[test] 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")]) }) .into_untagged_value(); @@ -253,7 +252,7 @@ mod tests { let (version, tag) = string("0.4.0").into_parts(); - let value = value::row(indexmap! { + let value = UntaggedValue::row(indexmap! { "package".into() => row(indexmap! { "name".into() => string("nu"), @@ -276,7 +275,7 @@ mod tests { let (_, tag) = string("Andrés N. Robalino").into_parts(); - let value = value::row(indexmap! { + let value = UntaggedValue::row(indexmap! { "package".into() => row(indexmap! { "name".into() => string("nu"), "version".into() => string("0.4.0"), @@ -310,7 +309,7 @@ mod tests { let (_, tag) = string("Andrés N. Robalino").into_parts(); - let value = value::row(indexmap! { + let value = UntaggedValue::row(indexmap! { "package".into() => row(indexmap! { "name".into() => string("nu"), "version".into() => string("0.4.0"), @@ -327,7 +326,7 @@ mod tests { .into_value(tag) .get_data_by_column_path(&field_path, Box::new(error_callback("package.authors.0"))) .unwrap(), - value::row(indexmap! { + UntaggedValue::row(indexmap! { "name".into() => string("Andrés N. Robalino") }) ); @@ -339,7 +338,7 @@ mod tests { let (_, tag) = string("Andrés N. Robalino").into_parts(); - let value = value::row(indexmap! { + let value = UntaggedValue::row(indexmap! { "package".into() => row(indexmap! { "name".into() => string("nu"), "version".into() => string("0.4.0"), @@ -359,7 +358,7 @@ mod tests { Box::new(error_callback("package.authors.\"0\"")) ) .unwrap(), - value::row(indexmap! { + UntaggedValue::row(indexmap! { "name".into() => string("Andrés N. Robalino") }) ); @@ -369,7 +368,7 @@ mod tests { fn replaces_matching_field_from_a_row() { let field_path = column_path(&vec![string("amigos")]); - let sample = value::row(indexmap! { + let sample = UntaggedValue::row(indexmap! { "amigos".into() => table(&vec![ string("andres"), string("jonathan"), @@ -395,7 +394,7 @@ mod tests { string("los.3.caballeros"), ]); - let sample = value::row(indexmap! { + let sample = UntaggedValue::row(indexmap! { "package".into() => row(indexmap! { "authors".into() => row(indexmap! { "los.3.mosqueteros".into() => table(&vec![string("andres::yehuda::jonathan")]), @@ -415,7 +414,7 @@ mod tests { assert_eq!( actual, - value::row(indexmap! { + UntaggedValue::row(indexmap! { "package".into() => row(indexmap! { "authors".into() => row(indexmap! { "los.3.mosqueteros".into() => table(&vec![string("andres::yehuda::jonathan")]), @@ -432,7 +431,7 @@ mod tests { string("nu.version.arepa"), ]); - let sample = value::row(indexmap! { + let sample = UntaggedValue::row(indexmap! { "shell_policy".into() => row(indexmap! { "releases".into() => table(&vec![ row(indexmap! { @@ -467,7 +466,7 @@ mod tests { assert_eq!( actual, - value::row(indexmap! { + UntaggedValue::row(indexmap! { "shell_policy".into() => row(indexmap! { "releases".into() => table(&vec![ row(indexmap! { diff --git a/src/data/base/property_get.rs b/src/data/base/property_get.rs index b447524802..13b3733fad 100644 --- a/src/data/base/property_get.rs +++ b/src/data/base/property_get.rs @@ -1,4 +1,3 @@ -use crate::data::value; use crate::prelude::*; use nu_errors::{ExpectedRange, ShellError}; 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::Row(o) => o.get_data(desc), 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 match o.get_data_by_key(name) { 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()), } } diff --git a/src/data/base/shape.rs b/src/data/base/shape.rs index 324c1df37b..4683202ea6 100644 --- a/src/data/base/shape.rs +++ b/src/data/base/shape.rs @@ -6,7 +6,8 @@ use derive_new::new; use indexmap::IndexMap; use nu_errors::ShellError; 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 std::collections::BTreeMap; @@ -535,7 +536,7 @@ impl Shape { .expect("Writing into a Vec can't fail"); 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 { let shape = self.shapes.keys().nth(0).unwrap(); - vec![dict! { - "type" => shape.to_value(), - "rows" => value::string("all") - }] + let mut tagged_dict = TaggedDictBuilder::new(Tag::unknown()); + tagged_dict.insert_untagged("type", shape.to_value()); + tagged_dict.insert_untagged("rows", UntaggedValue::string("all")); + vec![tagged_dict.into_value()] } else { self.shapes .iter() .map(|(shape, rows)| { let rows = rows.iter().map(|i| i.to_string()).join(", "); - dict! { - "type" => shape.to_value(), - "rows" => value::string(format!("[ {} ]", rows)) - } + let mut tagged_dict = TaggedDictBuilder::new(Tag::unknown()); + tagged_dict.insert_untagged("type", shape.to_value()); + tagged_dict + .insert_untagged("rows", UntaggedValue::string(format!("[ {} ]", rows))); + + tagged_dict.into_value() }) .collect() } diff --git a/src/data/command.rs b/src/data/command.rs index 3eb504a422..003af27e5b 100644 --- a/src/data/command.rs +++ b/src/data/command.rs @@ -1,7 +1,7 @@ use crate::commands::command::Command; -use crate::data::{TaggedDictBuilder, TaggedListBuilder}; +use crate::data::TaggedListBuilder; use crate::prelude::*; -use nu_protocol::{NamedType, PositionalType, Signature, Value}; +use nu_protocol::{NamedType, PositionalType, Signature, TaggedDictBuilder, UntaggedValue, Value}; use std::ops::Deref; pub(crate) fn command_dict(command: Arc, tag: impl Into) -> Value { @@ -9,18 +9,18 @@ pub(crate) fn command_dict(command: Arc, tag: impl Into) -> Value 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( "type", - value::string(match command.deref() { + UntaggedValue::string(match command.deref() { Command::WholeStream(_) => "Command", Command::PerItem(_) => "Filter", }), ); 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() } @@ -30,11 +30,11 @@ fn for_spec(name: &str, ty: &str, required: bool, tag: impl Into) -> Value let mut spec = TaggedDictBuilder::new(tag); - spec.insert_untagged("name", value::string(name)); - spec.insert_untagged("type", value::string(ty)); + spec.insert_untagged("name", UntaggedValue::string(name)); + spec.insert_untagged("type", UntaggedValue::string(ty)); spec.insert_untagged( "required", - value::string(if required { "yes" } else { "no" }), + UntaggedValue::string(if required { "yes" } else { "no" }), ); spec.into_value() diff --git a/src/data/dict.rs b/src/data/dict.rs index bbdcf5bd19..afdff355a1 100644 --- a/src/data/dict.rs +++ b/src/data/dict.rs @@ -1,6 +1,5 @@ use crate::prelude::*; use derive_new::new; -use indexmap::IndexMap; use nu_protocol::{Dictionary, Primitive, UntaggedValue, Value}; use nu_source::{b, PrettyDebug, Spanned}; @@ -106,59 +105,3 @@ impl From for Value { input.into_value() } } - -#[derive(Debug)] -pub struct TaggedDictBuilder { - tag: Tag, - dict: IndexMap, -} - -impl TaggedDictBuilder { - pub fn new(tag: impl Into) -> TaggedDictBuilder { - TaggedDictBuilder { - tag: tag.into(), - dict: IndexMap::default(), - } - } - - pub fn build(tag: impl Into, 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, n: usize) -> TaggedDictBuilder { - TaggedDictBuilder { - tag: tag.into(), - dict: IndexMap::with_capacity(n), - } - } - - pub fn insert_untagged(&mut self, key: impl Into, value: impl Into) { - self.dict - .insert(key.into(), value.into().into_value(&self.tag)); - } - - pub fn insert_value(&mut self, key: impl Into, value: impl Into) { - 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 for Value { - fn from(input: TaggedDictBuilder) -> Value { - input.into_value() - } -} diff --git a/src/data/files.rs b/src/data/files.rs index aec410e0e5..4da698dfa2 100644 --- a/src/data/files.rs +++ b/src/data/files.rs @@ -1,7 +1,6 @@ -use crate::data::TaggedDictBuilder; use crate::prelude::*; use nu_errors::ShellError; -use nu_protocol::Value; +use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value}; #[derive(Debug)] pub enum FileType { @@ -17,7 +16,7 @@ pub(crate) fn dir_entry_dict( full: bool, ) -> Result { 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() { FileType::Directory @@ -27,36 +26,39 @@ pub(crate) fn dir_entry_dict( FileType::Symlink }; - dict.insert_untagged("type", value::string(format!("{:?}", kind))); + dict.insert_untagged("type", UntaggedValue::string(format!("{:?}", kind))); if full { dict.insert_untagged( "readonly", - value::boolean(metadata.permissions().readonly()), + UntaggedValue::boolean(metadata.permissions().readonly()), ); #[cfg(unix)] { use std::os::unix::fs::PermissionsExt; 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() { - Ok(c) => dict.insert_untagged("created", value::system_date(c)), + Ok(c) => dict.insert_untagged("created", UntaggedValue::system_date(c)), Err(_) => {} } match metadata.accessed() { - Ok(a) => dict.insert_untagged("accessed", value::system_date(a)), + Ok(a) => dict.insert_untagged("accessed", UntaggedValue::system_date(a)), Err(_) => {} } match metadata.modified() { - Ok(m) => dict.insert_untagged("modified", value::system_date(m)), + Ok(m) => dict.insert_untagged("modified", UntaggedValue::system_date(m)), Err(_) => {} } diff --git a/src/data/value.rs b/src/data/value.rs index 27670e7af9..5742674064 100644 --- a/src/data/value.rs +++ b/src/data/value.rs @@ -1,86 +1,11 @@ use crate::data::base::coerce_compare; use crate::data::base::shape::{Column, InlineShape, TypeShape}; use crate::data::primitive::style_primitive; -use crate::data::value; -use bigdecimal::BigDecimal; use chrono::DateTime; -use indexmap::IndexMap; use nu_errors::ShellError; -use nu_parser::Number; use nu_parser::Operator; -use nu_protocol::{ColumnPath, PathMember, Primitive, UntaggedValue, Value}; +use nu_protocol::{Primitive, UntaggedValue}; 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) -> UntaggedValue { - UntaggedValue::Row(entries.into()) -} - -pub fn table(list: &Vec) -> UntaggedValue { - UntaggedValue::Table(list.to_vec()) -} - -pub fn string(s: impl Into) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::String(s.into())) -} - -pub fn line(s: impl Into) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::Line(s.into())) -} - -pub fn column_path(s: Vec>) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::new( - s.into_iter().map(|p| p.into()).collect(), - ))) -} - -pub fn int(i: impl Into) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::Int(i.into())) -} - -pub fn pattern(s: impl Into) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::String(s.into())) -} - -pub fn path(s: impl Into) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::Path(s.into())) -} - -pub fn bytes(s: impl Into) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::Bytes(s.into())) -} - -pub fn decimal(s: impl Into) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::Decimal(s.into())) -} - -pub fn binary(binary: Vec) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::Binary(binary)) -} - -pub fn number(s: impl Into) -> 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) -> 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 { let date = DateTime::parse_from_rfc3339(s.item).map_err(|err| { @@ -96,10 +21,6 @@ pub fn date_from_str(s: Tagged<&str>) -> Result { Ok(UntaggedValue::Primitive(Primitive::Date(date))) } -pub fn nothing() -> UntaggedValue { - UntaggedValue::Primitive(Primitive::Nothing) -} - pub fn compare_values( operator: &Operator, left: &UntaggedValue, diff --git a/src/deserializer.rs b/src/deserializer.rs index 12db815e12..5f366d68cb 100644 --- a/src/deserializer.rs +++ b/src/deserializer.rs @@ -1,5 +1,4 @@ use crate::data::base::property_get::ValueExt; -use crate::data::value; use log::trace; use nu_errors::{CoerceInto, ShellError}; use nu_protocol::{CallInfo, ColumnPath, Evaluate, Primitive, ShellTypeName, UntaggedValue, Value}; @@ -56,7 +55,7 @@ impl<'de> ConfigDeserializer<'de> { self.stack.push(DeserializerItem { 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(()) diff --git a/src/evaluate/evaluate_args.rs b/src/evaluate/evaluate_args.rs index 0ba59d5bd0..9fbeb4acb4 100644 --- a/src/evaluate/evaluate_args.rs +++ b/src/evaluate/evaluate_args.rs @@ -1,11 +1,10 @@ // TODO: Temporary redirect use crate::context::CommandRegistry; -use crate::data::value; use crate::evaluate::evaluate_baseline_expr; use indexmap::IndexMap; use nu_errors::ShellError; use nu_parser::hir; -use nu_protocol::{EvaluatedArgs, Scope, Value}; +use nu_protocol::{EvaluatedArgs, Scope, UntaggedValue, Value}; use nu_source::Text; pub(crate) fn evaluate_args( @@ -35,7 +34,7 @@ pub(crate) fn evaluate_args( for (name, value) in n.named.iter() { match value { 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) => { results.insert( diff --git a/src/evaluate/evaluator.rs b/src/evaluate/evaluator.rs index 4a3d3a1ccb..730a9a350a 100644 --- a/src/evaluate/evaluator.rs +++ b/src/evaluate/evaluator.rs @@ -1,14 +1,13 @@ use crate::context::CommandRegistry; use crate::data::base::Block; -use crate::data::value; use crate::evaluate::operator::apply_operator; use crate::prelude::*; -use crate::TaggedDictBuilder; use log::trace; use nu_errors::{ArgumentError, ShellError}; use nu_parser::hir::{self, Expression, RawExpression}; use nu_protocol::{ - ColumnPath, Evaluate, Primitive, Scope, UnspannedPathMember, UntaggedValue, Value, + ColumnPath, Evaluate, Primitive, Scope, TaggedDictBuilder, UnspannedPathMember, UntaggedValue, + Value, }; use nu_source::Text; @@ -28,9 +27,9 @@ pub(crate) fn evaluate_baseline_expr( "Invalid external word".spanned(tag.span), 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)) => { - Ok(value::string(s).into_untagged_value()) + Ok(UntaggedValue::string(s).into_untagged_value()) } RawExpression::Variable(var) => evaluate_reference(var, scope, source, tag), 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))) .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::String(tag) => value::string(tag.slice(source)).into_value(literal.span), - hir::RawLiteral::GlobPattern(pattern) => value::pattern(pattern).into_value(literal.span), - hir::RawLiteral::Bare => value::string(literal.span.slice(source)).into_value(literal.span), + hir::RawLiteral::String(tag) => { + UntaggedValue::string(tag.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); for v in std::env::vars() { 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()) } x if x == "nu:config" => { 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" => { let mut table = vec![]; match std::env::var_os("PATH") { Some(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 .vars .get(x) .map(|v| v.clone()) - .unwrap_or_else(|| value::nothing().into_value(tag))), + .unwrap_or_else(|| UntaggedValue::nothing().into_value(tag))), }, } } diff --git a/src/evaluate/operator.rs b/src/evaluate/operator.rs index 2d55bc15ba..8880630bcc 100644 --- a/src/evaluate/operator.rs +++ b/src/evaluate/operator.rs @@ -15,11 +15,13 @@ pub fn apply_operator( | Operator::GreaterThan | Operator::LessThanOrEqual | 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::Contains => contains(left, right).map(value::boolean), - Operator::NotContains => contains(left, right).map(Not::not).map(value::boolean), + Operator::Dot => Ok(UntaggedValue::boolean(false)), + Operator::Contains => contains(left, right).map(UntaggedValue::boolean), + Operator::NotContains => contains(left, right) + .map(Not::not) + .map(UntaggedValue::boolean), } } diff --git a/src/format/generic.rs b/src/format/generic.rs index f0860c7933..fdf3f203b0 100644 --- a/src/format/generic.rs +++ b/src/format/generic.rs @@ -35,7 +35,7 @@ impl RenderView for GenericView<'_> { b @ UntaggedValue::Block(_) => { 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)?; Ok(()) } diff --git a/src/format/table.rs b/src/format/table.rs index 7bb496bd77..2d35838225 100644 --- a/src/format/table.rs +++ b/src/format/table.rs @@ -68,8 +68,8 @@ impl TableView { value: UntaggedValue::Row(..), .. } => ( - format_leaf(&value::nothing()).plain_string(100000), - style_leaf(&value::nothing()), + format_leaf(&UntaggedValue::nothing()).plain_string(100000), + style_leaf(&UntaggedValue::nothing()), ), _ => (format_leaf(value).plain_string(100000), style_leaf(value)), } @@ -86,8 +86,8 @@ impl TableView { ) } _ => ( - format_leaf(&value::nothing()).plain_string(100000), - style_leaf(&value::nothing()), + format_leaf(&UntaggedValue::nothing()).plain_string(100000), + style_leaf(&UntaggedValue::nothing()), ), } } diff --git a/src/lib.rs b/src/lib.rs index 6f86ad8b84..9d24f24106 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,7 @@ mod utils; pub use crate::cli::cli; pub use crate::data::base::property_get::ValueExt; 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::value; pub use crate::env::host::BasicHost; @@ -32,4 +32,4 @@ pub use nu_parser::TokenTreeBuilder; pub use num_traits::cast::ToPrimitive; // TODO: Temporary redirect -pub use nu_protocol::{serve_plugin, Plugin}; +pub use nu_protocol::{serve_plugin, Plugin, TaggedDictBuilder}; diff --git a/src/plugins/average.rs b/src/plugins/average.rs index 560aa6562c..3ed18d971a 100644 --- a/src/plugins/average.rs +++ b/src/plugins/average.rs @@ -1,4 +1,4 @@ -use nu::{serve_plugin, value, Plugin}; +use nu::{serve_plugin, Plugin}; use nu_errors::{CoerceInto, ShellError}; use nu_protocol::{ CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, UntaggedValue, Value, @@ -27,7 +27,7 @@ impl Average { value: UntaggedValue::Primitive(Primitive::Int(j)), tag, }) => { - self.total = Some(value::int(i + j).into_value(tag)); + self.total = Some(UntaggedValue::int(i + j).into_value(tag)); self.count += 1; Ok(()) } @@ -47,7 +47,7 @@ impl Average { value: UntaggedValue::Primitive(Primitive::Bytes(j)), tag, }) => { - self.total = Some(value::bytes(b + j).into_value(tag)); + self.total = Some(UntaggedValue::bytes(b + j).into_value(tag)); self.count += 1; Ok(()) } diff --git a/src/plugins/embed.rs b/src/plugins/embed.rs index 0fd177a096..2c53385bec 100644 --- a/src/plugins/embed.rs +++ b/src/plugins/embed.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate indexmap; -use nu::{serve_plugin, value, Plugin}; +use nu::{serve_plugin, Plugin}; use nu_errors::ShellError; use nu_protocol::{ CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, SpannedTypeName, SyntaxShape, @@ -35,7 +35,7 @@ impl Embed { self.are_all_rows = false; self.values.push( - value::row(indexmap! { + UntaggedValue::row(indexmap! { match &self.field { Some(key) => key.clone(), None => "Column".into() @@ -81,11 +81,11 @@ impl Plugin for Embed { fn end_filter(&mut self) -> Result, ShellError> { if self.are_all_rows { - let row = value::row(indexmap! { + let row = UntaggedValue::row(indexmap! { match &self.field { Some(key) => key.clone(), None => "Column".into(), - } => value::table(&self.values).into_value(Tag::unknown()), + } => UntaggedValue::table(&self.values).into_value(Tag::unknown()), }) .into_untagged_value(); diff --git a/src/plugins/format.rs b/src/plugins/format.rs index d6b352c762..9745140336 100644 --- a/src/plugins/format.rs +++ b/src/plugins/format.rs @@ -1,4 +1,4 @@ -use nu::{serve_plugin, value, Plugin}; +use nu::{serve_plugin, Plugin}; use nu_errors::ShellError; use nu_protocol::{ CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, SyntaxShape, UntaggedValue, Value, @@ -115,7 +115,7 @@ impl Plugin for Format { } return Ok(vec![ReturnSuccess::value( - value::string(output).into_untagged_value(), + UntaggedValue::string(output).into_untagged_value(), )]); } _ => {} diff --git a/src/plugins/inc.rs b/src/plugins/inc.rs index 08887cfee5..da143e01e8 100644 --- a/src/plugins/inc.rs +++ b/src/plugins/inc.rs @@ -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_protocol::{ CallInfo, ColumnPath, Primitive, ReturnSuccess, ReturnValue, ShellTypeName, Signature, @@ -37,7 +37,7 @@ impl Inc { Some(Action::SemVerAction(act_on)) => { let mut ver = match semver::Version::parse(&input) { Ok(parsed_ver) => parsed_ver, - Err(_) => return Ok(value::string(input.to_string())), + Err(_) => return Ok(UntaggedValue::string(input.to_string())), }; match act_on { @@ -46,11 +46,11 @@ impl Inc { SemVerAction::Patch => ver.increment_patch(), } - value::string(ver.to_string()) + UntaggedValue::string(ver.to_string()) } Some(Action::Default) | None => match input.parse::() { - Ok(v) => value::string(format!("{}", v + 1)), - Err(_) => value::string(input), + Ok(v) => UntaggedValue::string(format!("{}", v + 1)), + Err(_) => UntaggedValue::string(input), }, }; @@ -80,10 +80,10 @@ impl Inc { fn inc(&self, value: Value) -> Result { match &value.value { 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)) => { - 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)) => { Ok(self.apply(&s)?.into_value(value.tag())) @@ -226,7 +226,7 @@ mod tests { use super::{Inc, SemVerAction}; use indexmap::IndexMap; - use nu::{value, Plugin, TaggedDictBuilder}; + use nu::{Plugin, TaggedDictBuilder}; use nu_protocol::{ CallInfo, EvaluatedArgs, PathMember, ReturnSuccess, UnspannedPathMember, UntaggedValue, Value, @@ -249,7 +249,7 @@ mod tests { fn with_long_flag(&mut self, name: &str) -> &mut Self { self.flags.insert( name.to_string(), - value::boolean(true).into_value(Tag::unknown()), + UntaggedValue::boolean(true).into_value(Tag::unknown()), ); self } @@ -263,7 +263,7 @@ mod tests { .collect(); self.positionals - .push(value::column_path(fields).into_untagged_value()); + .push(UntaggedValue::column_path(fields).into_untagged_value()); self } @@ -277,7 +277,7 @@ mod tests { fn cargo_sample_record(with_version: &str) -> Value { 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() } @@ -360,21 +360,21 @@ mod tests { fn incs_major() { let mut inc = Inc::new(); 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] fn incs_minor() { let mut inc = Inc::new(); 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] fn incs_patch() { let mut inc = Inc::new(); 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] @@ -399,7 +399,7 @@ mod tests { .. }) => assert_eq!( *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!( *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!( *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() ), _ => {} } diff --git a/src/plugins/parse.rs b/src/plugins/parse.rs index 5dc9e34439..400a7e8c79 100644 --- a/src/plugins/parse.rs +++ b/src/plugins/parse.rs @@ -1,4 +1,4 @@ -use nu::{serve_plugin, value, Plugin, TaggedDictBuilder}; +use nu::{serve_plugin, Plugin, TaggedDictBuilder}; use nu_errors::ShellError; use nu_protocol::{ CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, SyntaxShape, UntaggedValue, Value, @@ -134,7 +134,10 @@ impl Plugin for Parse { let mut dict = TaggedDictBuilder::new(input.tag()); 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())); diff --git a/src/plugins/str.rs b/src/plugins/str.rs index 566e9b9e44..5ac7486182 100644 --- a/src/plugins/str.rs +++ b/src/plugins/str.rs @@ -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_protocol::{ CallInfo, ColumnPath, Primitive, ReturnSuccess, ReturnValue, ShellTypeName, Signature, @@ -41,15 +41,15 @@ impl Str { fn apply(&self, input: &str) -> Result { let applied = match self.action.as_ref() { - Some(Action::Downcase) => value::string(input.to_ascii_lowercase()), - Some(Action::Upcase) => value::string(input.to_ascii_uppercase()), + Some(Action::Downcase) => UntaggedValue::string(input.to_ascii_lowercase()), + Some(Action::Upcase) => UntaggedValue::string(input.to_ascii_uppercase()), Some(Action::Substring(s, e)) => { let end: usize = cmp::min(*e, input.len()); let start: usize = *s; if start > input.len() - 1 { - value::string("") + UntaggedValue::string("") } else { - value::string( + UntaggedValue::string( &input .chars() .skip(start) @@ -59,23 +59,25 @@ impl Str { } } 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) => { let regex = Regex::new(find.as_str()); match regex { - Ok(re) => value::string(re.replace(input, replacement.as_str()).to_owned()), - Err(_) => value::string(input), + Ok(re) => UntaggedValue::string( + re.replace(input, replacement.as_str()).to_owned(), + ), + Err(_) => UntaggedValue::string(input), } } }, Some(Action::ToInteger) => match input.trim() { other => match other.parse::() { - Ok(v) => value::int(v), - Err(_) => value::string(input), + Ok(v) => UntaggedValue::int(v), + Err(_) => UntaggedValue::string(input), }, }, - None => value::string(input), + None => UntaggedValue::string(input), }; Ok(applied) @@ -315,17 +317,17 @@ fn main() { mod tests { use super::{Action, ReplaceAction, Str}; 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_source::Tag; use num_bigint::BigInt; fn string(input: impl Into) -> Value { - value::string(input.into()).into_untagged_value() + UntaggedValue::string(input.into()).into_untagged_value() } fn table(list: &Vec) -> Value { - value::table(list).into_untagged_value() + UntaggedValue::table(list).into_untagged_value() } fn column_path(paths: &Vec) -> Value { @@ -358,7 +360,7 @@ mod tests { fn with_long_flag(&mut self, name: &str) -> &mut Self { self.flags.insert( name.to_string(), - value::boolean(true).into_value(Tag::unknown()), + UntaggedValue::boolean(true).into_value(Tag::unknown()), ); self } @@ -366,7 +368,7 @@ mod tests { fn with_parameter(&mut self, name: &str) -> &mut Self { let fields: Vec = name .split(".") - .map(|s| value::string(s.to_string()).into_value(Tag::unknown())) + .map(|s| UntaggedValue::string(s.to_string()).into_value(Tag::unknown())) .collect(); self.positionals.push(column_path(&fields)); @@ -383,12 +385,12 @@ mod tests { fn structured_sample_record(key: &str, value: &str) -> Value { 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() } fn unstructured_sample_record(value: &str) -> Value { - value::string(value).into_value(Tag::unknown()) + UntaggedValue::string(value).into_value(Tag::unknown()) } #[test] @@ -530,21 +532,30 @@ mod tests { fn str_downcases() { let mut strutils = Str::new(); strutils.for_downcase(); - assert_eq!(strutils.apply("ANDRES").unwrap(), value::string("andres")); + assert_eq!( + strutils.apply("ANDRES").unwrap(), + UntaggedValue::string("andres") + ); } #[test] fn str_upcases() { let mut strutils = Str::new(); strutils.for_upcase(); - assert_eq!(strutils.apply("andres").unwrap(), value::string("ANDRES")); + assert_eq!( + strutils.apply("andres").unwrap(), + UntaggedValue::string("ANDRES") + ); } #[test] fn str_to_int() { let mut strutils = Str::new(); 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] @@ -552,7 +563,10 @@ mod tests { let mut strutils = Str::new(); 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] @@ -564,7 +578,7 @@ mod tests { )); assert_eq!( strutils.apply("wykittens").unwrap(), - value::string("wyjotandrehuda") + UntaggedValue::string("wyjotandrehuda") ); } @@ -590,7 +604,7 @@ mod tests { .. }) => assert_eq!( *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!( *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!( *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!( *o.get_data(&String::from("rustconf")).borrow(), Value { - value: value::string(String::from("22nd August 2019")), + value: UntaggedValue::string(String::from("22nd August 2019")), tag: Tag::unknown() } ), @@ -930,7 +944,7 @@ mod tests { }) => assert_eq!( *o.get_data(&String::from("staff")).borrow(), Value { - value: value::string(String::from("wyjotandrehuda")), + value: UntaggedValue::string(String::from("wyjotandrehuda")), tag: Tag::unknown() } ), diff --git a/src/plugins/sum.rs b/src/plugins/sum.rs index 32e9dff2e5..c46f42b465 100644 --- a/src/plugins/sum.rs +++ b/src/plugins/sum.rs @@ -1,4 +1,4 @@ -use nu::{serve_plugin, value, Plugin}; +use nu::{serve_plugin, Plugin}; use nu_errors::ShellError; use nu_protocol::{ CallInfo, Primitive, ReturnSuccess, ReturnValue, Signature, UntaggedValue, Value, @@ -22,7 +22,7 @@ impl Sum { tag, }) => { //TODO: handle overflow - self.total = Some(value::int(i + j).into_value(tag)); + self.total = Some(UntaggedValue::int(i + j).into_value(tag)); Ok(()) } None => { @@ -43,7 +43,7 @@ impl Sum { tag, }) => { //TODO: handle overflow - self.total = Some(value::bytes(b + j).into_value(tag)); + self.total = Some(UntaggedValue::bytes(b + j).into_value(tag)); Ok(()) } None => { diff --git a/src/prelude.rs b/src/prelude.rs index 35fa419c80..49a75fba43 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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 crate::commands::command::{ diff --git a/src/shell/help_shell.rs b/src/shell/help_shell.rs index 2da32fa60c..9dafccd34b 100644 --- a/src/shell/help_shell.rs +++ b/src/shell/help_shell.rs @@ -3,11 +3,13 @@ use crate::commands::cp::CopyArgs; use crate::commands::mkdir::MkdirArgs; use crate::commands::mv::MoveArgs; use crate::commands::rm::RemoveArgs; -use crate::data::{command_dict, TaggedDictBuilder}; +use crate::data::command_dict; use crate::prelude::*; use crate::shell::shell::Shell; 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 std::ffi::OsStr; use std::path::PathBuf; diff --git a/src/shell/value_shell.rs b/src/shell/value_shell.rs index b655d73443..5e34fd99a0 100644 --- a/src/shell/value_shell.rs +++ b/src/shell/value_shell.rs @@ -218,7 +218,7 @@ impl Shell for ValueShell { fn pwd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { let mut stream = VecDeque::new(); 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()) } diff --git a/src/utils.rs b/src/utils.rs index c57a4b861b..349ea66529 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -332,8 +332,7 @@ impl FileStructure { #[cfg(test)] mod tests { use super::{FileStructure, Res, ValueResource, ValueStructure}; - use crate::data::{value, TaggedDictBuilder}; - use nu_protocol::Value; + use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value}; use nu_source::Tag; use pretty_assertions::assert_eq; use std::path::PathBuf; @@ -352,7 +351,7 @@ mod tests { fn structured_sample_record(key: &str, value: &str) -> Value { 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() }