From b9e2263e0395a9b961b6f68269d2356620ed16bb Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Mon, 2 Sep 2024 06:59:47 +0200 Subject: [PATCH] fix: return exitcode --- src/application.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/application.rs b/src/application.rs index 63513b618..40c42701c 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,11 +1,11 @@ //! Rustic Abscissa Application -use std::env; +use std::{env, process}; use abscissa_core::{ - application::{self, AppCell}, + application::{self, fatal_error, AppCell}, config::{self, CfgCell}, terminal::component::Terminal, - Application, Component, FrameworkError, StandardPaths, + Application, Component, FrameworkError, Shutdown, StandardPaths, }; use anyhow::Result; @@ -99,4 +99,24 @@ impl Application for RusticApp { Ok(()) } + + /// Shut down this application gracefully + fn shutdown(&self, shutdown: Shutdown) -> ! { + let exit_code = match shutdown { + Shutdown::Crash => 1, + _ => 0, + }; + self.shutdown_with_exitcode(shutdown, exit_code) + } +} + +impl RusticApp { + /// Shut down this application gracefully, exiting with given exit code. + fn shutdown_with_exitcode(&self, shutdown: Shutdown, exit_code: i32) -> ! { + if let Err(e) = self.state().components().shutdown(self, shutdown) { + fatal_error(self, &e) + } + + process::exit(exit_code); + } }