From 06f4d449f44fb2f1b3f7edfdffcd223a54bc9a7d Mon Sep 17 00:00:00 2001 From: iff Date: Mon, 31 Jul 2023 10:25:12 +0200 Subject: [PATCH] fix: trim only parenthesis for argument --- src/corrections.rs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/corrections.rs b/src/corrections.rs index 07ebcc9..d64d5e1 100644 --- a/src/corrections.rs +++ b/src/corrections.rs @@ -58,23 +58,19 @@ fn check_suggest(suggest: &str, command: &str, error_msg: &str) -> Option>(); - let conditions = lines.first().unwrap().trim().replacen("#", "", 1); - let conditions = conditions - .trim_start_matches('[') - .trim_end_matches(']'); - let conditions = conditions - .split(",") - .collect::>() ; + let conditions = lines.first().unwrap().trim().replacen('#', "", 1); + let conditions = conditions.trim_start_matches('[').trim_end_matches(']'); + let conditions = conditions.split(',').collect::>(); for condition in conditions { let (mut condition, arg) = condition.split_once('(').unwrap(); condition = condition.trim(); - let arg = arg.trim_matches(|c| c == '(' || c == ')'); + let arg = arg.trim_start_matches('(').trim_end_matches(')'); let reverse = match condition.starts_with('!') { true => { condition = condition.trim_start_matches('!'); true - }, + } false => false, }; if eval_condition(condition, arg, command, error_msg) == reverse { @@ -92,14 +88,10 @@ fn eval_condition(condition: &str, arg: &str, command: &str, error_msg: &str) -> .output() .expect("failed to execute process"); output.status.success() - }, - "err_contains" => { - error_msg.contains(arg) - }, - "cmd_contains" => { - command.contains(arg) - }, - _ => unreachable!("Unknown condition when evaluation condition: {}", condition) + } + "err_contains" => error_msg.contains(arg), + "cmd_contains" => command.contains(arg), + _ => unreachable!("Unknown condition when evaluation condition: {}", condition), } }