Allow captured stderr saving to file (#6793)

* support redirect stderr to file

* fix test

* fix test

* fix test
This commit is contained in:
WindSoilder
2022-10-20 20:56:44 +08:00
committed by GitHub
parent d37e6ba3b5
commit 10aa86272b
4 changed files with 162 additions and 27 deletions

View File

@ -292,7 +292,8 @@ fn main() -> Result<()> {
if let Some(testbin) = &binary_args.testbin {
// Call out to the correct testbin
match testbin.item.as_str() {
"echo_env" => test_bins::echo_env(),
"echo_env" => test_bins::echo_env(true),
"echo_env_stderr" => test_bins::echo_env(false),
"cococo" => test_bins::cococo(),
"meow" => test_bins::meow(),
"meowb" => test_bins::meowb(),

View File

@ -11,11 +11,15 @@ use nu_protocol::{CliError, PipelineData, Span, Value};
/// Echo's value of env keys from args
/// Example: nu --testbin env_echo FOO BAR
/// If it it's not present echo's nothing
pub fn echo_env() {
pub fn echo_env(to_stdout: bool) {
let args = args();
for arg in args {
if let Ok(v) = std::env::var(arg) {
println!("{}", v);
if to_stdout {
println!("{}", v);
} else {
eprintln!("{}", v);
}
}
}
}