mirror of
https://github.com/nushell/nushell.git
synced 2024-11-15 21:14:40 +01:00
Add cell paths for streams
This commit is contained in:
parent
71bbd70a57
commit
a8646f94ab
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -32,7 +32,7 @@ impl Command for Length {
|
||||
span: call.head,
|
||||
})
|
||||
}
|
||||
Value::ValueStream { stream, .. } => {
|
||||
Value::Stream { stream, .. } => {
|
||||
let length = stream.count();
|
||||
|
||||
Ok(Value::Int {
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -252,7 +252,7 @@ pub enum Value {
|
||||
vals: Vec<Value>,
|
||||
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()),
|
||||
|
Loading…
Reference in New Issue
Block a user