mirror of
https://github.com/nushell/nushell
synced 2024-12-30 15:03:25 +00:00
Add cell paths for streams
This commit is contained in:
parent
71bbd70a57
commit
a8646f94ab
5 changed files with 29 additions and 12 deletions
|
@ -30,7 +30,7 @@ impl Command for Each {
|
||||||
let context = context.clone();
|
let context = context.clone();
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
Value::Range { val, .. } => Ok(Value::ValueStream {
|
Value::Range { val, .. } => Ok(Value::Stream {
|
||||||
stream: val
|
stream: val
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(move |x| {
|
.map(move |x| {
|
||||||
|
@ -52,7 +52,7 @@ impl Command for Each {
|
||||||
.into_value_stream(),
|
.into_value_stream(),
|
||||||
span: call.head,
|
span: call.head,
|
||||||
}),
|
}),
|
||||||
Value::List { vals: val, .. } => Ok(Value::ValueStream {
|
Value::List { vals: val, .. } => Ok(Value::Stream {
|
||||||
stream: val
|
stream: val
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(move |x| {
|
.map(move |x| {
|
||||||
|
@ -74,7 +74,7 @@ impl Command for Each {
|
||||||
.into_value_stream(),
|
.into_value_stream(),
|
||||||
span: call.head,
|
span: call.head,
|
||||||
}),
|
}),
|
||||||
Value::ValueStream { stream, .. } => Ok(Value::ValueStream {
|
Value::Stream { stream, .. } => Ok(Value::Stream {
|
||||||
stream: stream
|
stream: stream
|
||||||
.map(move |x| {
|
.map(move |x| {
|
||||||
let engine_state = context.engine_state.borrow();
|
let engine_state = context.engine_state.borrow();
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl Command for For {
|
||||||
let context = context.clone();
|
let context = context.clone();
|
||||||
|
|
||||||
match values {
|
match values {
|
||||||
Value::ValueStream { stream, .. } => Ok(Value::ValueStream {
|
Value::Stream { stream, .. } => Ok(Value::Stream {
|
||||||
stream: stream
|
stream: stream
|
||||||
.map(move |x| {
|
.map(move |x| {
|
||||||
let engine_state = context.engine_state.borrow();
|
let engine_state = context.engine_state.borrow();
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl Command for Length {
|
||||||
span: call.head,
|
span: call.head,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Value::ValueStream { stream, .. } => {
|
Value::Stream { stream, .. } => {
|
||||||
let length = stream.count();
|
let length = stream.count();
|
||||||
|
|
||||||
Ok(Value::Int {
|
Ok(Value::Int {
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl EvaluationContext {
|
||||||
// TODO: add ctrl-c support
|
// TODO: add ctrl-c support
|
||||||
|
|
||||||
let value = match value {
|
let value = match value {
|
||||||
Value::ValueStream { stream, span } => Value::List {
|
Value::Stream { stream, span } => Value::List {
|
||||||
vals: stream.collect(),
|
vals: stream.collect(),
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
|
|
|
@ -252,7 +252,7 @@ pub enum Value {
|
||||||
vals: Vec<Value>,
|
vals: Vec<Value>,
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
ValueStream {
|
Stream {
|
||||||
stream: ValueStream,
|
stream: ValueStream,
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
|
@ -290,7 +290,7 @@ impl Value {
|
||||||
Value::Record { span, .. } => *span,
|
Value::Record { span, .. } => *span,
|
||||||
Value::List { span, .. } => *span,
|
Value::List { span, .. } => *span,
|
||||||
Value::Block { span, .. } => *span,
|
Value::Block { span, .. } => *span,
|
||||||
Value::ValueStream { span, .. } => *span,
|
Value::Stream { span, .. } => *span,
|
||||||
Value::Nothing { span, .. } => *span,
|
Value::Nothing { span, .. } => *span,
|
||||||
Value::Error { .. } => Span::unknown(),
|
Value::Error { .. } => Span::unknown(),
|
||||||
}
|
}
|
||||||
|
@ -304,7 +304,7 @@ impl Value {
|
||||||
Value::Range { span, .. } => *span = new_span,
|
Value::Range { span, .. } => *span = new_span,
|
||||||
Value::String { span, .. } => *span = new_span,
|
Value::String { span, .. } => *span = new_span,
|
||||||
Value::Record { 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::List { span, .. } => *span = new_span,
|
||||||
Value::Block { span, .. } => *span = new_span,
|
Value::Block { span, .. } => *span = new_span,
|
||||||
Value::Nothing { 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::List { .. } => Type::List(Box::new(Type::Unknown)), // FIXME
|
||||||
Value::Nothing { .. } => Type::Nothing,
|
Value::Nothing { .. } => Type::Nothing,
|
||||||
Value::Block { .. } => Type::Block,
|
Value::Block { .. } => Type::Block,
|
||||||
Value::ValueStream { .. } => Type::ValueStream,
|
Value::Stream { .. } => Type::ValueStream,
|
||||||
Value::Error { .. } => Type::Error,
|
Value::Error { .. } => Type::Error,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,7 +357,7 @@ impl Value {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Value::String { val, .. } => val,
|
Value::String { val, .. } => val,
|
||||||
Value::ValueStream { stream, .. } => stream.into_string(),
|
Value::Stream { stream, .. } => stream.into_string(),
|
||||||
Value::List { vals: val, .. } => format!(
|
Value::List { vals: val, .. } => format!(
|
||||||
"[{}]",
|
"[{}]",
|
||||||
val.into_iter()
|
val.into_iter()
|
||||||
|
@ -404,7 +404,7 @@ impl Value {
|
||||||
return Err(ShellError::AccessBeyondEnd(val.len(), *origin_span));
|
return Err(ShellError::AccessBeyondEnd(val.len(), *origin_span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::ValueStream { stream, .. } => {
|
Value::Stream { stream, .. } => {
|
||||||
if let Some(item) = stream.nth(*count) {
|
if let Some(item) = stream.nth(*count) {
|
||||||
current = item;
|
current = item;
|
||||||
} else {
|
} else {
|
||||||
|
@ -454,6 +454,23 @@ impl Value {
|
||||||
span: *span,
|
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 => {
|
x => {
|
||||||
return Err(ShellError::IncompatiblePathAccess(
|
return Err(ShellError::IncompatiblePathAccess(
|
||||||
format!("{}", x.get_type()),
|
format!("{}", x.get_type()),
|
||||||
|
|
Loading…
Reference in a new issue