Refactor: introduce 2 associated functions to PipelineData (#16233)

# Description
As title: this pr is try to introduce 2 functions to `PipelineData`:
1. PipelineData::list_stream --> create a PipelineData::ListStream
2. PipelineData::byte_stream -> create a PipelineData::ByteStream
And use these functions everywhere.

### Reason behind this change
I tried to implement `pipefail` feature, but this would required to
change `PipelineData` from enum to struct. So use these functions can
reduce diff if I finally change to struct. [Discord message
here](https://discord.com/channels/601130461678272522/615962413203718156/1396999539000479784)
is my plan.

# User-Facing Changes
NaN

# Tests + Formatting
NaN

# After Submitting
NaN
This commit is contained in:
Wind
2025-08-02 09:30:30 +08:00
committed by GitHub
parent ee5b5bd39e
commit eb8d2d3206
126 changed files with 299 additions and 304 deletions

View File

@ -117,7 +117,7 @@ impl PluginExecutionContext for PluginExecutionCommandContext<'_> {
match value {
Value::Closure { val, .. } => {
ClosureEvalOnce::new(&self.engine_state, &self.stack, *val)
.run_with_input(PipelineData::Empty)
.run_with_input(PipelineData::empty())
.and_then(|data| data.into_value(span))
.unwrap_or_else(|err| Value::error(err, self.call.head))
}

View File

@ -600,7 +600,7 @@ impl InterfaceManager for PluginInterfaceManager {
}
PipelineData::ListStream(stream, meta) => {
let source = self.state.source.clone();
Ok(PipelineData::ListStream(
Ok(PipelineData::list_stream(
stream.map(move |mut value| {
let _ = PluginCustomValueWithSource::add_source_in(&mut value, &source);
value
@ -1101,12 +1101,12 @@ impl Interface for PluginInterface {
match data {
PipelineData::Value(mut value, meta) => {
state.prepare_value(&mut value, &self.state.source)?;
Ok(PipelineData::Value(value, meta))
Ok(PipelineData::value(value, meta))
}
PipelineData::ListStream(stream, meta) => {
let source = self.state.source.clone();
let state = state.clone();
Ok(PipelineData::ListStream(
Ok(PipelineData::list_stream(
stream.map(move |mut value| {
match state.prepare_value(&mut value, &source) {
Ok(()) => value,

View File

@ -646,7 +646,7 @@ fn manager_consume_stream_end_removes_context_only_if_last_stream() -> Result<()
fn manager_prepare_pipeline_data_adds_source_to_values() -> Result<(), ShellError> {
let manager = TestCase::new().plugin("test");
let data = manager.prepare_pipeline_data(PipelineData::Value(
let data = manager.prepare_pipeline_data(PipelineData::value(
Value::test_custom_value(Box::new(test_plugin_custom_value())),
None,
))?;
@ -815,7 +815,7 @@ fn interface_write_plugin_call_writes_run_with_value_input() -> Result<(), Shell
positional: vec![],
named: vec![],
},
input: PipelineData::Value(Value::test_int(-1), Some(metadata0.clone())),
input: PipelineData::value(Value::test_int(-1), Some(metadata0.clone())),
}),
None,
)?;
@ -1072,7 +1072,7 @@ fn interface_run() -> Result<(), ShellError> {
start_fake_plugin_call_responder(manager, 1, move |_| {
vec![ReceivedPluginCallMessage::Response(
PluginCallResponse::PipelineData(PipelineData::Value(Value::test_int(number), None)),
PluginCallResponse::PipelineData(PipelineData::value(Value::test_int(number), None)),
)]
});
@ -1084,7 +1084,7 @@ fn interface_run() -> Result<(), ShellError> {
positional: vec![],
named: vec![],
},
input: PipelineData::Empty,
input: PipelineData::empty(),
},
&mut PluginExecutionBogusContext,
)?;
@ -1106,7 +1106,7 @@ fn interface_custom_value_to_base_value() -> Result<(), ShellError> {
start_fake_plugin_call_responder(manager, 1, move |_| {
vec![ReceivedPluginCallMessage::Response(
PluginCallResponse::PipelineData(PipelineData::Value(Value::test_string(string), None)),
PluginCallResponse::PipelineData(PipelineData::value(Value::test_string(string), None)),
)]
});
@ -1137,7 +1137,7 @@ fn interface_prepare_pipeline_data_accepts_normal_values() -> Result<(), ShellEr
let interface = TestCase::new().plugin("test").get_interface();
let state = CurrentCallState::default();
for value in normal_values(&interface) {
match interface.prepare_pipeline_data(PipelineData::Value(value.clone(), None), &state) {
match interface.prepare_pipeline_data(PipelineData::value(value.clone(), None), &state) {
Ok(data) => assert_eq!(
value.get_type(),
data.into_value(Span::test_data())?.get_type(),
@ -1201,7 +1201,7 @@ fn interface_prepare_pipeline_data_rejects_bad_custom_value() -> Result<(), Shel
let interface = TestCase::new().plugin("test").get_interface();
let state = CurrentCallState::default();
for value in bad_custom_values() {
match interface.prepare_pipeline_data(PipelineData::Value(value.clone(), None), &state) {
match interface.prepare_pipeline_data(PipelineData::value(value.clone(), None), &state) {
Err(err) => match err {
ShellError::CustomValueIncorrectForPlugin { .. } => (),
_ => panic!("expected error type CustomValueIncorrectForPlugin, but got {err:?}"),
@ -1361,7 +1361,7 @@ fn prepare_plugin_call_run() {
positional: vec![Value::test_int(4)],
named: vec![("x".to_owned().into_spanned(span), Some(Value::test_int(6)))],
},
input: PipelineData::Empty,
input: PipelineData::empty(),
}),
),
(
@ -1373,7 +1373,7 @@ fn prepare_plugin_call_run() {
positional: vec![cv_ok.clone()],
named: vec![("ok".to_owned().into_spanned(span), Some(cv_ok.clone()))],
},
input: PipelineData::Empty,
input: PipelineData::empty(),
}),
),
(
@ -1385,7 +1385,7 @@ fn prepare_plugin_call_run() {
positional: vec![cv_bad.clone()],
named: vec![],
},
input: PipelineData::Empty,
input: PipelineData::empty(),
}),
),
(
@ -1397,7 +1397,7 @@ fn prepare_plugin_call_run() {
positional: vec![],
named: vec![("bad".to_owned().into_spanned(span), Some(cv_bad.clone()))],
},
input: PipelineData::Empty,
input: PipelineData::empty(),
}),
),
(
@ -1410,7 +1410,7 @@ fn prepare_plugin_call_run() {
named: vec![],
},
// Shouldn't check input - that happens somewhere else
input: PipelineData::Value(cv_bad.clone(), None),
input: PipelineData::value(cv_bad.clone(), None),
}),
),
];