mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:55:42 +02:00
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:
@ -320,9 +320,9 @@ where
|
||||
// simpler signature in Plugin
|
||||
let span = input.span().unwrap_or(call.head);
|
||||
let input_value = input.into_value(span)?;
|
||||
// Wrap the output in PipelineData::Value
|
||||
// Wrap the output in PipelineData::value
|
||||
<Self as SimplePluginCommand>::run(self, plugin, engine, call, &input_value)
|
||||
.map(|value| PipelineData::Value(value, None))
|
||||
.map(|value| PipelineData::value(value, None))
|
||||
}
|
||||
|
||||
fn search_terms(&self) -> Vec<&str> {
|
||||
|
@ -367,7 +367,7 @@ impl InterfaceManager for EngineInterfaceManager {
|
||||
.map(|()| value)
|
||||
.unwrap_or_else(|err| Value::error(err, span))
|
||||
});
|
||||
Ok(PipelineData::ListStream(stream, meta))
|
||||
Ok(PipelineData::list_stream(stream, meta))
|
||||
}
|
||||
PipelineData::Empty | PipelineData::ByteStream(..) => Ok(data),
|
||||
}
|
||||
@ -557,8 +557,8 @@ impl EngineInterface {
|
||||
}
|
||||
}
|
||||
|
||||
/// Do an engine call returning an `Option<Value>` as either `PipelineData::Empty` or
|
||||
/// `PipelineData::Value`
|
||||
/// Do an engine call returning an `Option<Value>` as either `PipelineData::empty()` or
|
||||
/// `PipelineData::value`
|
||||
fn engine_call_option_value(
|
||||
&self,
|
||||
engine_call: EngineCall<PipelineData>,
|
||||
@ -786,7 +786,7 @@ impl EngineInterface {
|
||||
/// # use nu_plugin::{EngineInterface, EvaluatedCall};
|
||||
/// # fn example(engine: &EngineInterface, call: &EvaluatedCall) -> Result<(), ShellError> {
|
||||
/// let closure = call.req(0)?;
|
||||
/// let input = PipelineData::Value(Value::int(4, call.head), None);
|
||||
/// let input = PipelineData::value(Value::int(4, call.head), None);
|
||||
/// let output = engine.eval_closure_with_stream(
|
||||
/// &closure,
|
||||
/// vec![],
|
||||
@ -885,7 +885,7 @@ impl EngineInterface {
|
||||
positional: Vec<Value>,
|
||||
input: Option<Value>,
|
||||
) -> Result<Value, ShellError> {
|
||||
let input = input.map_or_else(|| PipelineData::Empty, |v| PipelineData::Value(v, None));
|
||||
let input = input.map_or_else(PipelineData::empty, |v| PipelineData::value(v, None));
|
||||
let output = self.eval_closure_with_stream(closure, positional, input, true, false)?;
|
||||
// Unwrap an error value
|
||||
match output.into_value(closure.span)? {
|
||||
@ -924,7 +924,7 @@ impl EngineInterface {
|
||||
/// let commands = engine.call_decl(
|
||||
/// decl_id,
|
||||
/// EvaluatedCall::new(call.head),
|
||||
/// PipelineData::Empty,
|
||||
/// PipelineData::empty(),
|
||||
/// true,
|
||||
/// false,
|
||||
/// )?;
|
||||
@ -1025,7 +1025,7 @@ impl Interface for EngineInterface {
|
||||
.map(|_| value)
|
||||
.unwrap_or_else(|err| Value::error(err, span))
|
||||
});
|
||||
Ok(PipelineData::ListStream(stream, meta))
|
||||
Ok(PipelineData::list_stream(stream, meta))
|
||||
}
|
||||
PipelineData::Empty | PipelineData::ByteStream(..) => Ok(data),
|
||||
}
|
||||
|
@ -583,7 +583,7 @@ fn manager_consume_engine_call_response_forwards_to_subscriber_with_pipeline_dat
|
||||
fn manager_prepare_pipeline_data_deserializes_custom_values() -> Result<(), ShellError> {
|
||||
let manager = TestCase::new().engine();
|
||||
|
||||
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,
|
||||
))?;
|
||||
@ -690,7 +690,7 @@ fn interface_write_response_with_value() -> Result<(), ShellError> {
|
||||
let test = TestCase::new();
|
||||
let interface = test.engine().interface_for_context(33);
|
||||
interface
|
||||
.write_response(Ok::<_, ShellError>(PipelineData::Value(
|
||||
.write_response(Ok::<_, ShellError>(PipelineData::value(
|
||||
Value::test_int(6),
|
||||
None,
|
||||
)))?
|
||||
@ -901,9 +901,9 @@ fn interface_get_plugin_config() -> Result<(), ShellError> {
|
||||
|
||||
start_fake_plugin_call_responder(manager, 2, |id| {
|
||||
if id == 0 {
|
||||
EngineCallResponse::PipelineData(PipelineData::Empty)
|
||||
EngineCallResponse::PipelineData(PipelineData::empty())
|
||||
} else {
|
||||
EngineCallResponse::PipelineData(PipelineData::Value(Value::test_int(2), None))
|
||||
EngineCallResponse::PipelineData(PipelineData::value(Value::test_int(2), None))
|
||||
}
|
||||
});
|
||||
|
||||
@ -1038,7 +1038,7 @@ fn interface_eval_closure_with_stream() -> Result<(), ShellError> {
|
||||
let interface = manager.interface_for_context(0);
|
||||
|
||||
start_fake_plugin_call_responder(manager, 1, |_| {
|
||||
EngineCallResponse::PipelineData(PipelineData::Value(Value::test_int(2), None))
|
||||
EngineCallResponse::PipelineData(PipelineData::value(Value::test_int(2), None))
|
||||
});
|
||||
|
||||
let result = interface
|
||||
@ -1051,7 +1051,7 @@ fn interface_eval_closure_with_stream() -> Result<(), ShellError> {
|
||||
span: Span::test_data(),
|
||||
},
|
||||
vec![Value::test_string("test")],
|
||||
PipelineData::Empty,
|
||||
PipelineData::empty(),
|
||||
true,
|
||||
false,
|
||||
)?
|
||||
@ -1100,7 +1100,7 @@ fn interface_prepare_pipeline_data_serializes_custom_values() -> Result<(), Shel
|
||||
let interface = TestCase::new().engine().get_interface();
|
||||
|
||||
let data = interface.prepare_pipeline_data(
|
||||
PipelineData::Value(
|
||||
PipelineData::value(
|
||||
Value::test_custom_value(Box::new(expected_test_custom_value())),
|
||||
None,
|
||||
),
|
||||
|
@ -600,7 +600,7 @@ fn custom_value_op(
|
||||
CustomValueOp::ToBaseValue => {
|
||||
let result = plugin
|
||||
.custom_value_to_base_value(engine, local_value)
|
||||
.map(|value| PipelineData::Value(value, None));
|
||||
.map(|value| PipelineData::value(value, None));
|
||||
engine
|
||||
.write_response(result)
|
||||
.and_then(|writer| writer.write())
|
||||
@ -608,7 +608,7 @@ fn custom_value_op(
|
||||
CustomValueOp::FollowPathInt(index) => {
|
||||
let result = plugin
|
||||
.custom_value_follow_path_int(engine, local_value, index)
|
||||
.map(|value| PipelineData::Value(value, None));
|
||||
.map(|value| PipelineData::value(value, None));
|
||||
engine
|
||||
.write_response(result)
|
||||
.and_then(|writer| writer.write())
|
||||
@ -616,7 +616,7 @@ fn custom_value_op(
|
||||
CustomValueOp::FollowPathString(column_name) => {
|
||||
let result = plugin
|
||||
.custom_value_follow_path_string(engine, local_value, column_name)
|
||||
.map(|value| PipelineData::Value(value, None));
|
||||
.map(|value| PipelineData::value(value, None));
|
||||
engine
|
||||
.write_response(result)
|
||||
.and_then(|writer| writer.write())
|
||||
@ -634,7 +634,7 @@ fn custom_value_op(
|
||||
PluginCustomValue::deserialize_custom_values_in(&mut right)?;
|
||||
let result = plugin
|
||||
.custom_value_operation(engine, local_value, operator, right)
|
||||
.map(|value| PipelineData::Value(value, None));
|
||||
.map(|value| PipelineData::value(value, None));
|
||||
engine
|
||||
.write_response(result)
|
||||
.and_then(|writer| writer.write())
|
||||
@ -642,7 +642,7 @@ fn custom_value_op(
|
||||
CustomValueOp::Dropped => {
|
||||
let result = plugin
|
||||
.custom_value_dropped(engine, local_value.item)
|
||||
.map(|_| PipelineData::Empty);
|
||||
.map(|_| PipelineData::empty());
|
||||
engine
|
||||
.write_response(result)
|
||||
.and_then(|writer| writer.write())
|
||||
|
Reference in New Issue
Block a user