forked from extern/nushell
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();
|
||||
|
||||
for (pipeline_idx, pipeline) in block.pipelines.iter().enumerate() {
|
||||
let mut i = 0;
|
||||
|
||||
while i < pipeline.elements.len() {
|
||||
let mut elements_iter = pipeline.elements.iter().peekable();
|
||||
while let Some(element) = elements_iter.next() {
|
||||
let redirect_stderr = redirect_stderr
|
||||
|| ((i < pipeline.elements.len() - 1)
|
||||
&& (matches!(
|
||||
pipeline.elements[i + 1],
|
||||
|| (elements_iter.peek().map_or(false, |next_element| {
|
||||
matches!(
|
||||
next_element,
|
||||
PipelineElement::Redirection(_, Redirection::Stderr, _)
|
||||
| PipelineElement::Redirection(_, Redirection::StdoutAndStderr, _)
|
||||
| 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)`.
|
||||
let eval_result = eval_element_with_input(
|
||||
engine_state,
|
||||
stack,
|
||||
&pipeline.elements[i],
|
||||
element,
|
||||
input,
|
||||
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_stdout,
|
||||
redirect_stderr,
|
||||
);
|
||||
|
||||
@ -1073,8 +1076,6 @@ pub fn eval_block(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
if pipeline_idx < (num_pipelines) - 1 {
|
||||
|
Loading…
Reference in New Issue
Block a user