From dcd97b6346db4be7397aeee2b36e7ae8540b3510 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Fri, 6 Sep 2019 04:23:42 +1200 Subject: [PATCH] Move internal terminology to tables/rows --- src/cli.rs | 4 +-- src/commands/args.rs | 2 +- src/commands/command.rs | 2 +- src/commands/config.rs | 12 ++++---- src/commands/date.rs | 8 ++---- src/commands/fetch.rs | 4 +-- src/commands/from_bson.rs | 4 +-- src/commands/from_csv.rs | 9 +++--- src/commands/from_ini.rs | 4 +-- src/commands/from_json.rs | 9 +++--- src/commands/from_sqlite.rs | 8 +++--- src/commands/from_toml.rs | 6 ++-- src/commands/from_tsv.rs | 6 ++-- src/commands/from_xml.rs | 6 ++-- src/commands/from_yaml.rs | 6 ++-- src/commands/get.rs | 4 +-- src/commands/help.rs | 2 +- src/commands/lines.rs | 2 +- src/commands/macros.rs | 4 +-- src/commands/open.rs | 4 +-- src/commands/pick.rs | 2 +- src/commands/post.rs | 4 +-- src/commands/ps.rs | 2 +- src/commands/reject.rs | 2 +- src/commands/save.rs | 2 +- src/commands/shells.rs | 2 +- src/commands/size.rs | 2 +- src/commands/split_column.rs | 2 +- src/commands/split_row.rs | 2 +- src/commands/tags.rs | 2 +- src/commands/to_bson.rs | 8 +++--- src/commands/to_csv.rs | 16 +++++------ src/commands/to_json.rs | 8 +++--- src/commands/to_sqlite.rs | 10 +++---- src/commands/to_toml.rs | 8 +++--- src/commands/to_tsv.rs | 16 +++++------ src/commands/to_yaml.rs | 8 +++--- src/commands/trim.rs | 2 +- src/commands/version.rs | 4 +-- src/commands/which_.rs | 2 +- src/{object.rs => data.rs} | 0 src/{object => data}/base.rs | 48 +++++++++++++++---------------- src/{object => data}/command.rs | 11 ++++--- src/{object => data}/config.rs | 6 ++-- src/{object => data}/dict.rs | 8 +++--- src/{object => data}/files.rs | 2 +- src/{object => data}/into.rs | 2 +- src/{object => data}/meta.rs | 0 src/{object => data}/operators.rs | 0 src/{object => data}/process.rs | 2 +- src/{object => data}/types.rs | 0 src/evaluate/evaluator.rs | 4 +-- src/format/generic.rs | 6 ++-- src/format/table.rs | 4 +-- src/format/vtable.rs | 2 +- src/lib.rs | 8 +++--- src/parser/deserializer.rs | 39 ++++++++++++------------- src/parser/parse/unit.rs | 2 +- src/plugins/add.rs | 2 +- src/plugins/edit.rs | 2 +- src/plugins/embed.rs | 2 +- src/plugins/inc.rs | 8 +++--- src/plugins/str.rs | 12 ++++---- src/plugins/sys.rs | 10 +++---- src/plugins/tree.rs | 4 +-- src/prelude.rs | 10 +++---- src/shell/filesystem_shell.rs | 2 +- src/shell/help_shell.rs | 17 +++++++---- src/shell/value_shell.rs | 4 +-- src/utils.rs | 12 ++++---- 70 files changed, 220 insertions(+), 219 deletions(-) rename src/{object.rs => data.rs} (100%) rename src/{object => data}/base.rs (94%) rename src/{object => data}/command.rs (87%) rename src/{object => data}/config.rs (92%) rename src/{object => data}/dict.rs (96%) rename src/{object => data}/files.rs (96%) rename src/{object => data}/into.rs (92%) rename src/{object => data}/meta.rs (100%) rename src/{object => data}/operators.rs (100%) rename src/{object => data}/process.rs (94%) rename src/{object => data}/types.rs (100%) diff --git a/src/cli.rs b/src/cli.rs index 9b41c9dd21..66572d3d8e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -7,9 +7,9 @@ use crate::commands::plugin::JsonRpc; use crate::commands::plugin::{PluginCommand, PluginSink}; use crate::commands::whole_stream_command; use crate::context::Context; +use crate::data::Value; pub(crate) use crate::errors::ShellError; use crate::git::current_branch; -use crate::object::Value; use crate::parser::registry::Signature; use crate::parser::{hir, CallNode, Pipeline, PipelineElement, TokenNode}; use crate::prelude::*; @@ -265,7 +265,7 @@ pub async fn cli() -> Result<(), Box> { context.shell_manager.clone(), ))); - let edit_mode = crate::object::config::config(Span::unknown())? + let edit_mode = crate::data::config::config(Span::unknown())? .get("edit_mode") .map(|s| match s.as_string().unwrap().as_ref() { "vi" => EditMode::Vi, diff --git a/src/commands/args.rs b/src/commands/args.rs index c08a075dd2..85329af5a1 100644 --- a/src/commands/args.rs +++ b/src/commands/args.rs @@ -1,4 +1,4 @@ -use crate::object::Value; +use crate::data::Value; #[derive(Debug)] pub enum LogLevel {} diff --git a/src/commands/command.rs b/src/commands/command.rs index a79e797fd7..9f4d256c2b 100644 --- a/src/commands/command.rs +++ b/src/commands/command.rs @@ -1,7 +1,7 @@ use crate::context::{SourceMap, SpanSource}; use crate::errors::ShellError; use crate::evaluate::Scope; -use crate::object::Value; +use crate::data::Value; use crate::parser::hir; use crate::parser::{registry, ConfigDeserializer}; use crate::prelude::*; diff --git a/src/commands/config.rs b/src/commands/config.rs index 56cce62270..c1f000d04d 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -2,7 +2,7 @@ use crate::prelude::*; use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::{config, Value}; +use crate::data::{config, Value}; use crate::parser::hir::SyntaxType; use crate::parser::registry::{self}; use std::iter::FromIterator; @@ -55,7 +55,7 @@ pub fn config( }: ConfigArgs, RunnableContext { name, .. }: RunnableContext, ) -> Result { - let mut result = crate::object::config::config(name)?; + let mut result = crate::data::config::config(name)?; if let Some(v) = get { let key = v.to_string(); @@ -74,7 +74,7 @@ pub fn config( config::write_config(&result)?; return Ok(stream![Tagged::from_simple_spanned_item( - Value::Object(result.into()), + Value::Row(result.into()), value.span() )] .from_input_stream()); @@ -90,7 +90,7 @@ pub fn config( config::write_config(&result)?; return Ok(stream![Tagged::from_simple_spanned_item( - Value::Object(result.into()), + Value::Row(result.into()), span )] .from_input_stream()); @@ -123,9 +123,9 @@ pub fn config( ))); } - let obj = VecDeque::from_iter(vec![Value::Object(result.into()).simple_spanned(v.span())]); + let obj = VecDeque::from_iter(vec![Value::Row(result.into()).simple_spanned(v.span())]); return Ok(obj.from_input_stream()); } - return Ok(vec![Value::Object(result.into()).simple_spanned(name)].into()); + return Ok(vec![Value::Row(result.into()).simple_spanned(name)].into()); } diff --git a/src/commands/date.rs b/src/commands/date.rs index 0e2fee563a..7d3307fe58 100644 --- a/src/commands/date.rs +++ b/src/commands/date.rs @@ -1,5 +1,5 @@ use crate::errors::ShellError; -use crate::object::{Dictionary, Value}; +use crate::data::{Dictionary, Value}; use crate::prelude::*; use chrono::{DateTime, Local, Utc}; @@ -17,9 +17,7 @@ impl WholeStreamCommand for Date { } fn signature(&self) -> Signature { - Signature::build("date") - .switch("utc") - .switch("local") + Signature::build("date").switch("utc").switch("local") } fn usage(&self) -> &str { @@ -72,7 +70,7 @@ where Tagged::from_simple_spanned_item(Value::string(format!("{}", tz)), span), ); - Tagged::from_simple_spanned_item(Value::Object(Dictionary::from(indexmap)), span) + Tagged::from_simple_spanned_item(Value::Row(Dictionary::from(indexmap)), span) } pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result { diff --git a/src/commands/fetch.rs b/src/commands/fetch.rs index 8f69929a19..e87ddf8347 100644 --- a/src/commands/fetch.rs +++ b/src/commands/fetch.rs @@ -1,7 +1,7 @@ use crate::commands::UnevaluatedCallInfo; use crate::context::SpanSource; +use crate::data::Value; use crate::errors::ShellError; -use crate::object::Value; use crate::parser::hir::SyntaxType; use crate::parser::registry::Signature; use crate::prelude::*; @@ -106,7 +106,7 @@ fn run( let result_vec: Vec> = result.drain_vec().await; for res in result_vec { match res { - Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => { + Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => { for l in list { yield Ok(ReturnSuccess::Value(l)); } diff --git a/src/commands/from_bson.rs b/src/commands/from_bson.rs index 492553e9d9..e2f5421bd9 100644 --- a/src/commands/from_bson.rs +++ b/src/commands/from_bson.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ExpectedRange; -use crate::object::{Primitive, TaggedDictBuilder, Value}; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; use bson::{decode_document, spec::BinarySubtype, Bson}; use std::str::FromStr; @@ -48,7 +48,7 @@ fn convert_bson_value_to_nu_value( Ok(match v { Bson::FloatingPoint(n) => Value::Primitive(Primitive::from(*n)).tagged(tag), Bson::String(s) => Value::Primitive(Primitive::String(String::from(s))).tagged(tag), - Bson::Array(a) => Value::List(bson_array(a, tag)?).tagged(tag), + Bson::Array(a) => Value::Table(bson_array(a, tag)?).tagged(tag), Bson::Document(doc) => { let mut collected = TaggedDictBuilder::new(tag); for (k, v) in doc.iter() { diff --git a/src/commands/from_csv.rs b/src/commands/from_csv.rs index 9f4a96da3e..c872e77360 100644 --- a/src/commands/from_csv.rs +++ b/src/commands/from_csv.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, TaggedDictBuilder, Value}; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; use csv::ReaderBuilder; @@ -16,8 +16,7 @@ impl WholeStreamCommand for FromCSV { } fn signature(&self) -> Signature { - Signature::build("from-csv") - .switch("headerless") + Signature::build("from-csv").switch("headerless") } fn usage(&self) -> &str { @@ -78,7 +77,7 @@ pub fn from_csv_string_to_value( } } - Ok(Tagged::from_item(Value::List(rows), tag)) + Ok(Tagged::from_item(Value::Table(rows), tag)) } fn from_csv( @@ -116,7 +115,7 @@ fn from_csv( match from_csv_string_to_value(concat_string, skip_headers, name_span) { Ok(x) => match x { - Tagged { item: Value::List(list), .. } => { + Tagged { item: Value::Table(list), .. } => { for l in list { yield ReturnSuccess::value(l); } diff --git a/src/commands/from_ini.rs b/src/commands/from_ini.rs index 8495c4b221..0e128a22c4 100644 --- a/src/commands/from_ini.rs +++ b/src/commands/from_ini.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, TaggedDictBuilder, Value}; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; use std::collections::HashMap; @@ -94,7 +94,7 @@ fn from_ini(args: CommandArgs, registry: &CommandRegistry) -> Result match x { - Tagged { item: Value::List(list), .. } => { + Tagged { item: Value::Table(list), .. } => { for l in list { yield ReturnSuccess::value(l); } diff --git a/src/commands/from_json.rs b/src/commands/from_json.rs index f932e35793..6864391af8 100644 --- a/src/commands/from_json.rs +++ b/src/commands/from_json.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, TaggedDictBuilder, Value}; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; pub struct FromJSON; @@ -15,8 +15,7 @@ impl WholeStreamCommand for FromJSON { } fn signature(&self) -> Signature { - Signature::build("from-json") - .switch("objects") + Signature::build("from-json").switch("objects") } fn usage(&self) -> &str { @@ -44,7 +43,7 @@ fn convert_json_value_to_nu_value(v: &serde_hjson::Value, tag: impl Into) - serde_hjson::Value::String(s) => { Value::Primitive(Primitive::String(String::from(s))).tagged(tag) } - serde_hjson::Value::Array(a) => Value::List( + serde_hjson::Value::Array(a) => Value::Table( a.iter() .map(|x| convert_json_value_to_nu_value(x, tag)) .collect(), @@ -126,7 +125,7 @@ fn from_json( match from_json_string_to_value(concat_string, name_span) { Ok(x) => match x { - Tagged { item: Value::List(list), .. } => { + Tagged { item: Value::Table(list), .. } => { for l in list { yield ReturnSuccess::value(l); } diff --git a/src/commands/from_sqlite.rs b/src/commands/from_sqlite.rs index 9aca8a222e..c19c4fef10 100644 --- a/src/commands/from_sqlite.rs +++ b/src/commands/from_sqlite.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::errors::ShellError; -use crate::object::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; use rusqlite::{types::ValueRef, Connection, Row, NO_PARAMS}; use std::io::Write; @@ -76,11 +76,11 @@ pub fn convert_sqlite_file_to_nu_value( "table_name".to_string(), Value::Primitive(Primitive::String(table_name)).tagged(tag.clone()), ); - meta_dict.insert_tagged("table_values", Value::List(out).tagged(tag.clone())); + meta_dict.insert_tagged("table_values", Value::Table(out).tagged(tag.clone())); meta_out.push(meta_dict.into_tagged_value()); } let tag = tag.into(); - Ok(Value::List(meta_out).tagged(tag)) + Ok(Value::Table(meta_out).tagged(tag)) } fn convert_sqlite_row_to_nu_value( @@ -140,7 +140,7 @@ fn from_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result match from_sqlite_bytes_to_value(vb, span) { Ok(x) => match x { - Tagged { item: Value::List(list), .. } => { + Tagged { item: Value::Table(list), .. } => { for l in list { yield ReturnSuccess::value(l); } diff --git a/src/commands/from_toml.rs b/src/commands/from_toml.rs index 3d1d92fb67..c1338cb01f 100644 --- a/src/commands/from_toml.rs +++ b/src/commands/from_toml.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, TaggedDictBuilder, Value}; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; pub struct FromTOML; @@ -34,7 +34,7 @@ pub fn convert_toml_value_to_nu_value(v: &toml::Value, tag: impl Into) -> T toml::Value::Integer(n) => Value::number(n).tagged(tag), toml::Value::Float(n) => Value::number(n).tagged(tag), toml::Value::String(s) => Value::Primitive(Primitive::String(String::from(s))).tagged(tag), - toml::Value::Array(a) => Value::List( + toml::Value::Array(a) => Value::Table( a.iter() .map(|x| convert_toml_value_to_nu_value(x, tag)) .collect(), @@ -98,7 +98,7 @@ pub fn from_toml( match from_toml_string_to_value(concat_string, span) { Ok(x) => match x { - Tagged { item: Value::List(list), .. } => { + Tagged { item: Value::Table(list), .. } => { for l in list { yield ReturnSuccess::value(l); } diff --git a/src/commands/from_tsv.rs b/src/commands/from_tsv.rs index 366621d435..92696c1aaf 100644 --- a/src/commands/from_tsv.rs +++ b/src/commands/from_tsv.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, TaggedDictBuilder, Value}; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; use csv::ReaderBuilder; @@ -78,7 +78,7 @@ pub fn from_tsv_string_to_value( } } - Ok(Tagged::from_item(Value::List(rows), tag)) + Ok(Tagged::from_item(Value::Table(rows), tag)) } fn from_tsv( @@ -116,7 +116,7 @@ fn from_tsv( match from_tsv_string_to_value(concat_string, skip_headers, name_span) { Ok(x) => match x { - Tagged { item: Value::List(list), .. } => { + Tagged { item: Value::Table(list), .. } => { for l in list { yield ReturnSuccess::value(l); } diff --git a/src/commands/from_xml.rs b/src/commands/from_xml.rs index 4e4be72bc2..2c3f94cddc 100644 --- a/src/commands/from_xml.rs +++ b/src/commands/from_xml.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, TaggedDictBuilder, Value}; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; pub struct FromXML; @@ -55,7 +55,7 @@ fn from_node_to_value<'a, 'd>(n: &roxmltree::Node<'a, 'd>, tag: impl Into) .collect(); let mut collected = TaggedDictBuilder::new(tag); - collected.insert(name.clone(), Value::List(children_values)); + collected.insert(name.clone(), Value::Table(children_values)); collected.into_tagged_value() } else if n.is_comment() { @@ -113,7 +113,7 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result match x { - Tagged { item: Value::List(list), .. } => { + Tagged { item: Value::Table(list), .. } => { for l in list { yield ReturnSuccess::value(l); } diff --git a/src/commands/from_yaml.rs b/src/commands/from_yaml.rs index 3bac9d3f81..430ac765b9 100644 --- a/src/commands/from_yaml.rs +++ b/src/commands/from_yaml.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, TaggedDictBuilder, Value}; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; pub struct FromYAML; @@ -62,7 +62,7 @@ fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, tag: impl Into) -> Value::Primitive(Primitive::from(n.as_f64().unwrap())).tagged(tag) } serde_yaml::Value::String(s) => Value::string(s).tagged(tag), - serde_yaml::Value::Sequence(a) => Value::List( + serde_yaml::Value::Sequence(a) => Value::Table( a.iter() .map(|x| convert_yaml_value_to_nu_value(x, tag)) .collect(), @@ -127,7 +127,7 @@ fn from_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result match x { - Tagged { item: Value::List(list), .. } => { + Tagged { item: Value::Table(list), .. } => { for l in list { yield ReturnSuccess::value(l); } diff --git a/src/commands/get.rs b/src/commands/get.rs index 44e3259fd8..2f9ed8a32a 100644 --- a/src/commands/get.rs +++ b/src/commands/get.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::Value; +use crate::data::Value; use crate::prelude::*; pub struct Get; @@ -73,7 +73,7 @@ pub fn get( for field in &fields { match get_member(field, &item) { Ok(Tagged { - item: Value::List(l), + item: Value::Table(l), .. }) => { for item in l { diff --git a/src/commands/help.rs b/src/commands/help.rs index bfdd61173f..571868a02a 100644 --- a/src/commands/help.rs +++ b/src/commands/help.rs @@ -1,7 +1,7 @@ use crate::commands::command::CommandAction; use crate::commands::PerItemCommand; use crate::errors::ShellError; -use crate::object::{command_dict, TaggedDictBuilder}; +use crate::data::{command_dict, TaggedDictBuilder}; use crate::parser::registry; use crate::prelude::*; diff --git a/src/commands/lines.rs b/src/commands/lines.rs index 0195177542..15a467224f 100644 --- a/src/commands/lines.rs +++ b/src/commands/lines.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::{Primitive, Value}; +use crate::data::{Primitive, Value}; use crate::prelude::*; use log::trace; diff --git a/src/commands/macros.rs b/src/commands/macros.rs index adac8d9c89..4a83f5e069 100644 --- a/src/commands/macros.rs +++ b/src/commands/macros.rs @@ -266,7 +266,7 @@ macro_rules! command { Extract { $($extract:tt)* { - use $crate::object::types::ExtractType; + use $crate::data::types::ExtractType; let value = $args.expect_nth($($positional_count)*)?; Block::extract(value)? } @@ -321,7 +321,7 @@ macro_rules! command { Extract { $($extract:tt)* { - use $crate::object::types::ExtractType; + use $crate::data::types::ExtractType; let value = $args.expect_nth($($positional_count)*)?; <$param_kind>::extract(&value)? } diff --git a/src/commands/open.rs b/src/commands/open.rs index ea960d8380..32a99c6f17 100644 --- a/src/commands/open.rs +++ b/src/commands/open.rs @@ -1,7 +1,7 @@ use crate::commands::UnevaluatedCallInfo; use crate::context::SpanSource; +use crate::data::Value; use crate::errors::ShellError; -use crate::object::Value; use crate::parser::hir::SyntaxType; use crate::parser::registry::Signature; use crate::prelude::*; @@ -107,7 +107,7 @@ fn run( let result_vec: Vec> = result.drain_vec().await; for res in result_vec { match res { - Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => { + Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => { for l in list { yield Ok(ReturnSuccess::Value(l)); } diff --git a/src/commands/pick.rs b/src/commands/pick.rs index 927edf8b3d..bc5f8df401 100644 --- a/src/commands/pick.rs +++ b/src/commands/pick.rs @@ -1,7 +1,7 @@ use crate::commands::WholeStreamCommand; use crate::context::CommandRegistry; use crate::errors::ShellError; -use crate::object::base::select_fields; +use crate::data::base::select_fields; use crate::prelude::*; #[derive(Deserialize)] diff --git a/src/commands/post.rs b/src/commands/post.rs index c1fc5d42fe..8790c929a7 100644 --- a/src/commands/post.rs +++ b/src/commands/post.rs @@ -1,7 +1,7 @@ use crate::commands::UnevaluatedCallInfo; use crate::context::SpanSource; use crate::errors::ShellError; -use crate::object::Value; +use crate::data::Value; use crate::parser::hir::SyntaxType; use crate::parser::registry::Signature; use crate::prelude::*; @@ -116,7 +116,7 @@ fn run( let result_vec: Vec> = result.drain_vec().await; for res in result_vec { match res { - Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => { + Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => { for l in list { yield Ok(ReturnSuccess::Value(l)); } diff --git a/src/commands/ps.rs b/src/commands/ps.rs index b11e797961..cdacd7113c 100644 --- a/src/commands/ps.rs +++ b/src/commands/ps.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::TaggedDictBuilder; +use crate::data::TaggedDictBuilder; use crate::prelude::*; use std::time::Duration; use std::usize; diff --git a/src/commands/reject.rs b/src/commands/reject.rs index b519f8ea64..49dbc4dd36 100644 --- a/src/commands/reject.rs +++ b/src/commands/reject.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::base::reject_fields; +use crate::data::base::reject_fields; use crate::prelude::*; #[derive(Deserialize)] diff --git a/src/commands/save.rs b/src/commands/save.rs index e998329c8f..26bf8cb16d 100644 --- a/src/commands/save.rs +++ b/src/commands/save.rs @@ -1,6 +1,6 @@ use crate::commands::{UnevaluatedCallInfo, WholeStreamCommand}; use crate::errors::ShellError; -use crate::object::Value; +use crate::data::Value; use crate::prelude::*; use std::path::{Path, PathBuf}; diff --git a/src/commands/shells.rs b/src/commands/shells.rs index 5e0159e147..856c23e7be 100644 --- a/src/commands/shells.rs +++ b/src/commands/shells.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::TaggedDictBuilder; +use crate::data::TaggedDictBuilder; use crate::prelude::*; pub struct Shells; diff --git a/src/commands/size.rs b/src/commands/size.rs index 02da0460cb..d8383efcf8 100644 --- a/src/commands/size.rs +++ b/src/commands/size.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::{TaggedDictBuilder, Value}; +use crate::data::{TaggedDictBuilder, Value}; use crate::prelude::*; pub struct Size; diff --git a/src/commands/split_column.rs b/src/commands/split_column.rs index 4bde5e25b0..2df02cac16 100644 --- a/src/commands/split_column.rs +++ b/src/commands/split_column.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::{Primitive, TaggedDictBuilder, Value}; +use crate::data::{Primitive, TaggedDictBuilder, Value}; use crate::prelude::*; use log::trace; diff --git a/src/commands/split_row.rs b/src/commands/split_row.rs index fa95225f4f..d4f3824a80 100644 --- a/src/commands/split_row.rs +++ b/src/commands/split_row.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::{Primitive, Value}; +use crate::data::{Primitive, Value}; use crate::prelude::*; use log::trace; diff --git a/src/commands/tags.rs b/src/commands/tags.rs index 973105709c..3f112482ca 100644 --- a/src/commands/tags.rs +++ b/src/commands/tags.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::{TaggedDictBuilder, Value}; +use crate::data::{TaggedDictBuilder, Value}; use crate::prelude::*; pub struct Tags; diff --git a/src/commands/to_bson.rs b/src/commands/to_bson.rs index 8f7e9c3624..bb0355a5e9 100644 --- a/src/commands/to_bson.rs +++ b/src/commands/to_bson.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Dictionary, Primitive, Value}; +use crate::data::{Dictionary, Primitive, Value}; use crate::prelude::*; use bson::{encode_document, oid::ObjectId, spec::BinarySubtype, Bson, Document}; use std::convert::TryInto; @@ -51,14 +51,14 @@ pub fn value_to_bson_value(v: &Tagged) -> Result { Value::Primitive(Primitive::Nothing) => Bson::Null, Value::Primitive(Primitive::String(s)) => Bson::String(s.clone()), Value::Primitive(Primitive::Path(s)) => Bson::String(s.display().to_string()), - Value::List(l) => Bson::Array( + Value::Table(l) => Bson::Array( l.iter() .map(|x| value_to_bson_value(x)) .collect::>()?, ), Value::Block(_) => Bson::Null, Value::Binary(b) => Bson::Binary(BinarySubtype::Generic, b.clone()), - Value::Object(o) => object_value_to_bson(o)?, + Value::Row(o) => object_value_to_bson(o)?, }) } @@ -241,7 +241,7 @@ fn to_bson(args: CommandArgs, registry: &CommandRegistry) -> Result 1 { let tag = input[0].tag; - vec![Tagged { item: Value::List(input), tag } ] + vec![Tagged { item: Value::Table(input), tag } ] } else if input.len() == 1 { input } else { diff --git a/src/commands/to_csv.rs b/src/commands/to_csv.rs index 8f788e6484..0d13cab8fc 100644 --- a/src/commands/to_csv.rs +++ b/src/commands/to_csv.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, Value}; +use crate::data::{Primitive, Value}; use crate::prelude::*; use csv::WriterBuilder; @@ -39,8 +39,8 @@ pub fn value_to_csv_value(v: &Value) -> Value { Value::Primitive(Primitive::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())), Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(b.clone())), Value::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())), - Value::Object(o) => Value::Object(o.clone()), - Value::List(l) => Value::List(l.clone()), + Value::Row(o) => Value::Row(o.clone()), + Value::Table(l) => Value::Table(l.clone()), Value::Block(_) => Value::Primitive(Primitive::Nothing), _ => Value::Primitive(Primitive::Nothing), } @@ -51,8 +51,8 @@ fn to_string_helper(v: &Value) -> Result { Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()), Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)), Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?), - Value::List(_) => return Ok(String::from("[list list]")), - Value::Object(_) => return Ok(String::from("[object]")), + Value::Table(_) => return Ok(String::from("[list list]")), + Value::Row(_) => return Ok(String::from("[object]")), Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()), _ => return Err(ShellError::string("Unexpected value")), } @@ -72,7 +72,7 @@ fn merge_descriptors(values: &[Tagged]) -> Vec { pub fn to_string(v: &Value) -> Result { match v { - Value::Object(o) => { + Value::Row(o) => { let mut wtr = WriterBuilder::new().from_writer(vec![]); let mut fields: VecDeque = VecDeque::new(); let mut values: VecDeque = VecDeque::new(); @@ -92,7 +92,7 @@ pub fn to_string(v: &Value) -> Result { ) .map_err(|_| ShellError::string("Could not convert record"))?); } - Value::List(list) => { + Value::Table(list) => { let mut wtr = WriterBuilder::new().from_writer(vec![]); let merged_descriptors = merge_descriptors(&list); @@ -134,7 +134,7 @@ fn to_csv( let to_process_input = if input.len() > 1 { let tag = input[0].tag; - vec![Tagged { item: Value::List(input), tag } ] + vec![Tagged { item: Value::Table(input), tag } ] } else if input.len() == 1 { input } else { diff --git a/src/commands/to_json.rs b/src/commands/to_json.rs index a6123528dc..f53fbd8d28 100644 --- a/src/commands/to_json.rs +++ b/src/commands/to_json.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, Value}; +use crate::data::{Primitive, Value}; use crate::prelude::*; pub struct ToJSON; @@ -48,7 +48,7 @@ pub fn value_to_json_value(v: &Tagged) -> Result serde_json::Value::String(s.clone()), Value::Primitive(Primitive::Path(s)) => serde_json::Value::String(s.display().to_string()), - Value::List(l) => serde_json::Value::Array(json_list(l)?), + Value::Table(l) => serde_json::Value::Array(json_list(l)?), Value::Block(_) => serde_json::Value::Null, Value::Binary(b) => serde_json::Value::Array( b.iter() @@ -57,7 +57,7 @@ pub fn value_to_json_value(v: &Tagged) -> Result { + Value::Row(o) => { let mut m = serde_json::Map::new(); for (k, v) in o.entries.iter() { m.insert(k.clone(), value_to_json_value(v)?); @@ -85,7 +85,7 @@ fn to_json(args: CommandArgs, registry: &CommandRegistry) -> Result 1 { let tag = input[0].tag; - vec![Tagged { item: Value::List(input), tag } ] + vec![Tagged { item: Value::Table(input), tag } ] } else if input.len() == 1 { input } else { diff --git a/src/commands/to_sqlite.rs b/src/commands/to_sqlite.rs index 6506ac335d..7580c3f4b7 100644 --- a/src/commands/to_sqlite.rs +++ b/src/commands/to_sqlite.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Dictionary, Primitive, Value}; +use crate::data::{Dictionary, Primitive, Value}; use crate::prelude::*; use hex::encode; use rusqlite::{Connection, NO_PARAMS}; @@ -71,7 +71,7 @@ fn comma_concat(acc: String, current: String) -> String { fn get_columns(rows: &Vec>) -> Result { match &rows[0].item { - Value::Object(d) => Ok(d + Value::Row(d) => Ok(d .entries .iter() .map(|(k, _v)| k.clone()) @@ -107,7 +107,7 @@ fn get_insert_values(rows: Vec>) -> Result let values: Result, _> = rows .into_iter() .map(|value| match value.item { - Value::Object(d) => Ok(format!( + Value::Row(d) => Ok(format!( "({})", d.entries .iter() @@ -139,7 +139,7 @@ fn generate_statements(table: Dictionary) -> Result<(String, String), std::io::E }; let (columns, insert_values) = match table.entries.get("table_values") { Some(Tagged { - item: Value::List(l), + item: Value::Table(l), .. }) => (get_columns(l), get_insert_values(l.to_vec())), _ => { @@ -169,7 +169,7 @@ fn sqlite_input_stream_to_bytes( let tag = values[0].tag.clone(); for value in values.into_iter() { match value.item() { - Value::Object(d) => { + Value::Row(d) => { let (create, insert) = generate_statements(d.to_owned())?; match conn .execute(&create, NO_PARAMS) diff --git a/src/commands/to_toml.rs b/src/commands/to_toml.rs index 419a50ac77..7bca9840e9 100644 --- a/src/commands/to_toml.rs +++ b/src/commands/to_toml.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, Value}; +use crate::data::{Primitive, Value}; use crate::prelude::*; pub struct ToTOML; @@ -47,12 +47,12 @@ pub fn value_to_toml_value(v: &Tagged) -> Result Value::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()), Value::Primitive(Primitive::Path(s)) => toml::Value::String(s.display().to_string()), - Value::List(l) => toml::Value::Array(collect_values(l)?), + Value::Table(l) => toml::Value::Array(collect_values(l)?), Value::Block(_) => toml::Value::String("".to_string()), Value::Binary(b) => { toml::Value::Array(b.iter().map(|x| toml::Value::Integer(*x as i64)).collect()) } - Value::Object(o) => { + Value::Row(o) => { let mut m = toml::map::Map::new(); for (k, v) in o.entries.iter() { m.insert(k.clone(), value_to_toml_value(v)?); @@ -80,7 +80,7 @@ fn to_toml(args: CommandArgs, registry: &CommandRegistry) -> Result 1 { let tag = input[0].tag; - vec![Tagged { item: Value::List(input), tag } ] + vec![Tagged { item: Value::Table(input), tag } ] } else if input.len() == 1 { input } else { diff --git a/src/commands/to_tsv.rs b/src/commands/to_tsv.rs index e787d197ec..2842db2315 100644 --- a/src/commands/to_tsv.rs +++ b/src/commands/to_tsv.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, Value}; +use crate::data::{Primitive, Value}; use crate::prelude::*; use csv::WriterBuilder; @@ -39,8 +39,8 @@ pub fn value_to_tsv_value(v: &Value) -> Value { Value::Primitive(Primitive::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())), Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(b.clone())), Value::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())), - Value::Object(o) => Value::Object(o.clone()), - Value::List(l) => Value::List(l.clone()), + Value::Row(o) => Value::Row(o.clone()), + Value::Table(l) => Value::Table(l.clone()), Value::Block(_) => Value::Primitive(Primitive::Nothing), _ => Value::Primitive(Primitive::Nothing), } @@ -51,8 +51,8 @@ fn to_string_helper(v: &Value) -> Result { Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()), Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)), Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?), - Value::List(_) => return Ok(String::from("[table]")), - Value::Object(_) => return Ok(String::from("[row]")), + Value::Table(_) => return Ok(String::from("[table]")), + Value::Row(_) => return Ok(String::from("[row]")), Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()), _ => Err(ShellError::string("Unexpected value")), } @@ -72,7 +72,7 @@ fn merge_descriptors(values: &[Tagged]) -> Vec { pub fn to_string(v: &Value) -> Result { match v { - Value::Object(o) => { + Value::Row(o) => { let mut wtr = WriterBuilder::new().delimiter(b'\t').from_writer(vec![]); let mut fields: VecDeque = VecDeque::new(); let mut values: VecDeque = VecDeque::new(); @@ -91,7 +91,7 @@ pub fn to_string(v: &Value) -> Result { ) .map_err(|_| ShellError::string("Could not convert record"))?); } - Value::List(list) => { + Value::Table(list) => { let mut wtr = WriterBuilder::new().delimiter(b'\t').from_writer(vec![]); let merged_descriptors = merge_descriptors(&list); @@ -133,7 +133,7 @@ fn to_tsv( let to_process_input = if input.len() > 1 { let tag = input[0].tag; - vec![Tagged { item: Value::List(input), tag } ] + vec![Tagged { item: Value::Table(input), tag } ] } else if input.len() == 1 { input } else { diff --git a/src/commands/to_yaml.rs b/src/commands/to_yaml.rs index 5655567ef0..129deebdf6 100644 --- a/src/commands/to_yaml.rs +++ b/src/commands/to_yaml.rs @@ -1,5 +1,5 @@ use crate::commands::WholeStreamCommand; -use crate::object::{Primitive, Value}; +use crate::data::{Primitive, Value}; use crate::prelude::*; pub struct ToYAML; @@ -45,7 +45,7 @@ pub fn value_to_yaml_value(v: &Tagged) -> Result serde_yaml::Value::String(s.clone()), Value::Primitive(Primitive::Path(s)) => serde_yaml::Value::String(s.display().to_string()), - Value::List(l) => { + Value::Table(l) => { let mut out = vec![]; for value in l { @@ -60,7 +60,7 @@ pub fn value_to_yaml_value(v: &Tagged) -> Result { + Value::Row(o) => { let mut m = serde_yaml::Mapping::new(); for (k, v) in o.entries.iter() { m.insert( @@ -81,7 +81,7 @@ fn to_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result 1 { let tag = input[0].tag; - vec![Tagged { item: Value::List(input), tag } ] + vec![Tagged { item: Value::Table(input), tag } ] } else if input.len() == 1 { input } else { diff --git a/src/commands/trim.rs b/src/commands/trim.rs index 66152843f0..865f6b50bb 100644 --- a/src/commands/trim.rs +++ b/src/commands/trim.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::Value; +use crate::data::Value; use crate::prelude::*; pub struct Trim; diff --git a/src/commands/version.rs b/src/commands/version.rs index def335420a..a7a3578193 100644 --- a/src/commands/version.rs +++ b/src/commands/version.rs @@ -1,6 +1,6 @@ use crate::commands::WholeStreamCommand; use crate::errors::ShellError; -use crate::object::{Dictionary, Value}; +use crate::data::{Dictionary, Value}; use crate::parser::registry::Signature; use crate::prelude::*; use indexmap::IndexMap; @@ -39,6 +39,6 @@ pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result), - List(Vec>), + Table(Vec>), Block(Block), } @@ -220,8 +220,8 @@ impl fmt::Debug for ValueDebug<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.value.item() { Value::Primitive(p) => p.debug(f), - Value::Object(o) => o.debug(f), - Value::List(l) => debug_list(l).fmt(f), + Value::Row(o) => o.debug(f), + Value::Table(l) => debug_list(l).fmt(f), Value::Block(_) => write!(f, "[[block]]"), Value::Binary(_) => write!(f, "[[binary]]"), } @@ -293,12 +293,12 @@ impl std::convert::TryFrom<&Tagged> for Vec { } } -impl<'a> std::convert::TryFrom<&'a Tagged> for &'a crate::object::Dictionary { +impl<'a> std::convert::TryFrom<&'a Tagged> for &'a crate::data::Dictionary { type Error = ShellError; - fn try_from(value: &'a Tagged) -> Result<&'a crate::object::Dictionary, ShellError> { + fn try_from(value: &'a Tagged) -> Result<&'a crate::data::Dictionary, ShellError> { match value.item() { - Value::Object(d) => Ok(d), + Value::Row(d) => Ok(d), v => Err(ShellError::type_error( "Dictionary", value.copy_span(v.type_name()), @@ -340,8 +340,8 @@ impl Value { pub(crate) fn type_name(&self) -> String { match self { Value::Primitive(p) => p.type_name(), - Value::Object(_) => format!("object"), - Value::List(_) => format!("list"), + Value::Row(_) => format!("object"), + Value::Table(_) => format!("list"), Value::Block(_) => format!("block"), Value::Binary(_) => format!("binary"), } @@ -351,26 +351,26 @@ impl Value { pub fn data_descriptors(&self) -> Vec { match self { Value::Primitive(_) => vec![], - Value::Object(o) => o + Value::Row(o) => o .entries .keys() .into_iter() .map(|x| x.to_string()) .collect(), Value::Block(_) => vec![], - Value::List(_) => vec![], + Value::Table(_) => vec![], Value::Binary(_) => vec![], } } pub(crate) fn get_data_by_key(&self, name: &str) -> Option<&Tagged> { match self { - Value::Object(o) => o.get_data_by_key(name), - Value::List(l) => { + Value::Row(o) => o.get_data_by_key(name), + Value::Table(l) => { for item in l { match item { Tagged { - item: Value::Object(o), + item: Value::Row(o), .. } => match o.get_data_by_key(name) { Some(v) => return Some(v), @@ -407,7 +407,7 @@ impl Value { let split_path: Vec<_> = path.split(".").collect(); - if let Value::Object(ref mut o) = new_obj { + if let Value::Row(ref mut o) = new_obj { let mut current = o; if split_path.len() == 1 { @@ -423,7 +423,7 @@ impl Value { Some(next) => { if idx == (split_path.len() - 2) { match &mut next.item { - Value::Object(o) => { + Value::Row(o) => { o.entries.insert( split_path[idx + 1].to_string(), Tagged::from_item(new_value, tag), @@ -435,7 +435,7 @@ impl Value { return Some(Tagged::from_item(new_obj, tag)); } else { match next.item { - Value::Object(ref mut o) => { + Value::Row(ref mut o) => { current = o; } _ => return None, @@ -460,7 +460,7 @@ impl Value { let split_path: Vec<_> = path.split(".").collect(); - if let Value::Object(ref mut o) = new_obj { + if let Value::Row(ref mut o) = new_obj { let mut current = o; for idx in 0..split_path.len() { match current.entries.get_mut(split_path[idx]) { @@ -470,7 +470,7 @@ impl Value { return Some(Tagged::from_item(new_obj, tag)); } else { match next.item { - Value::Object(ref mut o) => { + Value::Row(ref mut o) => { current = o; } _ => return None, @@ -488,9 +488,9 @@ impl Value { pub fn get_data(&self, desc: &String) -> MaybeOwned<'_, Value> { match self { p @ Value::Primitive(_) => MaybeOwned::Borrowed(p), - Value::Object(o) => o.get_data(desc), + Value::Row(o) => o.get_data(desc), Value::Block(_) => MaybeOwned::Owned(Value::nothing()), - Value::List(_) => MaybeOwned::Owned(Value::nothing()), + Value::Table(_) => MaybeOwned::Owned(Value::nothing()), Value::Binary(_) => MaybeOwned::Owned(Value::nothing()), } } @@ -504,8 +504,8 @@ impl Value { .map(|e| e.source(&b.source).to_string()), "; ", ), - Value::Object(_) => format!("[table: 1 row]"), - Value::List(l) => format!( + Value::Row(_) => format!("[table: 1 row]"), + Value::Table(l) => format!( "[table: {} {}]", l.len(), if l.len() == 1 { "row" } else { "rows" } diff --git a/src/object/command.rs b/src/data/command.rs similarity index 87% rename from src/object/command.rs rename to src/data/command.rs index 317fe5fa34..a2046aa7aa 100644 --- a/src/object/command.rs +++ b/src/data/command.rs @@ -1,5 +1,5 @@ use crate::commands::command::Command; -use crate::object::{TaggedDictBuilder, TaggedListBuilder, Value}; +use crate::data::{TaggedDictBuilder, TaggedListBuilder, Value}; use crate::parser::registry::{NamedType, PositionalType, Signature}; use crate::prelude::*; use std::ops::Deref; @@ -32,7 +32,10 @@ fn for_spec(name: &str, ty: &str, required: bool, tag: impl Into) -> Tagged spec.insert("name", Value::string(name)); spec.insert("type", Value::string(ty)); - spec.insert("required", Value::string(if required { "yes" } else { "no" })); + spec.insert( + "required", + Value::string(if required { "yes" } else { "no" }), + ); spec.into_tagged_value() } @@ -43,8 +46,8 @@ fn signature_dict(signature: Signature, tag: impl Into) -> Tagged { for arg in signature.positional.iter() { let is_required = match arg { - PositionalType::Mandatory(_,_) => true, - PositionalType::Optional(_,_) => false, + PositionalType::Mandatory(_, _) => true, + PositionalType::Optional(_, _) => false, }; sig.insert_tagged(for_spec(arg.name(), "argument", is_required, tag)); diff --git a/src/object/config.rs b/src/data/config.rs similarity index 92% rename from src/object/config.rs rename to src/data/config.rs index 53a1c446f8..cf384e8b68 100644 --- a/src/object/config.rs +++ b/src/data/config.rs @@ -1,7 +1,7 @@ use crate::commands::from_toml::convert_toml_value_to_nu_value; use crate::commands::to_toml::value_to_toml_value; +use crate::data::{Dictionary, Value}; use crate::errors::ShellError; -use crate::object::{Dictionary, Value}; use crate::prelude::*; use app_dirs::*; use indexmap::IndexMap; @@ -37,7 +37,7 @@ pub(crate) fn write_config(config: &IndexMap>) -> Result<( touch(&filename)?; let contents = - value_to_toml_value(&Value::Object(Dictionary::new(config.clone())).tagged_unknown())?; + value_to_toml_value(&Value::Row(Dictionary::new(config.clone())).tagged_unknown())?; let contents = toml::to_string(&contents)?; @@ -67,7 +67,7 @@ pub(crate) fn config(span: impl Into) -> Result Ok(entries), + Value::Row(Dictionary { entries }) => Ok(entries), other => Err(ShellError::type_error( "Dictionary", other.type_name().tagged(tag), diff --git a/src/object/dict.rs b/src/data/dict.rs similarity index 96% rename from src/object/dict.rs rename to src/data/dict.rs index e52ab5882a..eba68a7f8a 100644 --- a/src/object/dict.rs +++ b/src/data/dict.rs @@ -1,5 +1,5 @@ +use crate::data::{Primitive, Value}; use crate::prelude::*; -use crate::object::{Primitive, Value}; use derive_new::new; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; @@ -64,7 +64,7 @@ impl PartialOrd for Dictionary { impl PartialEq for Dictionary { fn eq(&self, other: &Value) -> bool { match other { - Value::Object(d) => self == d, + Value::Row(d) => self == d, _ => false, } } @@ -123,7 +123,7 @@ impl TaggedListBuilder { } pub fn into_tagged_value(self) -> Tagged { - Value::List(self.list).tagged(self.tag) + Value::Table(self.list).tagged(self.tag) } } @@ -163,7 +163,7 @@ impl TaggedDictBuilder { } pub fn into_tagged_value(self) -> Tagged { - self.into_tagged_dict().map(Value::Object) + self.into_tagged_dict().map(Value::Row) } pub fn into_tagged_dict(self) -> Tagged { diff --git a/src/object/files.rs b/src/data/files.rs similarity index 96% rename from src/object/files.rs rename to src/data/files.rs index ba48aeab9c..47c6ae093f 100644 --- a/src/object/files.rs +++ b/src/data/files.rs @@ -1,5 +1,5 @@ +use crate::data::{TaggedDictBuilder, Value}; use crate::errors::ShellError; -use crate::object::{TaggedDictBuilder, Value}; use crate::prelude::*; #[derive(Debug)] diff --git a/src/object/into.rs b/src/data/into.rs similarity index 92% rename from src/object/into.rs rename to src/data/into.rs index 1d2648a7ad..749ab0601f 100644 --- a/src/object/into.rs +++ b/src/data/into.rs @@ -1,4 +1,4 @@ -use crate::object::{Primitive, Value}; +use crate::data::{Primitive, Value}; use crate::prelude::*; impl From for Value { diff --git a/src/object/meta.rs b/src/data/meta.rs similarity index 100% rename from src/object/meta.rs rename to src/data/meta.rs diff --git a/src/object/operators.rs b/src/data/operators.rs similarity index 100% rename from src/object/operators.rs rename to src/data/operators.rs diff --git a/src/object/process.rs b/src/data/process.rs similarity index 94% rename from src/object/process.rs rename to src/data/process.rs index 337f731b58..cf6a2fb148 100644 --- a/src/object/process.rs +++ b/src/data/process.rs @@ -1,4 +1,4 @@ -use crate::object::{TaggedDictBuilder, Value}; +use crate::data::{TaggedDictBuilder, Value}; use crate::prelude::*; use itertools::join; use sysinfo::ProcessExt; diff --git a/src/object/types.rs b/src/data/types.rs similarity index 100% rename from src/object/types.rs rename to src/data/types.rs diff --git a/src/evaluate/evaluator.rs b/src/evaluate/evaluator.rs index 0bf31b5e71..ee241583fd 100644 --- a/src/evaluate/evaluator.rs +++ b/src/evaluate/evaluator.rs @@ -1,5 +1,5 @@ +use crate::data::base::Block; use crate::errors::Description; -use crate::object::base::Block; use crate::parser::{ hir::{self, Expression, RawExpression}, CommandRegistry, Text, @@ -66,7 +66,7 @@ pub(crate) fn evaluate_baseline_expr( exprs.push(expr); } - Ok(Value::List(exprs).tagged(Tag::unknown_origin(expr.span()))) + Ok(Value::Table(exprs).tagged(Tag::unknown_origin(expr.span()))) } RawExpression::Block(block) => Ok(Tagged::from_simple_spanned_item( Value::Block(Block::new(block.clone(), source.clone(), expr.span())), diff --git a/src/format/generic.rs b/src/format/generic.rs index 6142b1122b..57726f819c 100644 --- a/src/format/generic.rs +++ b/src/format/generic.rs @@ -1,5 +1,5 @@ +use crate::data::Value; use crate::format::{EntriesView, RenderView, TableView}; -use crate::object::Value; use crate::prelude::*; use derive_new::new; @@ -13,7 +13,7 @@ impl RenderView for GenericView<'_> { fn render_view(&self, host: &mut dyn Host) -> Result<(), ShellError> { match self.value { Value::Primitive(p) => Ok(host.stdout(&p.format(None))), - Value::List(l) => { + Value::Table(l) => { let view = TableView::from_list(l); if let Some(view) = view { @@ -23,7 +23,7 @@ impl RenderView for GenericView<'_> { Ok(()) } - o @ Value::Object(_) => { + o @ Value::Row(_) => { let view = EntriesView::from_value(o); view.render_view(host)?; Ok(()) diff --git a/src/format/table.rs b/src/format/table.rs index 37ed516686..8deaf30aaf 100644 --- a/src/format/table.rs +++ b/src/format/table.rs @@ -1,5 +1,5 @@ +use crate::data::Value; use crate::format::RenderView; -use crate::object::Value; use crate::prelude::*; use derive_new::new; use textwrap::fill; @@ -45,7 +45,7 @@ impl TableView { for (idx, value) in values.iter().enumerate() { let mut row: Vec<(String, &'static str)> = match value { Tagged { - item: Value::Object(..), + item: Value::Row(..), .. } => headers .iter() diff --git a/src/format/vtable.rs b/src/format/vtable.rs index 08c4a72d0d..fe151224f4 100644 --- a/src/format/vtable.rs +++ b/src/format/vtable.rs @@ -1,5 +1,5 @@ +use crate::data::Value; use crate::format::RenderView; -use crate::object::Value; use crate::prelude::*; use derive_new::new; diff --git a/src/lib.rs b/src/lib.rs index 2e9b8fb061..4e16352e05 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,12 +7,12 @@ mod prelude; mod cli; mod commands; mod context; +mod data; mod env; mod errors; mod evaluate; mod format; mod git; -mod object; mod parser; mod plugin; mod shell; @@ -28,10 +28,10 @@ pub use crate::parser::parse::token_tree_builder::TokenTreeBuilder; pub use crate::plugin::{serve_plugin, Plugin}; pub use crate::utils::{AbsoluteFile, AbsolutePath, RelativePath}; pub use cli::cli; +pub use data::base::{Primitive, Value}; +pub use data::dict::{Dictionary, TaggedDictBuilder}; +pub use data::meta::{Span, Tag, Tagged, TaggedItem}; pub use errors::{CoerceInto, ShellError}; pub use num_traits::cast::ToPrimitive; -pub use object::base::{Primitive, Value}; -pub use object::dict::{Dictionary, TaggedDictBuilder}; -pub use object::meta::{Span, Tag, Tagged, TaggedItem}; pub use parser::parse::text::Text; pub use parser::registry::{EvaluatedArgs, NamedType, PositionalType, Signature}; diff --git a/src/parser/deserializer.rs b/src/parser/deserializer.rs index d37df05157..33a23189f1 100644 --- a/src/parser/deserializer.rs +++ b/src/parser/deserializer.rs @@ -37,7 +37,7 @@ impl<'de> ConfigDeserializer<'de> { let value: Option> = if name == "rest" { let positional = self.call.args.slice_from(self.position); self.position += positional.len(); - Some(Value::List(positional).tagged_unknown()) // TODO: correct span + Some(Value::Table(positional).tagged_unknown()) // TODO: correct span } else { if self.call.args.has(name) { self.call.args.get(name).map(|x| x.clone()) @@ -240,14 +240,11 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> { trace!(" Extracting {:?} for vec", value.val); match value.val.into_parts() { - (Value::List(items), _) => { + (Value::Table(items), _) => { let de = SeqDeserializer::new(&mut self, items.into_iter()); visitor.visit_seq(de) } - (other, tag) => Err(ShellError::type_error( - "Vec", - other.type_name().tagged(tag), - )), + (other, tag) => Err(ShellError::type_error("Vec", other.type_name().tagged(tag))), } } fn deserialize_tuple(mut self, len: usize, visitor: V) -> Result @@ -255,10 +252,14 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> { V: Visitor<'de>, { let value = self.pop(); - trace!(" Extracting {:?} for tuple with {} elements", value.val, len); + trace!( + " Extracting {:?} for tuple with {} elements", + value.val, + len + ); match value.val.into_parts() { - (Value::List(items), _) => { + (Value::Table(items), _) => { let de = SeqDeserializer::new(&mut self, items.into_iter()); visitor.visit_seq(de) } @@ -298,7 +299,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> { val: T, name: &'static str, fields: &'static [&'static str], - visitor: V + visitor: V, ) -> Result where T: serde::Serialize, @@ -364,7 +365,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> { } => { let i: i64 = int.tagged(value.val.tag).coerce_into("converting to i64")?; visit::, _>(i.tagged(tag), name, fields, visitor) - }, + } Tagged { item: Value::Primitive(Primitive::String(string)), .. @@ -398,21 +399,20 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> { } } -struct SeqDeserializer<'a, 'de: 'a, I: Iterator>> { +struct SeqDeserializer<'a, 'de: 'a, I: Iterator>> { de: &'a mut ConfigDeserializer<'de>, vals: I, } -impl<'a, 'de: 'a, I: Iterator>> SeqDeserializer<'a, 'de, I> { +impl<'a, 'de: 'a, I: Iterator>> SeqDeserializer<'a, 'de, I> { fn new(de: &'a mut ConfigDeserializer<'de>, vals: I) -> Self { - SeqDeserializer { - de, - vals, - } + SeqDeserializer { de, vals } } } -impl<'a, 'de: 'a, I: Iterator>> de::SeqAccess<'de> for SeqDeserializer<'a, 'de, I> { +impl<'a, 'de: 'a, I: Iterator>> de::SeqAccess<'de> + for SeqDeserializer<'a, 'de, I> +{ type Error = ShellError; fn next_element_seed(&mut self, seed: T) -> Result, Self::Error> @@ -441,10 +441,7 @@ struct StructDeserializer<'a, 'de: 'a> { impl<'a, 'de: 'a> StructDeserializer<'a, 'de> { fn new(de: &'a mut ConfigDeserializer<'de>, fields: &'static [&'static str]) -> Self { - StructDeserializer { - de, - fields, - } + StructDeserializer { de, fields } } } diff --git a/src/parser/parse/unit.rs b/src/parser/parse/unit.rs index a29ce15b9f..aa19580ac2 100644 --- a/src/parser/parse/unit.rs +++ b/src/parser/parse/unit.rs @@ -1,4 +1,4 @@ -use crate::object::base::Value; +use crate::data::base::Value; use crate::prelude::*; use serde::{Deserialize, Serialize}; use std::str::FromStr; diff --git a/src/plugins/add.rs b/src/plugins/add.rs index 3915cc4566..744003cd74 100644 --- a/src/plugins/add.rs +++ b/src/plugins/add.rs @@ -18,7 +18,7 @@ impl Add { fn add(&self, value: Tagged) -> Result, ShellError> { let value_tag = value.tag(); match (value.item, self.value.clone()) { - (obj @ Value::Object(_), Some(v)) => match &self.field { + (obj @ Value::Row(_), Some(v)) => match &self.field { Some(f) => match obj.insert_data_at_path(value_tag, &f, v) { Some(v) => return Ok(v), None => { diff --git a/src/plugins/edit.rs b/src/plugins/edit.rs index 15e87d996e..aeda4ba09b 100644 --- a/src/plugins/edit.rs +++ b/src/plugins/edit.rs @@ -18,7 +18,7 @@ impl Edit { fn edit(&self, value: Tagged) -> Result, ShellError> { let value_tag = value.tag(); match (value.item, self.value.clone()) { - (obj @ Value::Object(_), Some(v)) => match &self.field { + (obj @ Value::Row(_), Some(v)) => match &self.field { Some(f) => match obj.replace_data_at_path(value_tag, &f, v) { Some(v) => return Ok(v), None => { diff --git a/src/plugins/embed.rs b/src/plugins/embed.rs index 3c7adb01bf..95140aa609 100644 --- a/src/plugins/embed.rs +++ b/src/plugins/embed.rs @@ -74,7 +74,7 @@ impl Plugin for Embed { root.insert_tagged( self.field.as_ref().unwrap(), Tagged { - item: Value::List(self.values.clone()), + item: Value::Table(self.values.clone()), tag: Tag::unknown(), }, ); diff --git a/src/plugins/inc.rs b/src/plugins/inc.rs index ec78dbb622..d75da41428 100644 --- a/src/plugins/inc.rs +++ b/src/plugins/inc.rs @@ -83,7 +83,7 @@ impl Inc { Value::Primitive(Primitive::String(ref s)) => { Ok(Tagged::from_item(self.apply(&s)?, value.tag())) } - Value::Object(_) => match self.field { + Value::Row(_) => match self.field { Some(ref f) => { let replacement = match value.item.get_data_by_path(value.tag(), f) { Some(result) => self.inc(result.map(|x| x.clone()))?, @@ -333,7 +333,7 @@ mod tests { match output[0].as_ref().unwrap() { ReturnSuccess::Value(Tagged { - item: Value::Object(o), + item: Value::Row(o), .. }) => assert_eq!( *o.get_data(&String::from("version")).borrow(), @@ -361,7 +361,7 @@ mod tests { match output[0].as_ref().unwrap() { ReturnSuccess::Value(Tagged { - item: Value::Object(o), + item: Value::Row(o), .. }) => assert_eq!( *o.get_data(&String::from("version")).borrow(), @@ -390,7 +390,7 @@ mod tests { match output[0].as_ref().unwrap() { ReturnSuccess::Value(Tagged { - item: Value::Object(o), + item: Value::Row(o), .. }) => assert_eq!( *o.get_data(&field).borrow(), diff --git a/src/plugins/str.rs b/src/plugins/str.rs index 9b2f73c553..99700449b4 100644 --- a/src/plugins/str.rs +++ b/src/plugins/str.rs @@ -135,7 +135,7 @@ impl Str { Value::Primitive(Primitive::String(ref s)) => { Ok(Tagged::from_item(self.apply(&s)?, value.tag())) } - Value::Object(_) => match self.field { + Value::Row(_) => match self.field { Some(ref f) => { let replacement = match value.item.get_data_by_path(value.tag(), f) { Some(result) => self.strutils(result.map(|x| x.clone()))?, @@ -479,7 +479,7 @@ mod tests { match output[0].as_ref().unwrap() { ReturnSuccess::Value(Tagged { - item: Value::Object(o), + item: Value::Row(o), .. }) => assert_eq!( *o.get_data(&String::from("name")).borrow(), @@ -527,7 +527,7 @@ mod tests { match output[0].as_ref().unwrap() { ReturnSuccess::Value(Tagged { - item: Value::Object(o), + item: Value::Row(o), .. }) => assert_eq!( *o.get_data(&String::from("name")).borrow(), @@ -575,7 +575,7 @@ mod tests { match output[0].as_ref().unwrap() { ReturnSuccess::Value(Tagged { - item: Value::Object(o), + item: Value::Row(o), .. }) => assert_eq!( *o.get_data(&String::from("Nu_birthday")).borrow(), @@ -624,7 +624,7 @@ mod tests { match output[0].as_ref().unwrap() { ReturnSuccess::Value(Tagged { - item: Value::Object(o), + item: Value::Row(o), .. }) => assert_eq!( *o.get_data(&String::from("rustconf")).borrow(), @@ -679,7 +679,7 @@ mod tests { match output[0].as_ref().unwrap() { ReturnSuccess::Value(Tagged { - item: Value::Object(o), + item: Value::Row(o), .. }) => assert_eq!( *o.get_data(&String::from("staff")).borrow(), diff --git a/src/plugins/sys.rs b/src/plugins/sys.rs index 41b280ffe4..db7de6e625 100644 --- a/src/plugins/sys.rs +++ b/src/plugins/sys.rs @@ -119,7 +119,7 @@ async fn host(tag: Tag) -> Tagged { user_vec.push(Tagged::from_item(Value::string(user.username()), tag)); } } - let user_list = Value::List(user_vec); + let user_list = Value::Table(user_vec); dict.insert("users", user_list); dict.into_tagged_value() @@ -163,7 +163,7 @@ async fn disks(tag: Tag) -> Option { } if !output.is_empty() { - Some(Value::List(output)) + Some(Value::Table(output)) } else { None } @@ -205,7 +205,7 @@ async fn battery(tag: Tag) -> Option { } if !output.is_empty() { - Some(Value::List(output)) + Some(Value::Table(output)) } else { None } @@ -248,7 +248,7 @@ async fn temp(tag: Tag) -> Option { } if !output.is_empty() { - Some(Value::List(output)) + Some(Value::Table(output)) } else { None } @@ -273,7 +273,7 @@ async fn net(tag: Tag) -> Option { } } if !output.is_empty() { - Some(Value::List(output)) + Some(Value::Table(output)) } else { None } diff --git a/src/plugins/tree.rs b/src/plugins/tree.rs index 19e38b626c..3d571ca18c 100644 --- a/src/plugins/tree.rs +++ b/src/plugins/tree.rs @@ -17,14 +17,14 @@ impl TreeView { Value::Primitive(p) => { let _ = builder.add_empty_child(p.format(None)); } - Value::Object(o) => { + Value::Row(o) => { for (k, v) in o.entries.iter() { builder = builder.begin_child(k.clone()); Self::from_value_helper(v, builder); builder = builder.end_child(); } } - Value::List(l) => { + Value::Table(l) => { for elem in l.iter() { Self::from_value_helper(elem, builder); } diff --git a/src/prelude.rs b/src/prelude.rs index f800dc8cda..a491aff5de 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -55,20 +55,20 @@ pub(crate) use crate::commands::PerItemCommand; pub(crate) use crate::commands::RawCommandArgs; pub(crate) use crate::context::CommandRegistry; pub(crate) use crate::context::{Context, SpanSource}; +pub(crate) use crate::data::base as value; +pub(crate) use crate::data::meta::{Tag, Tagged, TaggedItem}; +pub(crate) use crate::data::types::ExtractType; +pub(crate) use crate::data::{Primitive, Value}; pub(crate) use crate::env::host::handle_unexpected; pub(crate) use crate::env::Host; pub(crate) use crate::errors::{CoerceInto, ShellError}; -pub(crate) use crate::object::base as value; -pub(crate) use crate::object::meta::{Tag, Tagged, TaggedItem}; -pub(crate) use crate::object::types::ExtractType; -pub(crate) use crate::object::{Primitive, Value}; pub(crate) use crate::parser::hir::SyntaxType; pub(crate) use crate::parser::parse::parser::Number; pub(crate) use crate::parser::registry::Signature; pub(crate) use crate::shell::filesystem_shell::FilesystemShell; +pub(crate) use crate::shell::help_shell::HelpShell; pub(crate) use crate::shell::shell_manager::ShellManager; pub(crate) use crate::shell::value_shell::ValueShell; -pub(crate) use crate::shell::help_shell::HelpShell; pub(crate) use crate::stream::{InputStream, OutputStream}; pub(crate) use crate::traits::{HasSpan, ToDebug}; pub(crate) use crate::Span; diff --git a/src/shell/filesystem_shell.rs b/src/shell/filesystem_shell.rs index 1bb7796b5d..5b62d329a2 100644 --- a/src/shell/filesystem_shell.rs +++ b/src/shell/filesystem_shell.rs @@ -4,7 +4,7 @@ use crate::commands::mkdir::MkdirArgs; use crate::commands::mv::MoveArgs; use crate::commands::rm::RemoveArgs; use crate::context::SourceMap; -use crate::object::dir_entry_dict; +use crate::data::dir_entry_dict; use crate::prelude::*; use crate::shell::completer::NuCompleter; use crate::shell::shell::Shell; diff --git a/src/shell/help_shell.rs b/src/shell/help_shell.rs index 59f141b8c0..aebdeff391 100644 --- a/src/shell/help_shell.rs +++ b/src/shell/help_shell.rs @@ -4,7 +4,7 @@ use crate::commands::mkdir::MkdirArgs; use crate::commands::mv::MoveArgs; use crate::commands::rm::RemoveArgs; use crate::context::SourceMap; -use crate::object::{TaggedDictBuilder, command_dict}; +use crate::data::{command_dict, TaggedDictBuilder}; use crate::prelude::*; use crate::shell::shell::Shell; use std::ffi::OsStr; @@ -26,13 +26,16 @@ impl HelpShell { let value = command_dict(registry.get_command(&cmd).unwrap(), Tag::unknown()); spec.insert("name", cmd); - spec.insert("description", value.get_data_by_key("usage").unwrap().as_string().unwrap()); + spec.insert( + "description", + value.get_data_by_key("usage").unwrap().as_string().unwrap(), + ); spec.insert_tagged("details", value); specs.push(spec.into_tagged_value()); } - cmds.insert("help", Value::List(specs)); + cmds.insert("help", Value::Table(specs)); Ok(HelpShell { path: "/help".to_string(), @@ -47,8 +50,10 @@ impl HelpShell { let mut sh = HelpShell::index(®istry)?; if let Tagged { - item: Value::Primitive(Primitive::String(name)), .. - } = cmd { + item: Value::Primitive(Primitive::String(name)), + .. + } = cmd + { sh.set_path(format!("/help/{:}/details", name)); } @@ -76,7 +81,7 @@ impl HelpShell { } match viewed { Tagged { - item: Value::List(l), + item: Value::Table(l), .. } => { for item in l { diff --git a/src/shell/value_shell.rs b/src/shell/value_shell.rs index 26dab3583f..84c8294625 100644 --- a/src/shell/value_shell.rs +++ b/src/shell/value_shell.rs @@ -43,7 +43,7 @@ impl ValueShell { } match viewed { Tagged { - item: Value::List(l), + item: Value::Table(l), .. } => { for item in l { @@ -55,7 +55,7 @@ impl ValueShell { } } - shell_entries + shell_entries } fn members(&self) -> VecDeque> { diff --git a/src/utils.rs b/src/utils.rs index 060b72d7a2..703f277254 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,6 @@ +use crate::data::meta::Tagged; +use crate::data::Value; use crate::errors::ShellError; -use crate::object::meta::Tagged; -use crate::object::Value; use std::fmt; use std::ops::Div; use std::path::{Component, Path, PathBuf}; @@ -150,14 +150,14 @@ impl<'a> Iterator for TaggedValueIter<'a> { impl Tagged { fn is_dir(&self) -> bool { match self.item() { - Value::Object(_) | Value::List(_) => true, + Value::Row(_) | Value::Table(_) => true, _ => false, } } fn entries(&self) -> TaggedValueIter<'_> { match self.item() { - Value::Object(o) => { + Value::Row(o) => { let iter = o.entries.iter(); TaggedValueIter::List(iter) } @@ -321,8 +321,8 @@ impl FileStructure { #[cfg(test)] mod tests { use super::{FileStructure, Res, ValueResource, ValueStructure}; - use crate::object::meta::{Tag, Tagged}; - use crate::object::{TaggedDictBuilder, Value}; + use crate::data::meta::{Tag, Tagged}; + use crate::data::{TaggedDictBuilder, Value}; use pretty_assertions::assert_eq; use std::path::PathBuf;