mirror of
https://github.com/nushell/nushell.git
synced 2025-04-16 17:28:19 +02: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 {
|
if pipeline_idx < (num_pipelines) - 1 {
|
||||||
match input {
|
match input {
|
||||||
PipelineData::Value(Value::Nothing { .. }, ..) => {}
|
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
|
// Drain the input to the screen via tabular output
|
||||||
let config = stack.get_config().unwrap_or_default();
|
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) {
|
if let Err(e) = engine_state.merge_delta(StateDelta::new(), Some(&mut stack), cwd) {
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
report_error(&working_set, &e);
|
report_error(&working_set, &e);
|
||||||
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
report_error(&working_set, &e);
|
report_error(&working_set, &e);
|
||||||
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +109,6 @@ pub(crate) fn evaluate(
|
|||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
|
||||||
report_error(&working_set, &err);
|
report_error(&working_set, &err);
|
||||||
|
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user