mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
add LAST_EXIT_CODE variable (#4655)
This commit is contained in:
parent
11bc056576
commit
d2bd71d2aa
2 changed files with 16 additions and 2 deletions
10
src/repl.rs
10
src/repl.rs
|
@ -86,7 +86,7 @@ pub(crate) fn evaluate(
|
|||
let exceptions = crate::utils::external_exceptions(engine_state, &stack);
|
||||
engine_state.external_exceptions = exceptions;
|
||||
|
||||
// seed the cmd_duration_ms env var
|
||||
// seed env vars
|
||||
stack.add_env_var(
|
||||
"CMD_DURATION_MS".into(),
|
||||
Value::String {
|
||||
|
@ -95,6 +95,14 @@ pub(crate) fn evaluate(
|
|||
},
|
||||
);
|
||||
|
||||
stack.add_env_var(
|
||||
"LAST_EXIT_CODE".into(),
|
||||
Value::Int {
|
||||
val: 0,
|
||||
span: Span { start: 0, end: 0 },
|
||||
},
|
||||
);
|
||||
|
||||
loop {
|
||||
if is_perf_true() {
|
||||
info!(
|
||||
|
|
|
@ -227,7 +227,13 @@ pub(crate) fn eval_source(
|
|||
}
|
||||
|
||||
match eval_block(engine_state, stack, &block, input, false, false) {
|
||||
Ok(pipeline_data) => {
|
||||
Ok(mut pipeline_data) => {
|
||||
if let PipelineData::ExternalStream { exit_code, .. } = &mut pipeline_data {
|
||||
if let Some(exit_code) = exit_code.take().and_then(|it| it.last()) {
|
||||
stack.add_env_var("LAST_EXIT_CODE".to_string(), exit_code);
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(err) = print_pipeline_data(pipeline_data, engine_state, stack) {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
|
||||
|
|
Loading…
Reference in a new issue