mirror of
https://github.com/nushell/nushell
synced 2024-12-27 13:33:16 +00:00
Move internal terminology to tables/rows
This commit is contained in:
parent
0a9897c5ca
commit
dcd97b6346
70 changed files with 220 additions and 219 deletions
|
@ -7,9 +7,9 @@ use crate::commands::plugin::JsonRpc;
|
||||||
use crate::commands::plugin::{PluginCommand, PluginSink};
|
use crate::commands::plugin::{PluginCommand, PluginSink};
|
||||||
use crate::commands::whole_stream_command;
|
use crate::commands::whole_stream_command;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
|
use crate::data::Value;
|
||||||
pub(crate) use crate::errors::ShellError;
|
pub(crate) use crate::errors::ShellError;
|
||||||
use crate::git::current_branch;
|
use crate::git::current_branch;
|
||||||
use crate::object::Value;
|
|
||||||
use crate::parser::registry::Signature;
|
use crate::parser::registry::Signature;
|
||||||
use crate::parser::{hir, CallNode, Pipeline, PipelineElement, TokenNode};
|
use crate::parser::{hir, CallNode, Pipeline, PipelineElement, TokenNode};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -265,7 +265,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||||
context.shell_manager.clone(),
|
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")
|
.get("edit_mode")
|
||||||
.map(|s| match s.as_string().unwrap().as_ref() {
|
.map(|s| match s.as_string().unwrap().as_ref() {
|
||||||
"vi" => EditMode::Vi,
|
"vi" => EditMode::Vi,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::object::Value;
|
use crate::data::Value;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum LogLevel {}
|
pub enum LogLevel {}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::context::{SourceMap, SpanSource};
|
use crate::context::{SourceMap, SpanSource};
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::evaluate::Scope;
|
use crate::evaluate::Scope;
|
||||||
use crate::object::Value;
|
use crate::data::Value;
|
||||||
use crate::parser::hir;
|
use crate::parser::hir;
|
||||||
use crate::parser::{registry, ConfigDeserializer};
|
use crate::parser::{registry, ConfigDeserializer};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::prelude::*;
|
||||||
|
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{config, Value};
|
use crate::data::{config, Value};
|
||||||
use crate::parser::hir::SyntaxType;
|
use crate::parser::hir::SyntaxType;
|
||||||
use crate::parser::registry::{self};
|
use crate::parser::registry::{self};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
|
@ -55,7 +55,7 @@ pub fn config(
|
||||||
}: ConfigArgs,
|
}: ConfigArgs,
|
||||||
RunnableContext { name, .. }: RunnableContext,
|
RunnableContext { name, .. }: RunnableContext,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let mut result = crate::object::config::config(name)?;
|
let mut result = crate::data::config::config(name)?;
|
||||||
|
|
||||||
if let Some(v) = get {
|
if let Some(v) = get {
|
||||||
let key = v.to_string();
|
let key = v.to_string();
|
||||||
|
@ -74,7 +74,7 @@ pub fn config(
|
||||||
config::write_config(&result)?;
|
config::write_config(&result)?;
|
||||||
|
|
||||||
return Ok(stream![Tagged::from_simple_spanned_item(
|
return Ok(stream![Tagged::from_simple_spanned_item(
|
||||||
Value::Object(result.into()),
|
Value::Row(result.into()),
|
||||||
value.span()
|
value.span()
|
||||||
)]
|
)]
|
||||||
.from_input_stream());
|
.from_input_stream());
|
||||||
|
@ -90,7 +90,7 @@ pub fn config(
|
||||||
config::write_config(&result)?;
|
config::write_config(&result)?;
|
||||||
|
|
||||||
return Ok(stream![Tagged::from_simple_spanned_item(
|
return Ok(stream![Tagged::from_simple_spanned_item(
|
||||||
Value::Object(result.into()),
|
Value::Row(result.into()),
|
||||||
span
|
span
|
||||||
)]
|
)]
|
||||||
.from_input_stream());
|
.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(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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Dictionary, Value};
|
use crate::data::{Dictionary, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use chrono::{DateTime, Local, Utc};
|
use chrono::{DateTime, Local, Utc};
|
||||||
|
|
||||||
|
@ -17,9 +17,7 @@ impl WholeStreamCommand for Date {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("date")
|
Signature::build("date").switch("utc").switch("local")
|
||||||
.switch("utc")
|
|
||||||
.switch("local")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
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::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<OutputStream, ShellError> {
|
pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::context::SpanSource;
|
use crate::context::SpanSource;
|
||||||
|
use crate::data::Value;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::Value;
|
|
||||||
use crate::parser::hir::SyntaxType;
|
use crate::parser::hir::SyntaxType;
|
||||||
use crate::parser::registry::Signature;
|
use crate::parser::registry::Signature;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -106,7 +106,7 @@ fn run(
|
||||||
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
|
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
|
||||||
for res in result_vec {
|
for res in result_vec {
|
||||||
match res {
|
match res {
|
||||||
Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => {
|
Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield Ok(ReturnSuccess::Value(l));
|
yield Ok(ReturnSuccess::Value(l));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ExpectedRange;
|
use crate::errors::ExpectedRange;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use bson::{decode_document, spec::BinarySubtype, Bson};
|
use bson::{decode_document, spec::BinarySubtype, Bson};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
@ -48,7 +48,7 @@ fn convert_bson_value_to_nu_value(
|
||||||
Ok(match v {
|
Ok(match v {
|
||||||
Bson::FloatingPoint(n) => Value::Primitive(Primitive::from(*n)).tagged(tag),
|
Bson::FloatingPoint(n) => Value::Primitive(Primitive::from(*n)).tagged(tag),
|
||||||
Bson::String(s) => Value::Primitive(Primitive::String(String::from(s))).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) => {
|
Bson::Document(doc) => {
|
||||||
let mut collected = TaggedDictBuilder::new(tag);
|
let mut collected = TaggedDictBuilder::new(tag);
|
||||||
for (k, v) in doc.iter() {
|
for (k, v) in doc.iter() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use csv::ReaderBuilder;
|
use csv::ReaderBuilder;
|
||||||
|
|
||||||
|
@ -16,8 +16,7 @@ impl WholeStreamCommand for FromCSV {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("from-csv")
|
Signature::build("from-csv").switch("headerless")
|
||||||
.switch("headerless")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
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(
|
fn from_csv(
|
||||||
|
@ -116,7 +115,7 @@ fn from_csv(
|
||||||
|
|
||||||
match from_csv_string_to_value(concat_string, skip_headers, name_span) {
|
match from_csv_string_to_value(concat_string, skip_headers, name_span) {
|
||||||
Ok(x) => match x {
|
Ok(x) => match x {
|
||||||
Tagged { item: Value::List(list), .. } => {
|
Tagged { item: Value::Table(list), .. } => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield ReturnSuccess::value(l);
|
yield ReturnSuccess::value(l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ fn from_ini(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
|
||||||
|
|
||||||
match from_ini_string_to_value(concat_string, span) {
|
match from_ini_string_to_value(concat_string, span) {
|
||||||
Ok(x) => match x {
|
Ok(x) => match x {
|
||||||
Tagged { item: Value::List(list), .. } => {
|
Tagged { item: Value::Table(list), .. } => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield ReturnSuccess::value(l);
|
yield ReturnSuccess::value(l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct FromJSON;
|
pub struct FromJSON;
|
||||||
|
@ -15,8 +15,7 @@ impl WholeStreamCommand for FromJSON {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("from-json")
|
Signature::build("from-json").switch("objects")
|
||||||
.switch("objects")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
|
@ -44,7 +43,7 @@ fn convert_json_value_to_nu_value(v: &serde_hjson::Value, tag: impl Into<Tag>) -
|
||||||
serde_hjson::Value::String(s) => {
|
serde_hjson::Value::String(s) => {
|
||||||
Value::Primitive(Primitive::String(String::from(s))).tagged(tag)
|
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()
|
a.iter()
|
||||||
.map(|x| convert_json_value_to_nu_value(x, tag))
|
.map(|x| convert_json_value_to_nu_value(x, tag))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
@ -126,7 +125,7 @@ fn from_json(
|
||||||
match from_json_string_to_value(concat_string, name_span) {
|
match from_json_string_to_value(concat_string, name_span) {
|
||||||
Ok(x) =>
|
Ok(x) =>
|
||||||
match x {
|
match x {
|
||||||
Tagged { item: Value::List(list), .. } => {
|
Tagged { item: Value::Table(list), .. } => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield ReturnSuccess::value(l);
|
yield ReturnSuccess::value(l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use rusqlite::{types::ValueRef, Connection, Row, NO_PARAMS};
|
use rusqlite::{types::ValueRef, Connection, Row, NO_PARAMS};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
@ -76,11 +76,11 @@ pub fn convert_sqlite_file_to_nu_value(
|
||||||
"table_name".to_string(),
|
"table_name".to_string(),
|
||||||
Value::Primitive(Primitive::String(table_name)).tagged(tag.clone()),
|
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());
|
meta_out.push(meta_dict.into_tagged_value());
|
||||||
}
|
}
|
||||||
let tag = tag.into();
|
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(
|
fn convert_sqlite_row_to_nu_value(
|
||||||
|
@ -140,7 +140,7 @@ fn from_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputSt
|
||||||
Value::Binary(vb) =>
|
Value::Binary(vb) =>
|
||||||
match from_sqlite_bytes_to_value(vb, span) {
|
match from_sqlite_bytes_to_value(vb, span) {
|
||||||
Ok(x) => match x {
|
Ok(x) => match x {
|
||||||
Tagged { item: Value::List(list), .. } => {
|
Tagged { item: Value::Table(list), .. } => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield ReturnSuccess::value(l);
|
yield ReturnSuccess::value(l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct FromTOML;
|
pub struct FromTOML;
|
||||||
|
@ -34,7 +34,7 @@ pub fn convert_toml_value_to_nu_value(v: &toml::Value, tag: impl Into<Tag>) -> T
|
||||||
toml::Value::Integer(n) => Value::number(n).tagged(tag),
|
toml::Value::Integer(n) => Value::number(n).tagged(tag),
|
||||||
toml::Value::Float(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::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()
|
a.iter()
|
||||||
.map(|x| convert_toml_value_to_nu_value(x, tag))
|
.map(|x| convert_toml_value_to_nu_value(x, tag))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
@ -98,7 +98,7 @@ pub fn from_toml(
|
||||||
|
|
||||||
match from_toml_string_to_value(concat_string, span) {
|
match from_toml_string_to_value(concat_string, span) {
|
||||||
Ok(x) => match x {
|
Ok(x) => match x {
|
||||||
Tagged { item: Value::List(list), .. } => {
|
Tagged { item: Value::Table(list), .. } => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield ReturnSuccess::value(l);
|
yield ReturnSuccess::value(l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use csv::ReaderBuilder;
|
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(
|
fn from_tsv(
|
||||||
|
@ -116,7 +116,7 @@ fn from_tsv(
|
||||||
|
|
||||||
match from_tsv_string_to_value(concat_string, skip_headers, name_span) {
|
match from_tsv_string_to_value(concat_string, skip_headers, name_span) {
|
||||||
Ok(x) => match x {
|
Ok(x) => match x {
|
||||||
Tagged { item: Value::List(list), .. } => {
|
Tagged { item: Value::Table(list), .. } => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield ReturnSuccess::value(l);
|
yield ReturnSuccess::value(l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct FromXML;
|
pub struct FromXML;
|
||||||
|
@ -55,7 +55,7 @@ fn from_node_to_value<'a, 'd>(n: &roxmltree::Node<'a, 'd>, tag: impl Into<Tag>)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut collected = TaggedDictBuilder::new(tag);
|
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()
|
collected.into_tagged_value()
|
||||||
} else if n.is_comment() {
|
} else if n.is_comment() {
|
||||||
|
@ -113,7 +113,7 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
|
||||||
|
|
||||||
match from_xml_string_to_value(concat_string, span) {
|
match from_xml_string_to_value(concat_string, span) {
|
||||||
Ok(x) => match x {
|
Ok(x) => match x {
|
||||||
Tagged { item: Value::List(list), .. } => {
|
Tagged { item: Value::Table(list), .. } => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield ReturnSuccess::value(l);
|
yield ReturnSuccess::value(l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct FromYAML;
|
pub struct FromYAML;
|
||||||
|
@ -62,7 +62,7 @@ fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, tag: impl Into<Tag>) ->
|
||||||
Value::Primitive(Primitive::from(n.as_f64().unwrap())).tagged(tag)
|
Value::Primitive(Primitive::from(n.as_f64().unwrap())).tagged(tag)
|
||||||
}
|
}
|
||||||
serde_yaml::Value::String(s) => Value::string(s).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()
|
a.iter()
|
||||||
.map(|x| convert_yaml_value_to_nu_value(x, tag))
|
.map(|x| convert_yaml_value_to_nu_value(x, tag))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
@ -127,7 +127,7 @@ fn from_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
|
||||||
|
|
||||||
match from_yaml_string_to_value(concat_string, span) {
|
match from_yaml_string_to_value(concat_string, span) {
|
||||||
Ok(x) => match x {
|
Ok(x) => match x {
|
||||||
Tagged { item: Value::List(list), .. } => {
|
Tagged { item: Value::Table(list), .. } => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield ReturnSuccess::value(l);
|
yield ReturnSuccess::value(l);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::Value;
|
use crate::data::Value;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Get;
|
pub struct Get;
|
||||||
|
@ -73,7 +73,7 @@ pub fn get(
|
||||||
for field in &fields {
|
for field in &fields {
|
||||||
match get_member(field, &item) {
|
match get_member(field, &item) {
|
||||||
Ok(Tagged {
|
Ok(Tagged {
|
||||||
item: Value::List(l),
|
item: Value::Table(l),
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
for item in l {
|
for item in l {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::commands::command::CommandAction;
|
use crate::commands::command::CommandAction;
|
||||||
use crate::commands::PerItemCommand;
|
use crate::commands::PerItemCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{command_dict, TaggedDictBuilder};
|
use crate::data::{command_dict, TaggedDictBuilder};
|
||||||
use crate::parser::registry;
|
use crate::parser::registry;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ macro_rules! command {
|
||||||
|
|
||||||
Extract {
|
Extract {
|
||||||
$($extract:tt)* {
|
$($extract:tt)* {
|
||||||
use $crate::object::types::ExtractType;
|
use $crate::data::types::ExtractType;
|
||||||
let value = $args.expect_nth($($positional_count)*)?;
|
let value = $args.expect_nth($($positional_count)*)?;
|
||||||
Block::extract(value)?
|
Block::extract(value)?
|
||||||
}
|
}
|
||||||
|
@ -321,7 +321,7 @@ macro_rules! command {
|
||||||
|
|
||||||
Extract {
|
Extract {
|
||||||
$($extract:tt)* {
|
$($extract:tt)* {
|
||||||
use $crate::object::types::ExtractType;
|
use $crate::data::types::ExtractType;
|
||||||
let value = $args.expect_nth($($positional_count)*)?;
|
let value = $args.expect_nth($($positional_count)*)?;
|
||||||
<$param_kind>::extract(&value)?
|
<$param_kind>::extract(&value)?
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::context::SpanSource;
|
use crate::context::SpanSource;
|
||||||
|
use crate::data::Value;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::Value;
|
|
||||||
use crate::parser::hir::SyntaxType;
|
use crate::parser::hir::SyntaxType;
|
||||||
use crate::parser::registry::Signature;
|
use crate::parser::registry::Signature;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -107,7 +107,7 @@ fn run(
|
||||||
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
|
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
|
||||||
for res in result_vec {
|
for res in result_vec {
|
||||||
match res {
|
match res {
|
||||||
Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => {
|
Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield Ok(ReturnSuccess::Value(l));
|
yield Ok(ReturnSuccess::Value(l));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::base::select_fields;
|
use crate::data::base::select_fields;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::context::SpanSource;
|
use crate::context::SpanSource;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::Value;
|
use crate::data::Value;
|
||||||
use crate::parser::hir::SyntaxType;
|
use crate::parser::hir::SyntaxType;
|
||||||
use crate::parser::registry::Signature;
|
use crate::parser::registry::Signature;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -116,7 +116,7 @@ fn run(
|
||||||
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
|
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
|
||||||
for res in result_vec {
|
for res in result_vec {
|
||||||
match res {
|
match res {
|
||||||
Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => {
|
Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => {
|
||||||
for l in list {
|
for l in list {
|
||||||
yield Ok(ReturnSuccess::Value(l));
|
yield Ok(ReturnSuccess::Value(l));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::TaggedDictBuilder;
|
use crate::data::TaggedDictBuilder;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::usize;
|
use std::usize;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::base::reject_fields;
|
use crate::data::base::reject_fields;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::{UnevaluatedCallInfo, WholeStreamCommand};
|
use crate::commands::{UnevaluatedCallInfo, WholeStreamCommand};
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::Value;
|
use crate::data::Value;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::TaggedDictBuilder;
|
use crate::data::TaggedDictBuilder;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Shells;
|
pub struct Shells;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{TaggedDictBuilder, Value};
|
use crate::data::{TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Size;
|
pub struct Size;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{TaggedDictBuilder, Value};
|
use crate::data::{TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Tags;
|
pub struct Tags;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Dictionary, Primitive, Value};
|
use crate::data::{Dictionary, Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use bson::{encode_document, oid::ObjectId, spec::BinarySubtype, Bson, Document};
|
use bson::{encode_document, oid::ObjectId, spec::BinarySubtype, Bson, Document};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
@ -51,14 +51,14 @@ pub fn value_to_bson_value(v: &Tagged<Value>) -> Result<Bson, ShellError> {
|
||||||
Value::Primitive(Primitive::Nothing) => Bson::Null,
|
Value::Primitive(Primitive::Nothing) => Bson::Null,
|
||||||
Value::Primitive(Primitive::String(s)) => Bson::String(s.clone()),
|
Value::Primitive(Primitive::String(s)) => Bson::String(s.clone()),
|
||||||
Value::Primitive(Primitive::Path(s)) => Bson::String(s.display().to_string()),
|
Value::Primitive(Primitive::Path(s)) => Bson::String(s.display().to_string()),
|
||||||
Value::List(l) => Bson::Array(
|
Value::Table(l) => Bson::Array(
|
||||||
l.iter()
|
l.iter()
|
||||||
.map(|x| value_to_bson_value(x))
|
.map(|x| value_to_bson_value(x))
|
||||||
.collect::<Result<_, _>>()?,
|
.collect::<Result<_, _>>()?,
|
||||||
),
|
),
|
||||||
Value::Block(_) => Bson::Null,
|
Value::Block(_) => Bson::Null,
|
||||||
Value::Binary(b) => Bson::Binary(BinarySubtype::Generic, b.clone()),
|
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<OutputStream
|
||||||
|
|
||||||
let to_process_input = if input.len() > 1 {
|
let to_process_input = if input.len() > 1 {
|
||||||
let tag = input[0].tag;
|
let tag = input[0].tag;
|
||||||
vec![Tagged { item: Value::List(input), tag } ]
|
vec![Tagged { item: Value::Table(input), tag } ]
|
||||||
} else if input.len() == 1 {
|
} else if input.len() == 1 {
|
||||||
input
|
input
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use csv::WriterBuilder;
|
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::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())),
|
||||||
Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(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::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())),
|
||||||
Value::Object(o) => Value::Object(o.clone()),
|
Value::Row(o) => Value::Row(o.clone()),
|
||||||
Value::List(l) => Value::List(l.clone()),
|
Value::Table(l) => Value::Table(l.clone()),
|
||||||
Value::Block(_) => Value::Primitive(Primitive::Nothing),
|
Value::Block(_) => Value::Primitive(Primitive::Nothing),
|
||||||
_ => Value::Primitive(Primitive::Nothing),
|
_ => Value::Primitive(Primitive::Nothing),
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ fn to_string_helper(v: &Value) -> Result<String, ShellError> {
|
||||||
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
|
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
|
||||||
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
|
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
|
||||||
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
|
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
|
||||||
Value::List(_) => return Ok(String::from("[list list]")),
|
Value::Table(_) => return Ok(String::from("[list list]")),
|
||||||
Value::Object(_) => return Ok(String::from("[object]")),
|
Value::Row(_) => return Ok(String::from("[object]")),
|
||||||
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
|
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
|
||||||
_ => return Err(ShellError::string("Unexpected value")),
|
_ => return Err(ShellError::string("Unexpected value")),
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
|
||||||
|
|
||||||
pub fn to_string(v: &Value) -> Result<String, ShellError> {
|
pub fn to_string(v: &Value) -> Result<String, ShellError> {
|
||||||
match v {
|
match v {
|
||||||
Value::Object(o) => {
|
Value::Row(o) => {
|
||||||
let mut wtr = WriterBuilder::new().from_writer(vec![]);
|
let mut wtr = WriterBuilder::new().from_writer(vec![]);
|
||||||
let mut fields: VecDeque<String> = VecDeque::new();
|
let mut fields: VecDeque<String> = VecDeque::new();
|
||||||
let mut values: VecDeque<String> = VecDeque::new();
|
let mut values: VecDeque<String> = VecDeque::new();
|
||||||
|
@ -92,7 +92,7 @@ pub fn to_string(v: &Value) -> Result<String, ShellError> {
|
||||||
)
|
)
|
||||||
.map_err(|_| ShellError::string("Could not convert record"))?);
|
.map_err(|_| ShellError::string("Could not convert record"))?);
|
||||||
}
|
}
|
||||||
Value::List(list) => {
|
Value::Table(list) => {
|
||||||
let mut wtr = WriterBuilder::new().from_writer(vec![]);
|
let mut wtr = WriterBuilder::new().from_writer(vec![]);
|
||||||
|
|
||||||
let merged_descriptors = merge_descriptors(&list);
|
let merged_descriptors = merge_descriptors(&list);
|
||||||
|
@ -134,7 +134,7 @@ fn to_csv(
|
||||||
|
|
||||||
let to_process_input = if input.len() > 1 {
|
let to_process_input = if input.len() > 1 {
|
||||||
let tag = input[0].tag;
|
let tag = input[0].tag;
|
||||||
vec![Tagged { item: Value::List(input), tag } ]
|
vec![Tagged { item: Value::Table(input), tag } ]
|
||||||
} else if input.len() == 1 {
|
} else if input.len() == 1 {
|
||||||
input
|
input
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct ToJSON;
|
pub struct ToJSON;
|
||||||
|
@ -48,7 +48,7 @@ pub fn value_to_json_value(v: &Tagged<Value>) -> Result<serde_json::Value, Shell
|
||||||
Value::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
|
Value::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
|
||||||
Value::Primitive(Primitive::Path(s)) => serde_json::Value::String(s.display().to_string()),
|
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::Block(_) => serde_json::Value::Null,
|
||||||
Value::Binary(b) => serde_json::Value::Array(
|
Value::Binary(b) => serde_json::Value::Array(
|
||||||
b.iter()
|
b.iter()
|
||||||
|
@ -57,7 +57,7 @@ pub fn value_to_json_value(v: &Tagged<Value>) -> Result<serde_json::Value, Shell
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
Value::Object(o) => {
|
Value::Row(o) => {
|
||||||
let mut m = serde_json::Map::new();
|
let mut m = serde_json::Map::new();
|
||||||
for (k, v) in o.entries.iter() {
|
for (k, v) in o.entries.iter() {
|
||||||
m.insert(k.clone(), value_to_json_value(v)?);
|
m.insert(k.clone(), value_to_json_value(v)?);
|
||||||
|
@ -85,7 +85,7 @@ fn to_json(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
|
||||||
|
|
||||||
let to_process_input = if input.len() > 1 {
|
let to_process_input = if input.len() > 1 {
|
||||||
let tag = input[0].tag;
|
let tag = input[0].tag;
|
||||||
vec![Tagged { item: Value::List(input), tag } ]
|
vec![Tagged { item: Value::Table(input), tag } ]
|
||||||
} else if input.len() == 1 {
|
} else if input.len() == 1 {
|
||||||
input
|
input
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Dictionary, Primitive, Value};
|
use crate::data::{Dictionary, Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use hex::encode;
|
use hex::encode;
|
||||||
use rusqlite::{Connection, NO_PARAMS};
|
use rusqlite::{Connection, NO_PARAMS};
|
||||||
|
@ -71,7 +71,7 @@ fn comma_concat(acc: String, current: String) -> String {
|
||||||
|
|
||||||
fn get_columns(rows: &Vec<Tagged<Value>>) -> Result<String, std::io::Error> {
|
fn get_columns(rows: &Vec<Tagged<Value>>) -> Result<String, std::io::Error> {
|
||||||
match &rows[0].item {
|
match &rows[0].item {
|
||||||
Value::Object(d) => Ok(d
|
Value::Row(d) => Ok(d
|
||||||
.entries
|
.entries
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(k, _v)| k.clone())
|
.map(|(k, _v)| k.clone())
|
||||||
|
@ -107,7 +107,7 @@ fn get_insert_values(rows: Vec<Tagged<Value>>) -> Result<String, std::io::Error>
|
||||||
let values: Result<Vec<_>, _> = rows
|
let values: Result<Vec<_>, _> = rows
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|value| match value.item {
|
.map(|value| match value.item {
|
||||||
Value::Object(d) => Ok(format!(
|
Value::Row(d) => Ok(format!(
|
||||||
"({})",
|
"({})",
|
||||||
d.entries
|
d.entries
|
||||||
.iter()
|
.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") {
|
let (columns, insert_values) = match table.entries.get("table_values") {
|
||||||
Some(Tagged {
|
Some(Tagged {
|
||||||
item: Value::List(l),
|
item: Value::Table(l),
|
||||||
..
|
..
|
||||||
}) => (get_columns(l), get_insert_values(l.to_vec())),
|
}) => (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();
|
let tag = values[0].tag.clone();
|
||||||
for value in values.into_iter() {
|
for value in values.into_iter() {
|
||||||
match value.item() {
|
match value.item() {
|
||||||
Value::Object(d) => {
|
Value::Row(d) => {
|
||||||
let (create, insert) = generate_statements(d.to_owned())?;
|
let (create, insert) = generate_statements(d.to_owned())?;
|
||||||
match conn
|
match conn
|
||||||
.execute(&create, NO_PARAMS)
|
.execute(&create, NO_PARAMS)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct ToTOML;
|
pub struct ToTOML;
|
||||||
|
@ -47,12 +47,12 @@ pub fn value_to_toml_value(v: &Tagged<Value>) -> Result<toml::Value, ShellError>
|
||||||
Value::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
|
Value::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
|
||||||
Value::Primitive(Primitive::Path(s)) => toml::Value::String(s.display().to_string()),
|
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("<Block>".to_string()),
|
Value::Block(_) => toml::Value::String("<Block>".to_string()),
|
||||||
Value::Binary(b) => {
|
Value::Binary(b) => {
|
||||||
toml::Value::Array(b.iter().map(|x| toml::Value::Integer(*x as i64)).collect())
|
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();
|
let mut m = toml::map::Map::new();
|
||||||
for (k, v) in o.entries.iter() {
|
for (k, v) in o.entries.iter() {
|
||||||
m.insert(k.clone(), value_to_toml_value(v)?);
|
m.insert(k.clone(), value_to_toml_value(v)?);
|
||||||
|
@ -80,7 +80,7 @@ fn to_toml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
|
||||||
|
|
||||||
let to_process_input = if input.len() > 1 {
|
let to_process_input = if input.len() > 1 {
|
||||||
let tag = input[0].tag;
|
let tag = input[0].tag;
|
||||||
vec![Tagged { item: Value::List(input), tag } ]
|
vec![Tagged { item: Value::Table(input), tag } ]
|
||||||
} else if input.len() == 1 {
|
} else if input.len() == 1 {
|
||||||
input
|
input
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use csv::WriterBuilder;
|
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::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())),
|
||||||
Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(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::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())),
|
||||||
Value::Object(o) => Value::Object(o.clone()),
|
Value::Row(o) => Value::Row(o.clone()),
|
||||||
Value::List(l) => Value::List(l.clone()),
|
Value::Table(l) => Value::Table(l.clone()),
|
||||||
Value::Block(_) => Value::Primitive(Primitive::Nothing),
|
Value::Block(_) => Value::Primitive(Primitive::Nothing),
|
||||||
_ => Value::Primitive(Primitive::Nothing),
|
_ => Value::Primitive(Primitive::Nothing),
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ fn to_string_helper(v: &Value) -> Result<String, ShellError> {
|
||||||
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
|
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
|
||||||
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
|
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
|
||||||
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
|
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
|
||||||
Value::List(_) => return Ok(String::from("[table]")),
|
Value::Table(_) => return Ok(String::from("[table]")),
|
||||||
Value::Object(_) => return Ok(String::from("[row]")),
|
Value::Row(_) => return Ok(String::from("[row]")),
|
||||||
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
|
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
|
||||||
_ => Err(ShellError::string("Unexpected value")),
|
_ => Err(ShellError::string("Unexpected value")),
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
|
||||||
|
|
||||||
pub fn to_string(v: &Value) -> Result<String, ShellError> {
|
pub fn to_string(v: &Value) -> Result<String, ShellError> {
|
||||||
match v {
|
match v {
|
||||||
Value::Object(o) => {
|
Value::Row(o) => {
|
||||||
let mut wtr = WriterBuilder::new().delimiter(b'\t').from_writer(vec![]);
|
let mut wtr = WriterBuilder::new().delimiter(b'\t').from_writer(vec![]);
|
||||||
let mut fields: VecDeque<String> = VecDeque::new();
|
let mut fields: VecDeque<String> = VecDeque::new();
|
||||||
let mut values: VecDeque<String> = VecDeque::new();
|
let mut values: VecDeque<String> = VecDeque::new();
|
||||||
|
@ -91,7 +91,7 @@ pub fn to_string(v: &Value) -> Result<String, ShellError> {
|
||||||
)
|
)
|
||||||
.map_err(|_| ShellError::string("Could not convert record"))?);
|
.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 mut wtr = WriterBuilder::new().delimiter(b'\t').from_writer(vec![]);
|
||||||
|
|
||||||
let merged_descriptors = merge_descriptors(&list);
|
let merged_descriptors = merge_descriptors(&list);
|
||||||
|
@ -133,7 +133,7 @@ fn to_tsv(
|
||||||
|
|
||||||
let to_process_input = if input.len() > 1 {
|
let to_process_input = if input.len() > 1 {
|
||||||
let tag = input[0].tag;
|
let tag = input[0].tag;
|
||||||
vec![Tagged { item: Value::List(input), tag } ]
|
vec![Tagged { item: Value::Table(input), tag } ]
|
||||||
} else if input.len() == 1 {
|
} else if input.len() == 1 {
|
||||||
input
|
input
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct ToYAML;
|
pub struct ToYAML;
|
||||||
|
@ -45,7 +45,7 @@ pub fn value_to_yaml_value(v: &Tagged<Value>) -> Result<serde_yaml::Value, Shell
|
||||||
Value::Primitive(Primitive::String(s)) => serde_yaml::Value::String(s.clone()),
|
Value::Primitive(Primitive::String(s)) => serde_yaml::Value::String(s.clone()),
|
||||||
Value::Primitive(Primitive::Path(s)) => serde_yaml::Value::String(s.display().to_string()),
|
Value::Primitive(Primitive::Path(s)) => serde_yaml::Value::String(s.display().to_string()),
|
||||||
|
|
||||||
Value::List(l) => {
|
Value::Table(l) => {
|
||||||
let mut out = vec![];
|
let mut out = vec![];
|
||||||
|
|
||||||
for value in l {
|
for value in l {
|
||||||
|
@ -60,7 +60,7 @@ pub fn value_to_yaml_value(v: &Tagged<Value>) -> Result<serde_yaml::Value, Shell
|
||||||
.map(|x| serde_yaml::Value::Number(serde_yaml::Number::from(*x)))
|
.map(|x| serde_yaml::Value::Number(serde_yaml::Number::from(*x)))
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
Value::Object(o) => {
|
Value::Row(o) => {
|
||||||
let mut m = serde_yaml::Mapping::new();
|
let mut m = serde_yaml::Mapping::new();
|
||||||
for (k, v) in o.entries.iter() {
|
for (k, v) in o.entries.iter() {
|
||||||
m.insert(
|
m.insert(
|
||||||
|
@ -81,7 +81,7 @@ fn to_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
|
||||||
|
|
||||||
let to_process_input = if input.len() > 1 {
|
let to_process_input = if input.len() > 1 {
|
||||||
let tag = input[0].tag;
|
let tag = input[0].tag;
|
||||||
vec![Tagged { item: Value::List(input), tag } ]
|
vec![Tagged { item: Value::Table(input), tag } ]
|
||||||
} else if input.len() == 1 {
|
} else if input.len() == 1 {
|
||||||
input
|
input
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::Value;
|
use crate::data::Value;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Trim;
|
pub struct Trim;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Dictionary, Value};
|
use crate::data::{Dictionary, Value};
|
||||||
use crate::parser::registry::Signature;
|
use crate::parser::registry::Signature;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
@ -39,6 +39,6 @@ pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
|
||||||
Tagged::from_simple_spanned_item(Value::string(clap::crate_version!()), span),
|
Tagged::from_simple_spanned_item(Value::string(clap::crate_version!()), span),
|
||||||
);
|
);
|
||||||
|
|
||||||
let value = Tagged::from_simple_spanned_item(Value::Object(Dictionary::from(indexmap)), span);
|
let value = Tagged::from_simple_spanned_item(Value::Row(Dictionary::from(indexmap)), span);
|
||||||
Ok(OutputStream::one(value))
|
Ok(OutputStream::one(value))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::Value;
|
use crate::data::Value;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
|
use crate::data::TaggedDictBuilder;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::evaluate::{evaluate_baseline_expr, Scope};
|
use crate::evaluate::{evaluate_baseline_expr, Scope};
|
||||||
use crate::object::TaggedDictBuilder;
|
|
||||||
use crate::parser::{hir, Operator};
|
use crate::parser::{hir, Operator};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::Text;
|
use crate::Text;
|
||||||
|
@ -170,10 +170,10 @@ impl Block {
|
||||||
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Serialize, Deserialize)]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
Primitive(Primitive),
|
Primitive(Primitive),
|
||||||
Object(crate::object::Dictionary),
|
Row(crate::data::Dictionary),
|
||||||
#[serde(with = "serde_bytes")]
|
#[serde(with = "serde_bytes")]
|
||||||
Binary(Vec<u8>),
|
Binary(Vec<u8>),
|
||||||
List(Vec<Tagged<Value>>),
|
Table(Vec<Tagged<Value>>),
|
||||||
|
|
||||||
Block(Block),
|
Block(Block),
|
||||||
}
|
}
|
||||||
|
@ -220,8 +220,8 @@ impl fmt::Debug for ValueDebug<'_> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self.value.item() {
|
match self.value.item() {
|
||||||
Value::Primitive(p) => p.debug(f),
|
Value::Primitive(p) => p.debug(f),
|
||||||
Value::Object(o) => o.debug(f),
|
Value::Row(o) => o.debug(f),
|
||||||
Value::List(l) => debug_list(l).fmt(f),
|
Value::Table(l) => debug_list(l).fmt(f),
|
||||||
Value::Block(_) => write!(f, "[[block]]"),
|
Value::Block(_) => write!(f, "[[block]]"),
|
||||||
Value::Binary(_) => write!(f, "[[binary]]"),
|
Value::Binary(_) => write!(f, "[[binary]]"),
|
||||||
}
|
}
|
||||||
|
@ -293,12 +293,12 @@ impl std::convert::TryFrom<&Tagged<Value>> for Vec<u8> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> std::convert::TryFrom<&'a Tagged<Value>> for &'a crate::object::Dictionary {
|
impl<'a> std::convert::TryFrom<&'a Tagged<Value>> for &'a crate::data::Dictionary {
|
||||||
type Error = ShellError;
|
type Error = ShellError;
|
||||||
|
|
||||||
fn try_from(value: &'a Tagged<Value>) -> Result<&'a crate::object::Dictionary, ShellError> {
|
fn try_from(value: &'a Tagged<Value>) -> Result<&'a crate::data::Dictionary, ShellError> {
|
||||||
match value.item() {
|
match value.item() {
|
||||||
Value::Object(d) => Ok(d),
|
Value::Row(d) => Ok(d),
|
||||||
v => Err(ShellError::type_error(
|
v => Err(ShellError::type_error(
|
||||||
"Dictionary",
|
"Dictionary",
|
||||||
value.copy_span(v.type_name()),
|
value.copy_span(v.type_name()),
|
||||||
|
@ -340,8 +340,8 @@ impl Value {
|
||||||
pub(crate) fn type_name(&self) -> String {
|
pub(crate) fn type_name(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Value::Primitive(p) => p.type_name(),
|
Value::Primitive(p) => p.type_name(),
|
||||||
Value::Object(_) => format!("object"),
|
Value::Row(_) => format!("object"),
|
||||||
Value::List(_) => format!("list"),
|
Value::Table(_) => format!("list"),
|
||||||
Value::Block(_) => format!("block"),
|
Value::Block(_) => format!("block"),
|
||||||
Value::Binary(_) => format!("binary"),
|
Value::Binary(_) => format!("binary"),
|
||||||
}
|
}
|
||||||
|
@ -351,26 +351,26 @@ impl Value {
|
||||||
pub fn data_descriptors(&self) -> Vec<String> {
|
pub fn data_descriptors(&self) -> Vec<String> {
|
||||||
match self {
|
match self {
|
||||||
Value::Primitive(_) => vec![],
|
Value::Primitive(_) => vec![],
|
||||||
Value::Object(o) => o
|
Value::Row(o) => o
|
||||||
.entries
|
.entries
|
||||||
.keys()
|
.keys()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
Value::Block(_) => vec![],
|
Value::Block(_) => vec![],
|
||||||
Value::List(_) => vec![],
|
Value::Table(_) => vec![],
|
||||||
Value::Binary(_) => vec![],
|
Value::Binary(_) => vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_data_by_key(&self, name: &str) -> Option<&Tagged<Value>> {
|
pub(crate) fn get_data_by_key(&self, name: &str) -> Option<&Tagged<Value>> {
|
||||||
match self {
|
match self {
|
||||||
Value::Object(o) => o.get_data_by_key(name),
|
Value::Row(o) => o.get_data_by_key(name),
|
||||||
Value::List(l) => {
|
Value::Table(l) => {
|
||||||
for item in l {
|
for item in l {
|
||||||
match item {
|
match item {
|
||||||
Tagged {
|
Tagged {
|
||||||
item: Value::Object(o),
|
item: Value::Row(o),
|
||||||
..
|
..
|
||||||
} => match o.get_data_by_key(name) {
|
} => match o.get_data_by_key(name) {
|
||||||
Some(v) => return Some(v),
|
Some(v) => return Some(v),
|
||||||
|
@ -407,7 +407,7 @@ impl Value {
|
||||||
|
|
||||||
let split_path: Vec<_> = path.split(".").collect();
|
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;
|
let mut current = o;
|
||||||
|
|
||||||
if split_path.len() == 1 {
|
if split_path.len() == 1 {
|
||||||
|
@ -423,7 +423,7 @@ impl Value {
|
||||||
Some(next) => {
|
Some(next) => {
|
||||||
if idx == (split_path.len() - 2) {
|
if idx == (split_path.len() - 2) {
|
||||||
match &mut next.item {
|
match &mut next.item {
|
||||||
Value::Object(o) => {
|
Value::Row(o) => {
|
||||||
o.entries.insert(
|
o.entries.insert(
|
||||||
split_path[idx + 1].to_string(),
|
split_path[idx + 1].to_string(),
|
||||||
Tagged::from_item(new_value, tag),
|
Tagged::from_item(new_value, tag),
|
||||||
|
@ -435,7 +435,7 @@ impl Value {
|
||||||
return Some(Tagged::from_item(new_obj, tag));
|
return Some(Tagged::from_item(new_obj, tag));
|
||||||
} else {
|
} else {
|
||||||
match next.item {
|
match next.item {
|
||||||
Value::Object(ref mut o) => {
|
Value::Row(ref mut o) => {
|
||||||
current = o;
|
current = o;
|
||||||
}
|
}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
|
@ -460,7 +460,7 @@ impl Value {
|
||||||
|
|
||||||
let split_path: Vec<_> = path.split(".").collect();
|
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;
|
let mut current = o;
|
||||||
for idx in 0..split_path.len() {
|
for idx in 0..split_path.len() {
|
||||||
match current.entries.get_mut(split_path[idx]) {
|
match current.entries.get_mut(split_path[idx]) {
|
||||||
|
@ -470,7 +470,7 @@ impl Value {
|
||||||
return Some(Tagged::from_item(new_obj, tag));
|
return Some(Tagged::from_item(new_obj, tag));
|
||||||
} else {
|
} else {
|
||||||
match next.item {
|
match next.item {
|
||||||
Value::Object(ref mut o) => {
|
Value::Row(ref mut o) => {
|
||||||
current = o;
|
current = o;
|
||||||
}
|
}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
|
@ -488,9 +488,9 @@ impl Value {
|
||||||
pub fn get_data(&self, desc: &String) -> MaybeOwned<'_, Value> {
|
pub fn get_data(&self, desc: &String) -> MaybeOwned<'_, Value> {
|
||||||
match self {
|
match self {
|
||||||
p @ Value::Primitive(_) => MaybeOwned::Borrowed(p),
|
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::Block(_) => MaybeOwned::Owned(Value::nothing()),
|
||||||
Value::List(_) => MaybeOwned::Owned(Value::nothing()),
|
Value::Table(_) => MaybeOwned::Owned(Value::nothing()),
|
||||||
Value::Binary(_) => MaybeOwned::Owned(Value::nothing()),
|
Value::Binary(_) => MaybeOwned::Owned(Value::nothing()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -504,8 +504,8 @@ impl Value {
|
||||||
.map(|e| e.source(&b.source).to_string()),
|
.map(|e| e.source(&b.source).to_string()),
|
||||||
"; ",
|
"; ",
|
||||||
),
|
),
|
||||||
Value::Object(_) => format!("[table: 1 row]"),
|
Value::Row(_) => format!("[table: 1 row]"),
|
||||||
Value::List(l) => format!(
|
Value::Table(l) => format!(
|
||||||
"[table: {} {}]",
|
"[table: {} {}]",
|
||||||
l.len(),
|
l.len(),
|
||||||
if l.len() == 1 { "row" } else { "rows" }
|
if l.len() == 1 { "row" } else { "rows" }
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::commands::command::Command;
|
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::parser::registry::{NamedType, PositionalType, Signature};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
@ -32,7 +32,10 @@ fn for_spec(name: &str, ty: &str, required: bool, tag: impl Into<Tag>) -> Tagged
|
||||||
|
|
||||||
spec.insert("name", Value::string(name));
|
spec.insert("name", Value::string(name));
|
||||||
spec.insert("type", Value::string(ty));
|
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()
|
spec.into_tagged_value()
|
||||||
}
|
}
|
||||||
|
@ -43,8 +46,8 @@ fn signature_dict(signature: Signature, tag: impl Into<Tag>) -> Tagged<Value> {
|
||||||
|
|
||||||
for arg in signature.positional.iter() {
|
for arg in signature.positional.iter() {
|
||||||
let is_required = match arg {
|
let is_required = match arg {
|
||||||
PositionalType::Mandatory(_,_) => true,
|
PositionalType::Mandatory(_, _) => true,
|
||||||
PositionalType::Optional(_,_) => false,
|
PositionalType::Optional(_, _) => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
sig.insert_tagged(for_spec(arg.name(), "argument", is_required, tag));
|
sig.insert_tagged(for_spec(arg.name(), "argument", is_required, tag));
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::commands::from_toml::convert_toml_value_to_nu_value;
|
use crate::commands::from_toml::convert_toml_value_to_nu_value;
|
||||||
use crate::commands::to_toml::value_to_toml_value;
|
use crate::commands::to_toml::value_to_toml_value;
|
||||||
|
use crate::data::{Dictionary, Value};
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Dictionary, Value};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use app_dirs::*;
|
use app_dirs::*;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
@ -37,7 +37,7 @@ pub(crate) fn write_config(config: &IndexMap<String, Tagged<Value>>) -> Result<(
|
||||||
touch(&filename)?;
|
touch(&filename)?;
|
||||||
|
|
||||||
let contents =
|
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)?;
|
let contents = toml::to_string(&contents)?;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ pub(crate) fn config(span: impl Into<Span>) -> Result<IndexMap<String, Tagged<Va
|
||||||
let value = convert_toml_value_to_nu_value(&parsed, Tag::unknown_origin(span));
|
let value = convert_toml_value_to_nu_value(&parsed, Tag::unknown_origin(span));
|
||||||
let tag = value.tag();
|
let tag = value.tag();
|
||||||
match value.item {
|
match value.item {
|
||||||
Value::Object(Dictionary { entries }) => Ok(entries),
|
Value::Row(Dictionary { entries }) => Ok(entries),
|
||||||
other => Err(ShellError::type_error(
|
other => Err(ShellError::type_error(
|
||||||
"Dictionary",
|
"Dictionary",
|
||||||
other.type_name().tagged(tag),
|
other.type_name().tagged(tag),
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::data::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::object::{Primitive, Value};
|
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -64,7 +64,7 @@ impl PartialOrd<Value> for Dictionary {
|
||||||
impl PartialEq<Value> for Dictionary {
|
impl PartialEq<Value> for Dictionary {
|
||||||
fn eq(&self, other: &Value) -> bool {
|
fn eq(&self, other: &Value) -> bool {
|
||||||
match other {
|
match other {
|
||||||
Value::Object(d) => self == d,
|
Value::Row(d) => self == d,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ impl TaggedListBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_tagged_value(self) -> Tagged<Value> {
|
pub fn into_tagged_value(self) -> Tagged<Value> {
|
||||||
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<Value> {
|
pub fn into_tagged_value(self) -> Tagged<Value> {
|
||||||
self.into_tagged_dict().map(Value::Object)
|
self.into_tagged_dict().map(Value::Row)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_tagged_dict(self) -> Tagged<Dictionary> {
|
pub fn into_tagged_dict(self) -> Tagged<Dictionary> {
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::data::{TaggedDictBuilder, Value};
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{TaggedDictBuilder, Value};
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::object::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
impl From<Primitive> for Value {
|
impl From<Primitive> for Value {
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::object::{TaggedDictBuilder, Value};
|
use crate::data::{TaggedDictBuilder, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use itertools::join;
|
use itertools::join;
|
||||||
use sysinfo::ProcessExt;
|
use sysinfo::ProcessExt;
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::data::base::Block;
|
||||||
use crate::errors::Description;
|
use crate::errors::Description;
|
||||||
use crate::object::base::Block;
|
|
||||||
use crate::parser::{
|
use crate::parser::{
|
||||||
hir::{self, Expression, RawExpression},
|
hir::{self, Expression, RawExpression},
|
||||||
CommandRegistry, Text,
|
CommandRegistry, Text,
|
||||||
|
@ -66,7 +66,7 @@ pub(crate) fn evaluate_baseline_expr(
|
||||||
exprs.push(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(
|
RawExpression::Block(block) => Ok(Tagged::from_simple_spanned_item(
|
||||||
Value::Block(Block::new(block.clone(), source.clone(), expr.span())),
|
Value::Block(Block::new(block.clone(), source.clone(), expr.span())),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::data::Value;
|
||||||
use crate::format::{EntriesView, RenderView, TableView};
|
use crate::format::{EntriesView, RenderView, TableView};
|
||||||
use crate::object::Value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ impl RenderView for GenericView<'_> {
|
||||||
fn render_view(&self, host: &mut dyn Host) -> Result<(), ShellError> {
|
fn render_view(&self, host: &mut dyn Host) -> Result<(), ShellError> {
|
||||||
match self.value {
|
match self.value {
|
||||||
Value::Primitive(p) => Ok(host.stdout(&p.format(None))),
|
Value::Primitive(p) => Ok(host.stdout(&p.format(None))),
|
||||||
Value::List(l) => {
|
Value::Table(l) => {
|
||||||
let view = TableView::from_list(l);
|
let view = TableView::from_list(l);
|
||||||
|
|
||||||
if let Some(view) = view {
|
if let Some(view) = view {
|
||||||
|
@ -23,7 +23,7 @@ impl RenderView for GenericView<'_> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
o @ Value::Object(_) => {
|
o @ Value::Row(_) => {
|
||||||
let view = EntriesView::from_value(o);
|
let view = EntriesView::from_value(o);
|
||||||
view.render_view(host)?;
|
view.render_view(host)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::data::Value;
|
||||||
use crate::format::RenderView;
|
use crate::format::RenderView;
|
||||||
use crate::object::Value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use textwrap::fill;
|
use textwrap::fill;
|
||||||
|
@ -45,7 +45,7 @@ impl TableView {
|
||||||
for (idx, value) in values.iter().enumerate() {
|
for (idx, value) in values.iter().enumerate() {
|
||||||
let mut row: Vec<(String, &'static str)> = match value {
|
let mut row: Vec<(String, &'static str)> = match value {
|
||||||
Tagged {
|
Tagged {
|
||||||
item: Value::Object(..),
|
item: Value::Row(..),
|
||||||
..
|
..
|
||||||
} => headers
|
} => headers
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::data::Value;
|
||||||
use crate::format::RenderView;
|
use crate::format::RenderView;
|
||||||
use crate::object::Value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,12 @@ mod prelude;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod context;
|
mod context;
|
||||||
|
mod data;
|
||||||
mod env;
|
mod env;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod evaluate;
|
mod evaluate;
|
||||||
mod format;
|
mod format;
|
||||||
mod git;
|
mod git;
|
||||||
mod object;
|
|
||||||
mod parser;
|
mod parser;
|
||||||
mod plugin;
|
mod plugin;
|
||||||
mod shell;
|
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::plugin::{serve_plugin, Plugin};
|
||||||
pub use crate::utils::{AbsoluteFile, AbsolutePath, RelativePath};
|
pub use crate::utils::{AbsoluteFile, AbsolutePath, RelativePath};
|
||||||
pub use cli::cli;
|
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 errors::{CoerceInto, ShellError};
|
||||||
pub use num_traits::cast::ToPrimitive;
|
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::parse::text::Text;
|
||||||
pub use parser::registry::{EvaluatedArgs, NamedType, PositionalType, Signature};
|
pub use parser::registry::{EvaluatedArgs, NamedType, PositionalType, Signature};
|
||||||
|
|
|
@ -37,7 +37,7 @@ impl<'de> ConfigDeserializer<'de> {
|
||||||
let value: Option<Tagged<Value>> = if name == "rest" {
|
let value: Option<Tagged<Value>> = if name == "rest" {
|
||||||
let positional = self.call.args.slice_from(self.position);
|
let positional = self.call.args.slice_from(self.position);
|
||||||
self.position += positional.len();
|
self.position += positional.len();
|
||||||
Some(Value::List(positional).tagged_unknown()) // TODO: correct span
|
Some(Value::Table(positional).tagged_unknown()) // TODO: correct span
|
||||||
} else {
|
} else {
|
||||||
if self.call.args.has(name) {
|
if self.call.args.has(name) {
|
||||||
self.call.args.get(name).map(|x| x.clone())
|
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!("<Vec> Extracting {:?} for vec", value.val);
|
trace!("<Vec> Extracting {:?} for vec", value.val);
|
||||||
|
|
||||||
match value.val.into_parts() {
|
match value.val.into_parts() {
|
||||||
(Value::List(items), _) => {
|
(Value::Table(items), _) => {
|
||||||
let de = SeqDeserializer::new(&mut self, items.into_iter());
|
let de = SeqDeserializer::new(&mut self, items.into_iter());
|
||||||
visitor.visit_seq(de)
|
visitor.visit_seq(de)
|
||||||
}
|
}
|
||||||
(other, tag) => Err(ShellError::type_error(
|
(other, tag) => Err(ShellError::type_error("Vec", other.type_name().tagged(tag))),
|
||||||
"Vec",
|
|
||||||
other.type_name().tagged(tag),
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn deserialize_tuple<V>(mut self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_tuple<V>(mut self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
@ -255,10 +252,14 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
let value = self.pop();
|
let value = self.pop();
|
||||||
trace!("<Tuple> Extracting {:?} for tuple with {} elements", value.val, len);
|
trace!(
|
||||||
|
"<Tuple> Extracting {:?} for tuple with {} elements",
|
||||||
|
value.val,
|
||||||
|
len
|
||||||
|
);
|
||||||
|
|
||||||
match value.val.into_parts() {
|
match value.val.into_parts() {
|
||||||
(Value::List(items), _) => {
|
(Value::Table(items), _) => {
|
||||||
let de = SeqDeserializer::new(&mut self, items.into_iter());
|
let de = SeqDeserializer::new(&mut self, items.into_iter());
|
||||||
visitor.visit_seq(de)
|
visitor.visit_seq(de)
|
||||||
}
|
}
|
||||||
|
@ -298,7 +299,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
|
||||||
val: T,
|
val: T,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
fields: &'static [&'static str],
|
fields: &'static [&'static str],
|
||||||
visitor: V
|
visitor: V,
|
||||||
) -> Result<V::Value, ShellError>
|
) -> Result<V::Value, ShellError>
|
||||||
where
|
where
|
||||||
T: serde::Serialize,
|
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")?;
|
let i: i64 = int.tagged(value.val.tag).coerce_into("converting to i64")?;
|
||||||
visit::<Tagged<i64>, _>(i.tagged(tag), name, fields, visitor)
|
visit::<Tagged<i64>, _>(i.tagged(tag), name, fields, visitor)
|
||||||
},
|
}
|
||||||
Tagged {
|
Tagged {
|
||||||
item: Value::Primitive(Primitive::String(string)),
|
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<Item=Tagged<Value>>> {
|
struct SeqDeserializer<'a, 'de: 'a, I: Iterator<Item = Tagged<Value>>> {
|
||||||
de: &'a mut ConfigDeserializer<'de>,
|
de: &'a mut ConfigDeserializer<'de>,
|
||||||
vals: I,
|
vals: I,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'de: 'a, I: Iterator<Item=Tagged<Value>>> SeqDeserializer<'a, 'de, I> {
|
impl<'a, 'de: 'a, I: Iterator<Item = Tagged<Value>>> SeqDeserializer<'a, 'de, I> {
|
||||||
fn new(de: &'a mut ConfigDeserializer<'de>, vals: I) -> Self {
|
fn new(de: &'a mut ConfigDeserializer<'de>, vals: I) -> Self {
|
||||||
SeqDeserializer {
|
SeqDeserializer { de, vals }
|
||||||
de,
|
|
||||||
vals,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'de: 'a, I: Iterator<Item=Tagged<Value>>> de::SeqAccess<'de> for SeqDeserializer<'a, 'de, I> {
|
impl<'a, 'de: 'a, I: Iterator<Item = Tagged<Value>>> de::SeqAccess<'de>
|
||||||
|
for SeqDeserializer<'a, 'de, I>
|
||||||
|
{
|
||||||
type Error = ShellError;
|
type Error = ShellError;
|
||||||
|
|
||||||
fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||||
|
@ -441,10 +441,7 @@ struct StructDeserializer<'a, 'de: 'a> {
|
||||||
|
|
||||||
impl<'a, 'de: 'a> StructDeserializer<'a, 'de> {
|
impl<'a, 'de: 'a> StructDeserializer<'a, 'de> {
|
||||||
fn new(de: &'a mut ConfigDeserializer<'de>, fields: &'static [&'static str]) -> Self {
|
fn new(de: &'a mut ConfigDeserializer<'de>, fields: &'static [&'static str]) -> Self {
|
||||||
StructDeserializer {
|
StructDeserializer { de, fields }
|
||||||
de,
|
|
||||||
fields,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::object::base::Value;
|
use crate::data::base::Value;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl Add {
|
||||||
fn add(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
|
fn add(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
|
||||||
let value_tag = value.tag();
|
let value_tag = value.tag();
|
||||||
match (value.item, self.value.clone()) {
|
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(f) => match obj.insert_data_at_path(value_tag, &f, v) {
|
||||||
Some(v) => return Ok(v),
|
Some(v) => return Ok(v),
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl Edit {
|
||||||
fn edit(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
|
fn edit(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
|
||||||
let value_tag = value.tag();
|
let value_tag = value.tag();
|
||||||
match (value.item, self.value.clone()) {
|
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(f) => match obj.replace_data_at_path(value_tag, &f, v) {
|
||||||
Some(v) => return Ok(v),
|
Some(v) => return Ok(v),
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl Plugin for Embed {
|
||||||
root.insert_tagged(
|
root.insert_tagged(
|
||||||
self.field.as_ref().unwrap(),
|
self.field.as_ref().unwrap(),
|
||||||
Tagged {
|
Tagged {
|
||||||
item: Value::List(self.values.clone()),
|
item: Value::Table(self.values.clone()),
|
||||||
tag: Tag::unknown(),
|
tag: Tag::unknown(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl Inc {
|
||||||
Value::Primitive(Primitive::String(ref s)) => {
|
Value::Primitive(Primitive::String(ref s)) => {
|
||||||
Ok(Tagged::from_item(self.apply(&s)?, value.tag()))
|
Ok(Tagged::from_item(self.apply(&s)?, value.tag()))
|
||||||
}
|
}
|
||||||
Value::Object(_) => match self.field {
|
Value::Row(_) => match self.field {
|
||||||
Some(ref f) => {
|
Some(ref f) => {
|
||||||
let replacement = match value.item.get_data_by_path(value.tag(), f) {
|
let replacement = match value.item.get_data_by_path(value.tag(), f) {
|
||||||
Some(result) => self.inc(result.map(|x| x.clone()))?,
|
Some(result) => self.inc(result.map(|x| x.clone()))?,
|
||||||
|
@ -333,7 +333,7 @@ mod tests {
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
match output[0].as_ref().unwrap() {
|
||||||
ReturnSuccess::Value(Tagged {
|
ReturnSuccess::Value(Tagged {
|
||||||
item: Value::Object(o),
|
item: Value::Row(o),
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("version")).borrow(),
|
*o.get_data(&String::from("version")).borrow(),
|
||||||
|
@ -361,7 +361,7 @@ mod tests {
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
match output[0].as_ref().unwrap() {
|
||||||
ReturnSuccess::Value(Tagged {
|
ReturnSuccess::Value(Tagged {
|
||||||
item: Value::Object(o),
|
item: Value::Row(o),
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("version")).borrow(),
|
*o.get_data(&String::from("version")).borrow(),
|
||||||
|
@ -390,7 +390,7 @@ mod tests {
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
match output[0].as_ref().unwrap() {
|
||||||
ReturnSuccess::Value(Tagged {
|
ReturnSuccess::Value(Tagged {
|
||||||
item: Value::Object(o),
|
item: Value::Row(o),
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&field).borrow(),
|
*o.get_data(&field).borrow(),
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl Str {
|
||||||
Value::Primitive(Primitive::String(ref s)) => {
|
Value::Primitive(Primitive::String(ref s)) => {
|
||||||
Ok(Tagged::from_item(self.apply(&s)?, value.tag()))
|
Ok(Tagged::from_item(self.apply(&s)?, value.tag()))
|
||||||
}
|
}
|
||||||
Value::Object(_) => match self.field {
|
Value::Row(_) => match self.field {
|
||||||
Some(ref f) => {
|
Some(ref f) => {
|
||||||
let replacement = match value.item.get_data_by_path(value.tag(), f) {
|
let replacement = match value.item.get_data_by_path(value.tag(), f) {
|
||||||
Some(result) => self.strutils(result.map(|x| x.clone()))?,
|
Some(result) => self.strutils(result.map(|x| x.clone()))?,
|
||||||
|
@ -479,7 +479,7 @@ mod tests {
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
match output[0].as_ref().unwrap() {
|
||||||
ReturnSuccess::Value(Tagged {
|
ReturnSuccess::Value(Tagged {
|
||||||
item: Value::Object(o),
|
item: Value::Row(o),
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("name")).borrow(),
|
*o.get_data(&String::from("name")).borrow(),
|
||||||
|
@ -527,7 +527,7 @@ mod tests {
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
match output[0].as_ref().unwrap() {
|
||||||
ReturnSuccess::Value(Tagged {
|
ReturnSuccess::Value(Tagged {
|
||||||
item: Value::Object(o),
|
item: Value::Row(o),
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("name")).borrow(),
|
*o.get_data(&String::from("name")).borrow(),
|
||||||
|
@ -575,7 +575,7 @@ mod tests {
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
match output[0].as_ref().unwrap() {
|
||||||
ReturnSuccess::Value(Tagged {
|
ReturnSuccess::Value(Tagged {
|
||||||
item: Value::Object(o),
|
item: Value::Row(o),
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("Nu_birthday")).borrow(),
|
*o.get_data(&String::from("Nu_birthday")).borrow(),
|
||||||
|
@ -624,7 +624,7 @@ mod tests {
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
match output[0].as_ref().unwrap() {
|
||||||
ReturnSuccess::Value(Tagged {
|
ReturnSuccess::Value(Tagged {
|
||||||
item: Value::Object(o),
|
item: Value::Row(o),
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("rustconf")).borrow(),
|
*o.get_data(&String::from("rustconf")).borrow(),
|
||||||
|
@ -679,7 +679,7 @@ mod tests {
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
match output[0].as_ref().unwrap() {
|
||||||
ReturnSuccess::Value(Tagged {
|
ReturnSuccess::Value(Tagged {
|
||||||
item: Value::Object(o),
|
item: Value::Row(o),
|
||||||
..
|
..
|
||||||
}) => assert_eq!(
|
}) => assert_eq!(
|
||||||
*o.get_data(&String::from("staff")).borrow(),
|
*o.get_data(&String::from("staff")).borrow(),
|
||||||
|
|
|
@ -119,7 +119,7 @@ async fn host(tag: Tag) -> Tagged<Value> {
|
||||||
user_vec.push(Tagged::from_item(Value::string(user.username()), tag));
|
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.insert("users", user_list);
|
||||||
|
|
||||||
dict.into_tagged_value()
|
dict.into_tagged_value()
|
||||||
|
@ -163,7 +163,7 @@ async fn disks(tag: Tag) -> Option<Value> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !output.is_empty() {
|
if !output.is_empty() {
|
||||||
Some(Value::List(output))
|
Some(Value::Table(output))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ async fn battery(tag: Tag) -> Option<Value> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !output.is_empty() {
|
if !output.is_empty() {
|
||||||
Some(Value::List(output))
|
Some(Value::Table(output))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ async fn temp(tag: Tag) -> Option<Value> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !output.is_empty() {
|
if !output.is_empty() {
|
||||||
Some(Value::List(output))
|
Some(Value::Table(output))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ async fn net(tag: Tag) -> Option<Value> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !output.is_empty() {
|
if !output.is_empty() {
|
||||||
Some(Value::List(output))
|
Some(Value::Table(output))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,14 @@ impl TreeView {
|
||||||
Value::Primitive(p) => {
|
Value::Primitive(p) => {
|
||||||
let _ = builder.add_empty_child(p.format(None));
|
let _ = builder.add_empty_child(p.format(None));
|
||||||
}
|
}
|
||||||
Value::Object(o) => {
|
Value::Row(o) => {
|
||||||
for (k, v) in o.entries.iter() {
|
for (k, v) in o.entries.iter() {
|
||||||
builder = builder.begin_child(k.clone());
|
builder = builder.begin_child(k.clone());
|
||||||
Self::from_value_helper(v, builder);
|
Self::from_value_helper(v, builder);
|
||||||
builder = builder.end_child();
|
builder = builder.end_child();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::List(l) => {
|
Value::Table(l) => {
|
||||||
for elem in l.iter() {
|
for elem in l.iter() {
|
||||||
Self::from_value_helper(elem, builder);
|
Self::from_value_helper(elem, builder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,20 +55,20 @@ pub(crate) use crate::commands::PerItemCommand;
|
||||||
pub(crate) use crate::commands::RawCommandArgs;
|
pub(crate) use crate::commands::RawCommandArgs;
|
||||||
pub(crate) use crate::context::CommandRegistry;
|
pub(crate) use crate::context::CommandRegistry;
|
||||||
pub(crate) use crate::context::{Context, SpanSource};
|
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::handle_unexpected;
|
||||||
pub(crate) use crate::env::Host;
|
pub(crate) use crate::env::Host;
|
||||||
pub(crate) use crate::errors::{CoerceInto, ShellError};
|
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::hir::SyntaxType;
|
||||||
pub(crate) use crate::parser::parse::parser::Number;
|
pub(crate) use crate::parser::parse::parser::Number;
|
||||||
pub(crate) use crate::parser::registry::Signature;
|
pub(crate) use crate::parser::registry::Signature;
|
||||||
pub(crate) use crate::shell::filesystem_shell::FilesystemShell;
|
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::shell_manager::ShellManager;
|
||||||
pub(crate) use crate::shell::value_shell::ValueShell;
|
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::stream::{InputStream, OutputStream};
|
||||||
pub(crate) use crate::traits::{HasSpan, ToDebug};
|
pub(crate) use crate::traits::{HasSpan, ToDebug};
|
||||||
pub(crate) use crate::Span;
|
pub(crate) use crate::Span;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::commands::mkdir::MkdirArgs;
|
||||||
use crate::commands::mv::MoveArgs;
|
use crate::commands::mv::MoveArgs;
|
||||||
use crate::commands::rm::RemoveArgs;
|
use crate::commands::rm::RemoveArgs;
|
||||||
use crate::context::SourceMap;
|
use crate::context::SourceMap;
|
||||||
use crate::object::dir_entry_dict;
|
use crate::data::dir_entry_dict;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::shell::completer::NuCompleter;
|
use crate::shell::completer::NuCompleter;
|
||||||
use crate::shell::shell::Shell;
|
use crate::shell::shell::Shell;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::commands::mkdir::MkdirArgs;
|
||||||
use crate::commands::mv::MoveArgs;
|
use crate::commands::mv::MoveArgs;
|
||||||
use crate::commands::rm::RemoveArgs;
|
use crate::commands::rm::RemoveArgs;
|
||||||
use crate::context::SourceMap;
|
use crate::context::SourceMap;
|
||||||
use crate::object::{TaggedDictBuilder, command_dict};
|
use crate::data::{command_dict, TaggedDictBuilder};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::shell::shell::Shell;
|
use crate::shell::shell::Shell;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
@ -26,13 +26,16 @@ impl HelpShell {
|
||||||
let value = command_dict(registry.get_command(&cmd).unwrap(), Tag::unknown());
|
let value = command_dict(registry.get_command(&cmd).unwrap(), Tag::unknown());
|
||||||
|
|
||||||
spec.insert("name", cmd);
|
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);
|
spec.insert_tagged("details", value);
|
||||||
|
|
||||||
specs.push(spec.into_tagged_value());
|
specs.push(spec.into_tagged_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
cmds.insert("help", Value::List(specs));
|
cmds.insert("help", Value::Table(specs));
|
||||||
|
|
||||||
Ok(HelpShell {
|
Ok(HelpShell {
|
||||||
path: "/help".to_string(),
|
path: "/help".to_string(),
|
||||||
|
@ -47,8 +50,10 @@ impl HelpShell {
|
||||||
let mut sh = HelpShell::index(®istry)?;
|
let mut sh = HelpShell::index(®istry)?;
|
||||||
|
|
||||||
if let Tagged {
|
if let Tagged {
|
||||||
item: Value::Primitive(Primitive::String(name)), ..
|
item: Value::Primitive(Primitive::String(name)),
|
||||||
} = cmd {
|
..
|
||||||
|
} = cmd
|
||||||
|
{
|
||||||
sh.set_path(format!("/help/{:}/details", name));
|
sh.set_path(format!("/help/{:}/details", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +81,7 @@ impl HelpShell {
|
||||||
}
|
}
|
||||||
match viewed {
|
match viewed {
|
||||||
Tagged {
|
Tagged {
|
||||||
item: Value::List(l),
|
item: Value::Table(l),
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
for item in l {
|
for item in l {
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl ValueShell {
|
||||||
}
|
}
|
||||||
match viewed {
|
match viewed {
|
||||||
Tagged {
|
Tagged {
|
||||||
item: Value::List(l),
|
item: Value::Table(l),
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
for item in l {
|
for item in l {
|
||||||
|
|
12
src/utils.rs
12
src/utils.rs
|
@ -1,6 +1,6 @@
|
||||||
|
use crate::data::meta::Tagged;
|
||||||
|
use crate::data::Value;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::meta::Tagged;
|
|
||||||
use crate::object::Value;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::Div;
|
use std::ops::Div;
|
||||||
use std::path::{Component, Path, PathBuf};
|
use std::path::{Component, Path, PathBuf};
|
||||||
|
@ -150,14 +150,14 @@ impl<'a> Iterator for TaggedValueIter<'a> {
|
||||||
impl Tagged<Value> {
|
impl Tagged<Value> {
|
||||||
fn is_dir(&self) -> bool {
|
fn is_dir(&self) -> bool {
|
||||||
match self.item() {
|
match self.item() {
|
||||||
Value::Object(_) | Value::List(_) => true,
|
Value::Row(_) | Value::Table(_) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn entries(&self) -> TaggedValueIter<'_> {
|
fn entries(&self) -> TaggedValueIter<'_> {
|
||||||
match self.item() {
|
match self.item() {
|
||||||
Value::Object(o) => {
|
Value::Row(o) => {
|
||||||
let iter = o.entries.iter();
|
let iter = o.entries.iter();
|
||||||
TaggedValueIter::List(iter)
|
TaggedValueIter::List(iter)
|
||||||
}
|
}
|
||||||
|
@ -321,8 +321,8 @@ impl FileStructure {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{FileStructure, Res, ValueResource, ValueStructure};
|
use super::{FileStructure, Res, ValueResource, ValueStructure};
|
||||||
use crate::object::meta::{Tag, Tagged};
|
use crate::data::meta::{Tag, Tagged};
|
||||||
use crate::object::{TaggedDictBuilder, Value};
|
use crate::data::{TaggedDictBuilder, Value};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue