mirror of
https://github.com/nushell/nushell.git
synced 2025-02-02 11:39:55 +01:00
chore: Small refactor of eval.rs
(#10554)
# Description - Extract long expression in `eval.rs` into variable - Improve loop in eval.rs # User-Facing Changes None
This commit is contained in:
parent
50039164f1
commit
85d6529f0d
@ -1015,33 +1015,36 @@ pub fn eval_block(
|
|||||||
let num_pipelines = block.len();
|
let num_pipelines = block.len();
|
||||||
|
|
||||||
for (pipeline_idx, pipeline) in block.pipelines.iter().enumerate() {
|
for (pipeline_idx, pipeline) in block.pipelines.iter().enumerate() {
|
||||||
let mut i = 0;
|
let mut elements_iter = pipeline.elements.iter().peekable();
|
||||||
|
while let Some(element) = elements_iter.next() {
|
||||||
while i < pipeline.elements.len() {
|
|
||||||
let redirect_stderr = redirect_stderr
|
let redirect_stderr = redirect_stderr
|
||||||
|| ((i < pipeline.elements.len() - 1)
|
|| (elements_iter.peek().map_or(false, |next_element| {
|
||||||
&& (matches!(
|
matches!(
|
||||||
pipeline.elements[i + 1],
|
next_element,
|
||||||
PipelineElement::Redirection(_, Redirection::Stderr, _)
|
PipelineElement::Redirection(_, Redirection::Stderr, _)
|
||||||
| PipelineElement::Redirection(_, Redirection::StdoutAndStderr, _)
|
| PipelineElement::Redirection(_, Redirection::StdoutAndStderr, _)
|
||||||
| PipelineElement::SeparateRedirection { .. }
|
| PipelineElement::SeparateRedirection { .. }
|
||||||
)));
|
)
|
||||||
|
}));
|
||||||
|
|
||||||
|
let redirect_stdout = redirect_stdout
|
||||||
|
|| (elements_iter.peek().map_or(false, |next_element| {
|
||||||
|
matches!(
|
||||||
|
next_element,
|
||||||
|
PipelineElement::Redirection(_, Redirection::Stdout, _)
|
||||||
|
| PipelineElement::Redirection(_, Redirection::StdoutAndStderr, _)
|
||||||
|
| PipelineElement::Expression(..)
|
||||||
|
| PipelineElement::SeparateRedirection { .. }
|
||||||
|
)
|
||||||
|
}));
|
||||||
|
|
||||||
// if eval internal command failed, it can just make early return with `Err(ShellError)`.
|
// if eval internal command failed, it can just make early return with `Err(ShellError)`.
|
||||||
let eval_result = eval_element_with_input(
|
let eval_result = eval_element_with_input(
|
||||||
engine_state,
|
engine_state,
|
||||||
stack,
|
stack,
|
||||||
&pipeline.elements[i],
|
element,
|
||||||
input,
|
input,
|
||||||
redirect_stdout
|
redirect_stdout,
|
||||||
|| (i != pipeline.elements.len() - 1)
|
|
||||||
&& (matches!(
|
|
||||||
pipeline.elements[i + 1],
|
|
||||||
PipelineElement::Redirection(_, Redirection::Stdout, _)
|
|
||||||
| PipelineElement::Redirection(_, Redirection::StdoutAndStderr, _)
|
|
||||||
| PipelineElement::Expression(..)
|
|
||||||
| PipelineElement::SeparateRedirection { .. }
|
|
||||||
)),
|
|
||||||
redirect_stderr,
|
redirect_stderr,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1073,8 +1076,6 @@ pub fn eval_block(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if pipeline_idx < (num_pipelines) - 1 {
|
if pipeline_idx < (num_pipelines) - 1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user