fix redirection to save
This commit is contained in:
parent
b7225f4c0e
commit
855b76eb2f
|
@ -1,7 +1,7 @@
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{Block, Pipeline, PipelineRedirection, RedirectionSource},
|
ast::{Block, Pipeline, PipelineRedirection, RedirectionSource},
|
||||||
engine::StateWorkingSet,
|
engine::StateWorkingSet,
|
||||||
ir::{Instruction, IrBlock},
|
ir::{Instruction, IrBlock, RedirectMode},
|
||||||
CompileError, IntoSpanned, RegId, Span,
|
CompileError, IntoSpanned, RegId, Span,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,20 +113,24 @@ fn compile_pipeline(
|
||||||
// element, then it's from whatever is passed in as the mode to use.
|
// element, then it's from whatever is passed in as the mode to use.
|
||||||
|
|
||||||
let next_redirect_modes = if let Some(next_element) = iter.peek() {
|
let next_redirect_modes = if let Some(next_element) = iter.peek() {
|
||||||
// If there's a next element we always pipe out *unless* this is a single redirection
|
let mut modes = redirect_modes_of_expression(working_set, &next_element.expr, span)?;
|
||||||
// to stderr (e>|)
|
|
||||||
let modes = redirect_modes_of_expression(working_set, &next_element.expr, span)?;
|
// If there's a next element with no inherent redirection we always pipe out *unless*
|
||||||
if matches!(
|
// this is a single redirection to stderr (e>|)
|
||||||
element.redirection,
|
if modes.out.is_none()
|
||||||
Some(PipelineRedirection::Single {
|
&& !matches!(
|
||||||
source: RedirectionSource::Stderr,
|
element.redirection,
|
||||||
..
|
Some(PipelineRedirection::Single {
|
||||||
})
|
source: RedirectionSource::Stderr,
|
||||||
) {
|
..
|
||||||
modes
|
})
|
||||||
} else {
|
)
|
||||||
modes.with_pipe_out(next_element.pipe.unwrap_or(next_element.expr.span))
|
{
|
||||||
|
let pipe_span = next_element.pipe.unwrap_or(next_element.expr.span);
|
||||||
|
modes.out = Some(RedirectMode::Pipe.into_spanned(pipe_span));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modes
|
||||||
} else {
|
} else {
|
||||||
redirect_modes
|
redirect_modes
|
||||||
.take()
|
.take()
|
||||||
|
|
|
@ -28,13 +28,6 @@ impl RedirectModes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn with_pipe_out(&self, span: Span) -> Self {
|
|
||||||
RedirectModes {
|
|
||||||
out: Some(RedirectMode::Pipe.into_spanned(span)),
|
|
||||||
err: self.err.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn with_capture_out(&self, span: Span) -> Self {
|
pub(crate) fn with_capture_out(&self, span: Span) -> Self {
|
||||||
RedirectModes {
|
RedirectModes {
|
||||||
out: Some(RedirectMode::Capture.into_spanned(span)),
|
out: Some(RedirectMode::Capture.into_spanned(span)),
|
||||||
|
@ -134,7 +127,7 @@ pub(crate) fn finish_redirection(
|
||||||
builder.push(Instruction::CloseFile { file_num }.into_spanned(span))?;
|
builder.push(Instruction::CloseFile { file_num }.into_spanned(span))?;
|
||||||
}
|
}
|
||||||
Some(Spanned {
|
Some(Spanned {
|
||||||
item: RedirectMode::Pipe | RedirectMode::Capture,
|
item: RedirectMode::Pipe,
|
||||||
span,
|
span,
|
||||||
}) => {
|
}) => {
|
||||||
builder.push(Instruction::CheckErrRedirected { src: out_reg }.into_spanned(span))?;
|
builder.push(Instruction::CheckErrRedirected { src: out_reg }.into_spanned(span))?;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user