From dbb54cab96216be96108081f6cbb4770c316fe21 Mon Sep 17 00:00:00 2001 From: dark0dave Date: Sat, 2 Dec 2023 14:43:11 +0000 Subject: [PATCH] fix(exit): Exit if successs found Signed-off-by: dark0dave --- src/weidu_parser.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/weidu_parser.rs b/src/weidu_parser.rs index d59249a..31e4ae4 100644 --- a/src/weidu_parser.rs +++ b/src/weidu_parser.rs @@ -31,6 +31,8 @@ const WEIDU_COMPLETED_WITH_WARNINGS: &str = "installed with warnings"; const WEIDU_FAILED_WITH_ERROR: &str = "not installed due to errors"; +const WEIDU_FINISHED: &str = "successfully installed"; + #[derive(Debug)] enum ParserState { CollectingQuestion, @@ -99,6 +101,7 @@ pub fn parse_raw_output(sender: Sender, receiver: Receiver) { question = String::new(); } _ => { + // TODO: Exit here if we come here too much // there is no new weidu output and we are not waiting for any, so there is nothing to do } } @@ -137,6 +140,8 @@ fn detect_weidu_finished_state(weidu_output: &str) -> Option { }) } else if comparable_output.contains(WEIDU_COMPLETED_WITH_WARNINGS) { Some(State::CompletedWithWarnings) + } else if comparable_output.contains(WEIDU_FINISHED) { + Some(State::Completed) } else { None } @@ -153,4 +158,9 @@ mod tests { Some(State::CompletedWithWarnings) ) } + #[test] + fn test_exit_success() { + let test = "SUCCESSFULLY INSTALLED Jan's Extended Quest"; + assert_eq!(detect_weidu_finished_state(test), Some(State::Completed)) + } }