Simplify print_table_or_error (#6122)

Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
nibon7 2022-07-26 01:01:10 +08:00 committed by GitHub
parent 32e4535f24
commit 3643ee6dfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -86,20 +86,7 @@ pub fn print_table_or_error(
match table { match table {
Ok(table) => { Ok(table) => {
for item in table { print_or_exit(table, engine_state, config);
if let Value::Error { error } = item {
let working_set = StateWorkingSet::new(engine_state);
report_error(&working_set, &error);
std::process::exit(1);
}
let mut out = item.into_string("\n", config);
out.push('\n');
let _ = stdout_write_all_and_flush(out).map_err(|err| eprintln!("{}", err));
}
} }
Err(error) => { Err(error) => {
let working_set = StateWorkingSet::new(engine_state); let working_set = StateWorkingSet::new(engine_state);
@ -111,20 +98,7 @@ pub fn print_table_or_error(
} }
} }
None => { None => {
for item in pipeline_data { print_or_exit(pipeline_data, engine_state, config);
if let Value::Error { error } = item {
let working_set = StateWorkingSet::new(engine_state);
report_error(&working_set, &error);
std::process::exit(1);
}
let mut out = item.into_string("\n", config);
out.push('\n');
let _ = stdout_write_all_and_flush(out).map_err(|err| eprintln!("{}", err));
}
} }
}; };
@ -141,3 +115,20 @@ pub fn print_table_or_error(
None None
} }
} }
fn print_or_exit(pipeline_data: PipelineData, engine_state: &mut EngineState, config: &Config) {
for item in pipeline_data {
if let Value::Error { error } = item {
let working_set = StateWorkingSet::new(engine_state);
report_error(&working_set, &error);
std::process::exit(1);
}
let mut out = item.into_string("\n", config);
out.push('\n');
let _ = stdout_write_all_and_flush(out).map_err(|err| eprintln!("{}", err));
}
}