mirror of
https://github.com/nushell/nushell
synced 2024-12-28 05:53:09 +00:00
Allow invocations and fix span error reporting.
This commit is contained in:
parent
08d1be79fc
commit
034c33c2b5
8 changed files with 114 additions and 108 deletions
91
Cargo.lock
generated
91
Cargo.lock
generated
|
@ -367,18 +367,17 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "battery"
|
name = "battery"
|
||||||
version = "0.7.5"
|
version = "0.7.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "36a698e449024a5d18994a815998bf5e2e4bc1883e35a7d7ba95b6b69ee45907"
|
checksum = "8775be4956c98c9ac7c11cc383d632636935d3a688dabddb71ac83ba00a3a72f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"core-foundation 0.6.4",
|
"core-foundation",
|
||||||
"lazycell",
|
"lazycell",
|
||||||
"libc",
|
"libc",
|
||||||
"mach 0.2.3",
|
"mach",
|
||||||
"nix 0.15.0",
|
|
||||||
"num-traits 0.2.12",
|
"num-traits 0.2.12",
|
||||||
"uom 0.26.0",
|
"uom 0.29.0",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -857,32 +856,16 @@ dependencies = [
|
||||||
"url 1.7.2",
|
"url 1.7.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "core-foundation"
|
|
||||||
version = "0.6.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d"
|
|
||||||
dependencies = [
|
|
||||||
"core-foundation-sys 0.6.2",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
|
checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"core-foundation-sys 0.7.0",
|
"core-foundation-sys",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "core-foundation-sys"
|
|
||||||
version = "0.6.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation-sys"
|
name = "core-foundation-sys"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
@ -1044,7 +1027,7 @@ version = "3.1.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d0b676fa23f995faf587496dcd1c80fead847ed58d2da52ac1caca9a72790dd2"
|
checksum = "d0b676fa23f995faf587496dcd1c80fead847ed58d2da52ac1caca9a72790dd2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nix 0.17.0",
|
"nix",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1907,13 +1890,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "58d46c2c79530368c7a76e4808ff7263970029f38bcd544a9d43722ed0828527"
|
checksum = "58d46c2c79530368c7a76e4808ff7263970029f38bcd544a9d43722ed0828527"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"core-foundation 0.7.0",
|
"core-foundation",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"lazy_static 1.4.0",
|
"lazy_static 1.4.0",
|
||||||
"libc",
|
"libc",
|
||||||
"mach 0.3.2",
|
"mach",
|
||||||
"nix 0.17.0",
|
"nix",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
"uom 0.28.0",
|
"uom 0.28.0",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
|
@ -1932,7 +1915,7 @@ dependencies = [
|
||||||
"heim-runtime",
|
"heim-runtime",
|
||||||
"lazy_static 1.4.0",
|
"lazy_static 1.4.0",
|
||||||
"libc",
|
"libc",
|
||||||
"mach 0.3.2",
|
"mach",
|
||||||
"ntapi",
|
"ntapi",
|
||||||
"smol",
|
"smol",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
|
@ -1946,11 +1929,11 @@ checksum = "8c650cc53da13cb4027eba907bfeff7c764d801e83fd833e48b513c38ed78368"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"core-foundation 0.7.0",
|
"core-foundation",
|
||||||
"heim-common",
|
"heim-common",
|
||||||
"heim-runtime",
|
"heim-runtime",
|
||||||
"libc",
|
"libc",
|
||||||
"mach 0.3.2",
|
"mach",
|
||||||
"widestring",
|
"widestring",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
@ -1967,7 +1950,7 @@ dependencies = [
|
||||||
"lazy_static 1.4.0",
|
"lazy_static 1.4.0",
|
||||||
"libc",
|
"libc",
|
||||||
"log 0.4.11",
|
"log 0.4.11",
|
||||||
"mach 0.3.2",
|
"mach",
|
||||||
"ntapi",
|
"ntapi",
|
||||||
"platforms",
|
"platforms",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
|
@ -1984,7 +1967,7 @@ dependencies = [
|
||||||
"heim-runtime",
|
"heim-runtime",
|
||||||
"lazy_static 1.4.0",
|
"lazy_static 1.4.0",
|
||||||
"libc",
|
"libc",
|
||||||
"mach 0.3.2",
|
"mach",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -2000,7 +1983,7 @@ dependencies = [
|
||||||
"heim-runtime",
|
"heim-runtime",
|
||||||
"libc",
|
"libc",
|
||||||
"macaddr",
|
"macaddr",
|
||||||
"nix 0.17.0",
|
"nix",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2020,7 +2003,7 @@ dependencies = [
|
||||||
"heim-runtime",
|
"heim-runtime",
|
||||||
"lazy_static 1.4.0",
|
"lazy_static 1.4.0",
|
||||||
"libc",
|
"libc",
|
||||||
"mach 0.3.2",
|
"mach",
|
||||||
"memchr",
|
"memchr",
|
||||||
"ntapi",
|
"ntapi",
|
||||||
"ordered-float",
|
"ordered-float",
|
||||||
|
@ -2667,15 +2650,6 @@ version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baee0bbc17ce759db233beb01648088061bf678383130602a298e6998eedb2d8"
|
checksum = "baee0bbc17ce759db233beb01648088061bf678383130602a298e6998eedb2d8"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "mach"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "86dd2487cdfea56def77b88438a2c915fb45113c5319bfe7e14306ca4cd0b0e1"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mach"
|
name = "mach"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
|
@ -2934,19 +2908,6 @@ dependencies = [
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nix"
|
|
||||||
version = "0.15.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"cc",
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
"void",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.17.0"
|
version = "0.17.0"
|
||||||
|
@ -4731,7 +4692,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log 0.4.11",
|
"log 0.4.11",
|
||||||
"memchr",
|
"memchr",
|
||||||
"nix 0.17.0",
|
"nix",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
|
@ -4830,8 +4791,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535"
|
checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"core-foundation 0.7.0",
|
"core-foundation",
|
||||||
"core-foundation-sys 0.7.0",
|
"core-foundation-sys",
|
||||||
"libc",
|
"libc",
|
||||||
"security-framework-sys",
|
"security-framework-sys",
|
||||||
]
|
]
|
||||||
|
@ -4842,7 +4803,7 @@ version = "0.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405"
|
checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"core-foundation-sys 0.7.0",
|
"core-foundation-sys",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -5809,21 +5770,21 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uom"
|
name = "uom"
|
||||||
version = "0.26.0"
|
version = "0.28.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4cec796ec5f7ac557631709079168286056205c51c60aac33f51764bdc7b8dc4"
|
checksum = "627142a1043c2d460613232ce4f7e322e756636e000c0f1d1f2e779cb431358a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"num-rational",
|
||||||
"num-traits 0.2.12",
|
"num-traits 0.2.12",
|
||||||
"typenum",
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uom"
|
name = "uom"
|
||||||
version = "0.28.0"
|
version = "0.29.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "627142a1043c2d460613232ce4f7e322e756636e000c0f1d1f2e779cb431358a"
|
checksum = "8bb593f5252356bfb829112f8fca2d0982d48588d2d6bb5a92553b0dfc4c9aba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num-rational",
|
|
||||||
"num-traits 0.2.12",
|
"num-traits 0.2.12",
|
||||||
"typenum",
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,7 +7,7 @@ use nu_protocol::{
|
||||||
did_you_mean, ColumnPath, PathMember, Primitive, ReturnSuccess, Signature, SyntaxShape,
|
did_you_mean, ColumnPath, PathMember, Primitive, ReturnSuccess, Signature, SyntaxShape,
|
||||||
UnspannedPathMember, UntaggedValue, Value,
|
UnspannedPathMember, UntaggedValue, Value,
|
||||||
};
|
};
|
||||||
use nu_source::span_for_spanned_list;
|
use nu_source::HasFallibleSpan;
|
||||||
use nu_value_ext::get_data_by_column_path;
|
use nu_value_ext::get_data_by_column_path;
|
||||||
|
|
||||||
pub struct Get;
|
pub struct Get;
|
||||||
|
@ -65,7 +65,7 @@ pub fn get_column_path(path: &ColumnPath, obj: &Value) -> Result<Value, ShellErr
|
||||||
obj,
|
obj,
|
||||||
path,
|
path,
|
||||||
Box::new(move |(obj_source, column_path_tried, error)| {
|
Box::new(move |(obj_source, column_path_tried, error)| {
|
||||||
let path_members_span = span_for_spanned_list(fields.members().iter().map(|p| p.span));
|
let path_members_span = fields.maybe_span().unwrap_or_else(Span::unknown);
|
||||||
|
|
||||||
match &obj_source.value {
|
match &obj_source.value {
|
||||||
UntaggedValue::Table(rows) => match column_path_tried {
|
UntaggedValue::Table(rows) => match column_path_tried {
|
||||||
|
|
|
@ -2,11 +2,13 @@ use crate::commands::classified::block::run_block;
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use futures::stream::once;
|
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ColumnPath, ReturnSuccess, Scope, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{
|
||||||
|
ColumnPath, Primitive, ReturnSuccess, Scope, Signature, SyntaxShape, UntaggedValue, Value,
|
||||||
|
};
|
||||||
use nu_value_ext::ValueExt;
|
use nu_value_ext::ValueExt;
|
||||||
|
|
||||||
|
use futures::stream::once;
|
||||||
pub struct Insert;
|
pub struct Insert;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -49,14 +51,14 @@ async fn process_row(
|
||||||
mut context: Arc<Context>,
|
mut context: Arc<Context>,
|
||||||
input: Value,
|
input: Value,
|
||||||
mut value: Arc<Value>,
|
mut value: Arc<Value>,
|
||||||
column: Arc<ColumnPath>,
|
field: Arc<ColumnPath>,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let value = Arc::make_mut(&mut value);
|
let value = Arc::make_mut(&mut value);
|
||||||
|
|
||||||
Ok(match value {
|
Ok(match value {
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Block(block),
|
value: UntaggedValue::Block(block),
|
||||||
..
|
tag: block_tag,
|
||||||
} => {
|
} => {
|
||||||
let for_block = input.clone();
|
let for_block = input.clone();
|
||||||
let input_stream = once(async { Ok(for_block) }).to_input_stream();
|
let input_stream = once(async { Ok(for_block) }).to_input_stream();
|
||||||
|
@ -98,35 +100,32 @@ async fn process_row(
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Row(_),
|
value: UntaggedValue::Row(_),
|
||||||
..
|
..
|
||||||
} => match obj.insert_data_at_column_path(&column, result) {
|
} => match obj.insert_data_at_column_path(&field, result) {
|
||||||
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
|
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => OutputStream::one(Err(e)),
|
||||||
},
|
},
|
||||||
Value { tag, .. } => OutputStream::one(Err(ShellError::labeled_error(
|
_ => OutputStream::one(Err(ShellError::labeled_error(
|
||||||
"Unrecognized type in stream",
|
"Unrecognized type in stream",
|
||||||
"original value",
|
"original value",
|
||||||
tag,
|
block_tag.clone(),
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => OutputStream::one(Err(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => match input {
|
value => match input {
|
||||||
obj
|
|
||||||
@
|
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Row(_),
|
value: UntaggedValue::Primitive(Primitive::Nothing),
|
||||||
..
|
..
|
||||||
} => match obj.insert_data_at_column_path(&column, value.clone()) {
|
} => match scope.it.insert_data_at_column_path(&field, value.clone()) {
|
||||||
|
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
|
||||||
|
Err(e) => OutputStream::one(Err(e)),
|
||||||
|
},
|
||||||
|
_ => match input.insert_data_at_column_path(&field, value.clone()) {
|
||||||
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
|
Ok(v) => OutputStream::one(ReturnSuccess::value(v)),
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => OutputStream::one(Err(e)),
|
||||||
},
|
},
|
||||||
Value { tag, .. } => OutputStream::one(Err(ShellError::labeled_error(
|
|
||||||
"Unrecognized type in stream",
|
|
||||||
"original value",
|
|
||||||
tag,
|
|
||||||
))),
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::prelude::*;
|
||||||
use nu_data::base::select_fields;
|
use nu_data::base::select_fields;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ColumnPath, ReturnSuccess, Signature, SyntaxShape, Value};
|
use nu_protocol::{ColumnPath, ReturnSuccess, Signature, SyntaxShape, Value};
|
||||||
use nu_source::span_for_spanned_list;
|
use nu_source::HasFallibleSpan;
|
||||||
|
|
||||||
pub struct SubCommand;
|
pub struct SubCommand;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ async fn operate(
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect::<Vec<&ColumnPath>>();
|
.collect::<Vec<&ColumnPath>>();
|
||||||
|
|
||||||
let after_span = span_for_spanned_list(after.members().iter().map(|p| p.span));
|
let after_span = after.maybe_span().unwrap_or_else(Span::unknown);
|
||||||
|
|
||||||
if after.members().len() == 1 {
|
if after.members().len() == 1 {
|
||||||
let keys = column_paths
|
let keys = column_paths
|
||||||
|
@ -154,7 +154,7 @@ async fn operate(
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect::<Vec<&ColumnPath>>();
|
.collect::<Vec<&ColumnPath>>();
|
||||||
|
|
||||||
let before_span = span_for_spanned_list(before.members().iter().map(|p| p.span));
|
let before_span = before.maybe_span().unwrap_or_else(Span::unknown);
|
||||||
|
|
||||||
if before.members().len() == 1 {
|
if before.members().len() == 1 {
|
||||||
let keys = column_paths
|
let keys = column_paths
|
||||||
|
@ -207,7 +207,7 @@ fn move_after(
|
||||||
tag: impl Into<Tag>,
|
tag: impl Into<Tag>,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
let tag = tag.into();
|
let tag = tag.into();
|
||||||
let from_fields = span_for_spanned_list(from.members().iter().map(|p| p.span));
|
let from_fields = from.maybe_span().unwrap_or_else(Span::unknown);
|
||||||
let from = if let Some((last, _)) = from.split_last() {
|
let from = if let Some((last, _)) = from.split_last() {
|
||||||
last.as_string()
|
last.as_string()
|
||||||
} else {
|
} else {
|
||||||
|
@ -270,7 +270,7 @@ fn move_before(
|
||||||
tag: impl Into<Tag>,
|
tag: impl Into<Tag>,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
let tag = tag.into();
|
let tag = tag.into();
|
||||||
let from_fields = span_for_spanned_list(from.members().iter().map(|p| p.span));
|
let from_fields = from.maybe_span().unwrap_or_else(Span::unknown);
|
||||||
let from = if let Some((last, _)) = from.split_last() {
|
let from = if let Some((last, _)) = from.split_last() {
|
||||||
last.as_string()
|
last.as_string()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,7 +3,10 @@ use crate::commands::WholeStreamCommand;
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ColumnPath, ReturnSuccess, Scope, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{
|
||||||
|
ColumnPath, Primitive, ReturnSuccess, Scope, Signature, SyntaxShape, UntaggedValue, Value,
|
||||||
|
};
|
||||||
|
use nu_source::HasFallibleSpan;
|
||||||
use nu_value_ext::ValueExt;
|
use nu_value_ext::ValueExt;
|
||||||
|
|
||||||
use futures::stream::once;
|
use futures::stream::once;
|
||||||
|
@ -54,13 +57,15 @@ async fn process_row(
|
||||||
input: Value,
|
input: Value,
|
||||||
mut replacement: Arc<Value>,
|
mut replacement: Arc<Value>,
|
||||||
field: Arc<ColumnPath>,
|
field: Arc<ColumnPath>,
|
||||||
|
tag: Arc<Tag>,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
|
let tag = &*tag;
|
||||||
let replacement = Arc::make_mut(&mut replacement);
|
let replacement = Arc::make_mut(&mut replacement);
|
||||||
|
|
||||||
Ok(match replacement {
|
Ok(match replacement {
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Block(block),
|
value: UntaggedValue::Block(block),
|
||||||
..
|
tag: block_tag,
|
||||||
} => {
|
} => {
|
||||||
let for_block = input.clone();
|
let for_block = input.clone();
|
||||||
let input_stream = once(async { Ok(for_block) }).to_input_stream();
|
let input_stream = once(async { Ok(for_block) }).to_input_stream();
|
||||||
|
@ -110,35 +115,41 @@ async fn process_row(
|
||||||
obj.tag,
|
obj.tag,
|
||||||
))),
|
))),
|
||||||
},
|
},
|
||||||
Value { tag, .. } => OutputStream::one(Err(ShellError::labeled_error(
|
_ => OutputStream::one(Err(ShellError::labeled_error(
|
||||||
"Unrecognized type in stream",
|
"Unrecognized type in stream",
|
||||||
"original value",
|
"original value",
|
||||||
tag,
|
block_tag.clone(),
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => OutputStream::one(Err(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => match input {
|
replacement => match input {
|
||||||
obj
|
|
||||||
@
|
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Row(_),
|
value: UntaggedValue::Primitive(Primitive::Nothing),
|
||||||
..
|
..
|
||||||
} => match obj.replace_data_at_column_path(&field, replacement.clone()) {
|
} => match scope
|
||||||
|
.it
|
||||||
|
.replace_data_at_column_path(&field, replacement.clone())
|
||||||
|
{
|
||||||
Some(v) => OutputStream::one(ReturnSuccess::value(v)),
|
Some(v) => OutputStream::one(ReturnSuccess::value(v)),
|
||||||
None => OutputStream::one(Err(ShellError::labeled_error(
|
None => OutputStream::one(Err(ShellError::labeled_error(
|
||||||
"update could not find place to insert column",
|
"update could not find place to insert column",
|
||||||
"column name",
|
"column name",
|
||||||
obj.tag,
|
field.maybe_span().unwrap_or_else(|| tag.span),
|
||||||
))),
|
))),
|
||||||
},
|
},
|
||||||
Value { tag, .. } => OutputStream::one(Err(ShellError::labeled_error(
|
Value { value: _, ref tag } => {
|
||||||
"Unrecognized type in stream",
|
match input.replace_data_at_column_path(&field, replacement.clone()) {
|
||||||
"original value",
|
Some(v) => OutputStream::one(ReturnSuccess::value(v)),
|
||||||
tag,
|
None => OutputStream::one(Err(ShellError::labeled_error(
|
||||||
))),
|
"update could not find place to insert column",
|
||||||
|
"column name",
|
||||||
|
field.maybe_span().unwrap_or_else(|| tag.span),
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -148,6 +159,7 @@ async fn update(
|
||||||
registry: &CommandRegistry,
|
registry: &CommandRegistry,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let registry = registry.clone();
|
let registry = registry.clone();
|
||||||
|
let name_tag = Arc::new(raw_args.call_info.name_tag.clone());
|
||||||
let scope = Arc::new(raw_args.call_info.scope.clone());
|
let scope = Arc::new(raw_args.call_info.scope.clone());
|
||||||
let context = Arc::new(Context::from_raw(&raw_args, ®istry));
|
let context = Arc::new(Context::from_raw(&raw_args, ®istry));
|
||||||
let (UpdateArgs { field, replacement }, input) = raw_args.process(®istry).await?;
|
let (UpdateArgs { field, replacement }, input) = raw_args.process(®istry).await?;
|
||||||
|
@ -156,13 +168,14 @@ async fn update(
|
||||||
|
|
||||||
Ok(input
|
Ok(input
|
||||||
.then(move |input| {
|
.then(move |input| {
|
||||||
|
let tag = name_tag.clone();
|
||||||
let scope = scope.clone();
|
let scope = scope.clone();
|
||||||
let context = context.clone();
|
let context = context.clone();
|
||||||
let replacement = replacement.clone();
|
let replacement = replacement.clone();
|
||||||
let field = field.clone();
|
let field = field.clone();
|
||||||
|
|
||||||
async {
|
async {
|
||||||
match process_row(scope, context, input, replacement, field).await {
|
match process_row(scope, context, input, replacement, field, tag).await {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => OutputStream::one(Err(e)),
|
Err(e) => OutputStream::one(Err(e)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,3 +30,19 @@ fn sets_the_column_from_a_block_full_stream_output() {
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sets_the_column_from_an_invocation() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
wrap content
|
||||||
|
| insert content $(open --raw cargo_sample.toml | lines | first 5)
|
||||||
|
| get content.1
|
||||||
|
| str contains "nu"
|
||||||
|
| echo $it
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "true");
|
||||||
|
}
|
||||||
|
|
|
@ -46,3 +46,19 @@ fn sets_the_column_from_a_block_full_stream_output() {
|
||||||
|
|
||||||
assert_eq!(actual.out, "true");
|
assert_eq!(actual.out, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sets_the_column_from_an_invocation() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
wrap content
|
||||||
|
| update content $(open --raw cargo_sample.toml | lines | first 5)
|
||||||
|
| get content.1
|
||||||
|
| str contains "nu"
|
||||||
|
| echo $it
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "true");
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,9 @@ use nu_protocol::{
|
||||||
ColumnPath, MaybeOwned, PathMember, Primitive, ShellTypeName, SpannedTypeName,
|
ColumnPath, MaybeOwned, PathMember, Primitive, ShellTypeName, SpannedTypeName,
|
||||||
UnspannedPathMember, UntaggedValue, Value,
|
UnspannedPathMember, UntaggedValue, Value,
|
||||||
};
|
};
|
||||||
use nu_source::{HasSpan, PrettyDebug, Spanned, SpannedItem, Tag, Tagged, TaggedItem};
|
use nu_source::{
|
||||||
|
HasFallibleSpan, HasSpan, PrettyDebug, Span, Spanned, SpannedItem, Tag, Tagged, TaggedItem,
|
||||||
|
};
|
||||||
use num_traits::cast::ToPrimitive;
|
use num_traits::cast::ToPrimitive;
|
||||||
|
|
||||||
pub trait ValueExt {
|
pub trait ValueExt {
|
||||||
|
@ -220,8 +222,7 @@ pub fn swap_data_by_column_path(
|
||||||
&value,
|
&value,
|
||||||
path,
|
path,
|
||||||
Box::new(move |(obj_source, column_path_tried, error)| {
|
Box::new(move |(obj_source, column_path_tried, error)| {
|
||||||
let path_members_span =
|
let path_members_span = fields.maybe_span().unwrap_or_else(Span::unknown);
|
||||||
nu_source::span_for_spanned_list(fields.members().iter().map(|p| p.span));
|
|
||||||
|
|
||||||
match &obj_source.value {
|
match &obj_source.value {
|
||||||
UntaggedValue::Table(rows) => match column_path_tried {
|
UntaggedValue::Table(rows) => match column_path_tried {
|
||||||
|
|
Loading…
Reference in a new issue