mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 02:13:47 +01:00
Add more exit code support (#4730)
This commit is contained in:
parent
cd721fc363
commit
9c17c73d5f
@ -600,6 +600,66 @@ pub fn eval_block(
|
||||
if pipeline_idx < (num_pipelines) - 1 {
|
||||
match input {
|
||||
PipelineData::Value(Value::Nothing { .. }, ..) => {}
|
||||
PipelineData::ExternalStream {
|
||||
ref mut exit_code, ..
|
||||
} => {
|
||||
let exit_code = exit_code.take();
|
||||
|
||||
// Drain the input to the screen via tabular output
|
||||
let config = stack.get_config().unwrap_or_default();
|
||||
|
||||
match engine_state.find_decl("table".as_bytes()) {
|
||||
Some(decl_id) => {
|
||||
let table = engine_state.get_decl(decl_id).run(
|
||||
engine_state,
|
||||
stack,
|
||||
&Call::new(Span::new(0, 0)),
|
||||
input,
|
||||
)?;
|
||||
|
||||
for item in table {
|
||||
let stdout = std::io::stdout();
|
||||
|
||||
if let Value::Error { error } = item {
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
let mut out = item.into_string("\n", &config);
|
||||
out.push('\n');
|
||||
|
||||
match stdout.lock().write_all(out.as_bytes()) {
|
||||
Ok(_) => (),
|
||||
Err(err) => eprintln!("{}", err),
|
||||
};
|
||||
}
|
||||
}
|
||||
None => {
|
||||
for item in input {
|
||||
let stdout = std::io::stdout();
|
||||
|
||||
if let Value::Error { error } = item {
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
let mut out = item.into_string("\n", &config);
|
||||
out.push('\n');
|
||||
|
||||
match stdout.lock().write_all(out.as_bytes()) {
|
||||
Ok(_) => (),
|
||||
Err(err) => eprintln!("{}", err),
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(exit_code) = exit_code {
|
||||
let mut v: Vec<_> = exit_code.collect();
|
||||
|
||||
if let Some(v) = v.pop() {
|
||||
stack.add_env_var("LAST_EXIT_CODE".into(), v);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// Drain the input to the screen via tabular output
|
||||
let config = stack.get_config().unwrap_or_default();
|
||||
|
@ -84,11 +84,13 @@ pub(crate) fn evaluate(
|
||||
if let Err(e) = engine_state.merge_delta(StateDelta::new(), Some(&mut stack), cwd) {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
report_error(&working_set, &e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
report_error(&working_set, &e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +109,6 @@ pub(crate) fn evaluate(
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
|
||||
report_error(&working_set, &err);
|
||||
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user