mirror of
https://github.com/nushell/nushell
synced 2024-12-25 12:33:17 +00:00
get
now behaves correctly with integer cell paths
patch
This commit is contained in:
parent
7766b3893f
commit
fb65d5e721
1 changed files with 31 additions and 11 deletions
|
@ -145,6 +145,13 @@ If multiple cell paths are given, this will produce a list of values."#
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the PipelineData.follow_cell_path function, when given a
|
||||||
|
// stream, collects it into a vec before doing its job
|
||||||
|
//
|
||||||
|
// this is fine, since it returns a Result<Value ShellError>,
|
||||||
|
// but if we want to follow a PipelineData into a cell path and
|
||||||
|
// return another PipelineData, then we have to take care to
|
||||||
|
// make sure it streams
|
||||||
pub fn follow_cell_path_into_stream(
|
pub fn follow_cell_path_into_stream(
|
||||||
data: PipelineData,
|
data: PipelineData,
|
||||||
signals: Signals,
|
signals: Signals,
|
||||||
|
@ -154,19 +161,32 @@ pub fn follow_cell_path_into_stream(
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
match data {
|
match data {
|
||||||
PipelineData::ListStream(stream, ..) => {
|
PipelineData::ListStream(stream, ..) => {
|
||||||
let result = stream
|
let has_int_member = cell_path.iter().any(|it| match it {
|
||||||
.into_iter()
|
PathMember::String { .. } => false,
|
||||||
.map(move |value| {
|
PathMember::Int { .. } => true,
|
||||||
let span = value.span();
|
});
|
||||||
|
|
||||||
match value.follow_cell_path(&cell_path, insensitive) {
|
if has_int_member {
|
||||||
Ok(v) => v,
|
// when given an integer/indexing, we fallback to
|
||||||
Err(error) => Value::error(error, span),
|
// the default nushell indexing behaviour
|
||||||
}
|
Value::list(stream.into_iter().collect(), head)
|
||||||
})
|
.follow_cell_path(&cell_path, insensitive)
|
||||||
.into_pipeline_data(head, signals);
|
.map(|it| it.into_pipeline_data())
|
||||||
|
} else {
|
||||||
|
let result = stream
|
||||||
|
.into_iter()
|
||||||
|
.map(move |value| {
|
||||||
|
let span = value.span();
|
||||||
|
|
||||||
Ok(result)
|
match value.follow_cell_path(&cell_path, insensitive) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(error) => Value::error(error, span),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.into_pipeline_data(head, signals);
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => data
|
_ => data
|
||||||
|
|
Loading…
Reference in a new issue