From a8646f94abadbbdce6543bb0f8ed65ed6c1ef708 Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 7 Sep 2021 19:35:59 +1200 Subject: [PATCH] Add cell paths for streams --- crates/nu-command/src/each.rs | 6 ++-- crates/nu-command/src/for_.rs | 2 +- crates/nu-command/src/length.rs | 2 +- .../src/engine/evaluation_context.rs | 2 +- crates/nu-protocol/src/value.rs | 29 +++++++++++++++---- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/crates/nu-command/src/each.rs b/crates/nu-command/src/each.rs index 24733b149..624370cc7 100644 --- a/crates/nu-command/src/each.rs +++ b/crates/nu-command/src/each.rs @@ -30,7 +30,7 @@ impl Command for Each { let context = context.clone(); match input { - Value::Range { val, .. } => Ok(Value::ValueStream { + Value::Range { val, .. } => Ok(Value::Stream { stream: val .into_iter() .map(move |x| { @@ -52,7 +52,7 @@ impl Command for Each { .into_value_stream(), span: call.head, }), - Value::List { vals: val, .. } => Ok(Value::ValueStream { + Value::List { vals: val, .. } => Ok(Value::Stream { stream: val .into_iter() .map(move |x| { @@ -74,7 +74,7 @@ impl Command for Each { .into_value_stream(), span: call.head, }), - Value::ValueStream { stream, .. } => Ok(Value::ValueStream { + Value::Stream { stream, .. } => Ok(Value::Stream { stream: stream .map(move |x| { let engine_state = context.engine_state.borrow(); diff --git a/crates/nu-command/src/for_.rs b/crates/nu-command/src/for_.rs index 5ba8bb8df..35d806dd5 100644 --- a/crates/nu-command/src/for_.rs +++ b/crates/nu-command/src/for_.rs @@ -53,7 +53,7 @@ impl Command for For { let context = context.clone(); match values { - Value::ValueStream { stream, .. } => Ok(Value::ValueStream { + Value::Stream { stream, .. } => Ok(Value::Stream { stream: stream .map(move |x| { let engine_state = context.engine_state.borrow(); diff --git a/crates/nu-command/src/length.rs b/crates/nu-command/src/length.rs index 854a5c4af..d2c33fad5 100644 --- a/crates/nu-command/src/length.rs +++ b/crates/nu-command/src/length.rs @@ -32,7 +32,7 @@ impl Command for Length { span: call.head, }) } - Value::ValueStream { stream, .. } => { + Value::Stream { stream, .. } => { let length = stream.count(); Ok(Value::Int { diff --git a/crates/nu-protocol/src/engine/evaluation_context.rs b/crates/nu-protocol/src/engine/evaluation_context.rs index 01dd9ea56..776a69fb1 100644 --- a/crates/nu-protocol/src/engine/evaluation_context.rs +++ b/crates/nu-protocol/src/engine/evaluation_context.rs @@ -29,7 +29,7 @@ impl EvaluationContext { // TODO: add ctrl-c support let value = match value { - Value::ValueStream { stream, span } => Value::List { + Value::Stream { stream, span } => Value::List { vals: stream.collect(), span, }, diff --git a/crates/nu-protocol/src/value.rs b/crates/nu-protocol/src/value.rs index 0fc760406..dc36aaa08 100644 --- a/crates/nu-protocol/src/value.rs +++ b/crates/nu-protocol/src/value.rs @@ -252,7 +252,7 @@ pub enum Value { vals: Vec, span: Span, }, - ValueStream { + Stream { stream: ValueStream, span: Span, }, @@ -290,7 +290,7 @@ impl Value { Value::Record { span, .. } => *span, Value::List { span, .. } => *span, Value::Block { span, .. } => *span, - Value::ValueStream { span, .. } => *span, + Value::Stream { span, .. } => *span, Value::Nothing { span, .. } => *span, Value::Error { .. } => Span::unknown(), } @@ -304,7 +304,7 @@ impl Value { Value::Range { span, .. } => *span = new_span, Value::String { span, .. } => *span = new_span, Value::Record { span, .. } => *span = new_span, - Value::ValueStream { span, .. } => *span = new_span, + Value::Stream { span, .. } => *span = new_span, Value::List { span, .. } => *span = new_span, Value::Block { span, .. } => *span = new_span, Value::Nothing { span, .. } => *span = new_span, @@ -327,7 +327,7 @@ impl Value { Value::List { .. } => Type::List(Box::new(Type::Unknown)), // FIXME Value::Nothing { .. } => Type::Nothing, Value::Block { .. } => Type::Block, - Value::ValueStream { .. } => Type::ValueStream, + Value::Stream { .. } => Type::ValueStream, Value::Error { .. } => Type::Error, } } @@ -357,7 +357,7 @@ impl Value { ) } Value::String { val, .. } => val, - Value::ValueStream { stream, .. } => stream.into_string(), + Value::Stream { stream, .. } => stream.into_string(), Value::List { vals: val, .. } => format!( "[{}]", val.into_iter() @@ -404,7 +404,7 @@ impl Value { return Err(ShellError::AccessBeyondEnd(val.len(), *origin_span)); } } - Value::ValueStream { stream, .. } => { + Value::Stream { stream, .. } => { if let Some(item) = stream.nth(*count) { current = item; } else { @@ -454,6 +454,23 @@ impl Value { span: *span, }; } + Value::Stream { stream, span } => { + let mut output = vec![]; + for val in stream { + if let Value::Record { cols, vals, .. } = val { + for col in cols.iter().enumerate() { + if col.1 == column_name { + output.push(vals[col.0].clone()); + } + } + } + } + + current = Value::List { + vals: output, + span: *span, + }; + } x => { return Err(ShellError::IncompatiblePathAccess( format!("{}", x.get_type()),