Skip to content

Commit

Permalink
fix: return exitcode (#1220)
Browse files Browse the repository at this point in the history
rustic now returns an error code for failing command.

Note: Some command do not fail yet fail in every cases user would expect
is. Most notably the `check` ckommand producing `error` messages may
still return error code 0.

closes #927
  • Loading branch information
aawsome authored Sep 7, 2024
1 parent 9cada7e commit ffe05f5
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/application.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -99,4 +99,25 @@ 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) -> ! {
let result = self.state().components().shutdown(self, shutdown);
if let Err(e) = result {
fatal_error(self, &e)
}

process::exit(exit_code);
}
}

0 comments on commit ffe05f5

Please sign in to comment.