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(
|
||||
data: PipelineData,
|
||||
signals: Signals,
|
||||
|
@ -154,6 +161,18 @@ pub fn follow_cell_path_into_stream(
|
|||
) -> Result<PipelineData, ShellError> {
|
||||
match data {
|
||||
PipelineData::ListStream(stream, ..) => {
|
||||
let has_int_member = cell_path.iter().any(|it| match it {
|
||||
PathMember::String { .. } => false,
|
||||
PathMember::Int { .. } => true,
|
||||
});
|
||||
|
||||
if has_int_member {
|
||||
// when given an integer/indexing, we fallback to
|
||||
// the default nushell indexing behaviour
|
||||
Value::list(stream.into_iter().collect(), head)
|
||||
.follow_cell_path(&cell_path, insensitive)
|
||||
.map(|it| it.into_pipeline_data())
|
||||
} else {
|
||||
let result = stream
|
||||
.into_iter()
|
||||
.map(move |value| {
|
||||
|
@ -168,6 +187,7 @@ pub fn follow_cell_path_into_stream(
|
|||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
_ => data
|
||||
.follow_cell_path(&cell_path, head, insensitive)
|
||||
|
|
Loading…
Reference in a new issue