fix exit code (#5835)

* fix exit code

* fix usage

* add comment
This commit is contained in:
WindSoilder
2022-06-20 22:05:11 +08:00
committed by GitHub
parent dbcfcdae89
commit fab3f8fd40
4 changed files with 33 additions and 7 deletions

View File

@ -18,7 +18,7 @@ pub fn evaluate_commands(
input: PipelineData,
is_perf_true: bool,
table_mode: Option<Value>,
) -> Result<()> {
) -> Result<Option<i64>> {
// Run a command (or commands) given to us by the user
let (block, delta) = {
if let Some(ref t_mode) = table_mode {
@ -74,7 +74,7 @@ pub fn evaluate_commands(
std::process::exit(1);
}
match eval_block(engine_state, stack, &block, input, false, false) {
let exit_code = match eval_block(engine_state, stack, &block, input, false, false) {
Ok(pipeline_data) => {
crate::eval_file::print_table_or_error(engine_state, stack, pipeline_data, &mut config)
}
@ -84,11 +84,11 @@ pub fn evaluate_commands(
report_error(&working_set, &err);
std::process::exit(1);
}
}
};
if is_perf_true {
info!("evaluate {}:{}:{}", file!(), line!(), column!());
}
Ok(())
Ok(exit_code)
}

View File

@ -66,7 +66,7 @@ pub fn print_table_or_error(
stack: &mut Stack,
mut pipeline_data: PipelineData,
config: &mut Config,
) {
) -> Option<i64> {
let exit_code = match &mut pipeline_data {
PipelineData::ExternalStream { exit_code, .. } => exit_code.take(),
_ => None,
@ -130,6 +130,14 @@ 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();
let mut exit_code: Vec<_> = exit_code.into_iter().collect();
exit_code
.pop()
.and_then(|last_exit_code| match last_exit_code {
Value::Int { val: code, .. } => Some(code),
_ => None,
})
} else {
None
}
}