mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
ensure exit codes in more cases (#4803)
This commit is contained in:
parent
12bf23faa6
commit
9abb14b5fd
2 changed files with 24 additions and 14 deletions
|
@ -19,13 +19,22 @@ pub fn print_pipeline_data(
|
|||
let stdout = std::io::stdout();
|
||||
|
||||
if let PipelineData::ExternalStream {
|
||||
stdout: Some(stream),
|
||||
stdout: stream,
|
||||
exit_code,
|
||||
..
|
||||
} = input
|
||||
{
|
||||
for s in stream {
|
||||
let _ = stdout.lock().write_all(s?.as_binary()?);
|
||||
if let Some(stream) = stream {
|
||||
for s in stream {
|
||||
let _ = stdout.lock().write_all(s?.as_binary()?);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure everything has finished
|
||||
if let Some(exit_code) = exit_code {
|
||||
let _: Vec<_> = exit_code.into_iter().collect();
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
|
@ -87,9 +87,14 @@ pub(crate) fn evaluate(
|
|||
pub fn print_table_or_error(
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
pipeline_data: PipelineData,
|
||||
mut pipeline_data: PipelineData,
|
||||
config: &Config,
|
||||
) {
|
||||
let exit_code = match &mut pipeline_data {
|
||||
PipelineData::ExternalStream { exit_code, .. } => exit_code.take(),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
match engine_state.find_decl("table".as_bytes()) {
|
||||
Some(decl_id) => {
|
||||
let table = engine_state.get_decl(decl_id).run(
|
||||
|
@ -100,12 +105,7 @@ pub fn print_table_or_error(
|
|||
);
|
||||
|
||||
match table {
|
||||
Ok(mut table) => {
|
||||
let exit_code = match &mut table {
|
||||
PipelineData::ExternalStream { exit_code, .. } => exit_code.take(),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
Ok(table) => {
|
||||
for item in table {
|
||||
let stdout = std::io::stdout();
|
||||
|
||||
|
@ -125,10 +125,6 @@ pub fn print_table_or_error(
|
|||
Err(err) => eprintln!("{}", err),
|
||||
};
|
||||
}
|
||||
|
||||
if let Some(exit_code) = exit_code {
|
||||
let _: Vec<_> = exit_code.into_iter().collect();
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
|
@ -161,4 +157,9 @@ pub fn print_table_or_error(
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Make sure everything has finished
|
||||
if let Some(exit_code) = exit_code {
|
||||
let _: Vec<_> = exit_code.into_iter().collect();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue