From c4c208c15575e64907291d4567cd72d5ceb7c0ef Mon Sep 17 00:00:00 2001 From: Henrique Alves Date: Tue, 26 Jul 2022 11:16:51 -0300 Subject: Asserting results form shell commands --- src/utils.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index e925f9d..81bd63f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,6 @@ use colored::Colorize; use std::io::Write; +use std::process::exit; pub fn log_warning(msg: &str) { let msg = format!("⚠️ {}", msg).yellow(); @@ -21,6 +22,14 @@ pub fn log_check(msg: &str) { println!("{}", msg); } +pub fn assert_res(res : &Result, error_msg : &str) { + if res.is_err() { + log_error(error_msg); + log_error(&format!("{:?}", res)); + exit(1); + } +} + pub fn get_repo_name(repo: &str) -> String { let mut chars = repo.chars().rev(); let length = repo.chars().count(); -- cgit v1.2.3