From 16dc05992adf7ce5f6d9fbd0747d8b7703181789 Mon Sep 17 00:00:00 2001 From: rascul Date: Sat, 23 Jul 2022 12:04:26 -0500 Subject: [PATCH] use false as default instead of Option --- src/app.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app.rs b/src/app.rs index 1a95c52..20f5b6f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -19,13 +19,16 @@ pub struct App { pub args: Option>, /// should the app be restarted if it exits successfully - pub restart_on_success: Option, + #[serde(default = "ret_false")] + pub restart_on_success: bool, /// should the app be restarted if it exits unsuccessfully - pub restart_on_failure: Option, + #[serde(default = "ret_false")] + pub restart_on_failure: bool, /// should the app be restarted if it is killed (SIGKILL) - pub restart_on_terminate: Option, + #[serde(default = "ret_false")] + pub restart_on_terminate: bool, /// on sup startup, should we wait for this app to run before continuting pub wait: Option, @@ -34,6 +37,10 @@ pub struct App { pub hold: Option, } +fn ret_false() -> bool { + false +} + impl App { /// start the application and wait for it to exit pub fn wait_start(&self) -> Result<()> { @@ -66,11 +73,11 @@ impl App { /// see if the app should be restarted pub fn check_restart(&self, status: ExitStatus) -> bool { if status.success() { - self.restart_on_success.unwrap_or(false) + self.restart_on_success } else if let Some(_code) = status.code() { - self.restart_on_failure.unwrap_or(false) + self.restart_on_failure } else { - self.restart_on_terminate.unwrap_or(false) + self.restart_on_terminate } } }