ListStream touchup (#12524)

# Description

Does some misc changes to `ListStream`:
- Moves it into its own module/file separate from `RawStream`.
- `ListStream`s now have an associated `Span`.
- This required changes to `ListStreamInfo` in `nu-plugin`. Note sure if
this is a breaking change for the plugin protocol.
- Hides the internals of `ListStream` but also adds a few more methods.
- This includes two functions to more easily alter a stream (these take
a `ListStream` and return a `ListStream` instead of having to go through
the whole `into_pipeline_data(..)` route).
  -  `map`: takes a `FnMut(Value) -> Value`
  - `modify`: takes a function to modify the inner stream.
This commit is contained in:
Ian Manske
2024-05-05 16:00:59 +00:00
committed by GitHub
parent 3143ded374
commit e879d4ecaf
106 changed files with 957 additions and 874 deletions

View File

@ -121,7 +121,7 @@ impl Command for Du {
};
Ok(
du_for_one_pattern(args, &current_dir, tag, engine_state.ctrlc.clone())?
.into_pipeline_data(engine_state.ctrlc.clone()),
.into_pipeline_data(tag, engine_state.ctrlc.clone()),
)
}
Some(paths) => {
@ -147,7 +147,7 @@ impl Command for Du {
Ok(result_iters
.into_iter()
.flatten()
.into_pipeline_data(engine_state.ctrlc.clone()))
.into_pipeline_data(tag, engine_state.ctrlc.clone()))
}
}
}

View File

@ -199,7 +199,7 @@ impl Command for Glob {
}
};
Ok(if !not_patterns.is_empty() {
let result = if !not_patterns.is_empty() {
let np: Vec<&str> = not_patterns.iter().map(|s| s as &str).collect();
let glob_results = glob
.walk_with_behavior(
@ -218,10 +218,7 @@ impl Command for Glob {
inner: vec![],
})?
.flatten();
let result = glob_to_value(ctrlc, glob_results, no_dirs, no_files, no_symlinks, span)?;
result
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone())
glob_to_value(ctrlc, glob_results, no_dirs, no_files, no_symlinks, span)
} else {
let glob_results = glob
.walk_with_behavior(
@ -232,11 +229,12 @@ impl Command for Glob {
},
)
.flatten();
let result = glob_to_value(ctrlc, glob_results, no_dirs, no_files, no_symlinks, span)?;
result
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone())
})
glob_to_value(ctrlc, glob_results, no_dirs, no_files, no_symlinks, span)
}?;
Ok(result
.into_iter()
.into_pipeline_data(span, engine_state.ctrlc.clone()))
}
}

View File

@ -115,10 +115,11 @@ impl Command for Ls {
match input_pattern_arg {
None => Ok(ls_for_one_pattern(None, args, ctrl_c.clone(), cwd)?
.into_pipeline_data_with_metadata(
call_span,
ctrl_c,
PipelineMetadata {
data_source: DataSource::Ls,
},
ctrl_c,
)),
Some(pattern) => {
let mut result_iters = vec![];
@ -137,10 +138,11 @@ impl Command for Ls {
.into_iter()
.flatten()
.into_pipeline_data_with_metadata(
call_span,
ctrl_c,
PipelineMetadata {
data_source: DataSource::Ls,
},
ctrl_c,
))
}
}

View File

@ -209,7 +209,10 @@ impl Command for Open {
} else if output.len() == 1 {
Ok(output.remove(0))
} else {
Ok(output.into_iter().flatten().into_pipeline_data(ctrlc))
Ok(output
.into_iter()
.flatten()
.into_pipeline_data(call_span, ctrlc))
}
}

View File

@ -465,7 +465,7 @@ fn rm(
}
})
.filter(|x| !matches!(x.get_type(), Type::Nothing))
.into_pipeline_data(ctrlc)
.into_pipeline_data(span, ctrlc)
.print_not_formatted(engine_state, false, true)?;
Ok(PipelineData::empty())