mirror of
https://github.com/nushell/nushell.git
synced 2025-04-14 16:28:17 +02:00
Fix pipe redirection into complete
(#12818)
# Description Fixes #12796 where a combined out and err pipe redirection (`o+e>|`) into `complete` still provides separate `stdout` and `stderr` columns in the record. Now, the combined output will be in the `stdout` column. This PR also fixes a similar error with the `e>|` pipe redirection. # Tests + Formatting Added two tests.
This commit is contained in:
parent
b9a7faad5a
commit
cab86f49c0
@ -92,3 +92,16 @@ fn capture_error_with_both_stdout_stderr_messages_not_hang_nushell() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn combined_pipe_redirection() {
|
||||||
|
let actual = nu!("$env.FOO = hello; $env.BAR = world; nu --testbin echo_env_mixed out-err FOO BAR o+e>| complete | get stdout");
|
||||||
|
assert_eq!(actual.out, "helloworld");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn err_pipe_redirection() {
|
||||||
|
let actual =
|
||||||
|
nu!("$env.FOO = hello; nu --testbin echo_env_stderr FOO e>| complete | get stdout");
|
||||||
|
assert_eq!(actual.out, "hello");
|
||||||
|
}
|
||||||
|
@ -340,7 +340,13 @@ fn eval_redirection<D: DebugContext>(
|
|||||||
}
|
}
|
||||||
Ok(Redirection::file(options.create(true).open(path)?))
|
Ok(Redirection::file(options.create(true).open(path)?))
|
||||||
}
|
}
|
||||||
RedirectionTarget::Pipe { .. } => Ok(Redirection::Pipe(next_out.unwrap_or(OutDest::Pipe))),
|
RedirectionTarget::Pipe { .. } => {
|
||||||
|
let dest = match next_out {
|
||||||
|
None | Some(OutDest::Capture) => OutDest::Pipe,
|
||||||
|
Some(next) => next,
|
||||||
|
};
|
||||||
|
Ok(Redirection::Pipe(dest))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,11 +373,12 @@ fn eval_element_redirection<D: DebugContext>(
|
|||||||
} => {
|
} => {
|
||||||
let stderr = eval_redirection::<D>(engine_state, stack, target, None)?;
|
let stderr = eval_redirection::<D>(engine_state, stack, target, None)?;
|
||||||
if matches!(stderr, Redirection::Pipe(OutDest::Pipe)) {
|
if matches!(stderr, Redirection::Pipe(OutDest::Pipe)) {
|
||||||
|
let dest = match next_out {
|
||||||
|
None | Some(OutDest::Capture) => OutDest::Pipe,
|
||||||
|
Some(next) => next,
|
||||||
|
};
|
||||||
// e>| redirection, don't override current stack `stdout`
|
// e>| redirection, don't override current stack `stdout`
|
||||||
Ok((
|
Ok((None, Some(Redirection::Pipe(dest))))
|
||||||
None,
|
|
||||||
Some(next_out.map(Redirection::Pipe).unwrap_or(stderr)),
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Ok((next_out.map(Redirection::Pipe), Some(stderr)))
|
Ok((next_out.map(Redirection::Pipe), Some(stderr)))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user