mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 22:40:09 +01:00
fix: trim only parenthesis for argument
This commit is contained in:
parent
adbb37a17e
commit
06f4d449f4
1 changed files with 9 additions and 17 deletions
|
|
@ -58,23 +58,19 @@ fn check_suggest(suggest: &str, command: &str, error_msg: &str) -> Option<String
|
||||||
return Some(suggest.to_owned());
|
return Some(suggest.to_owned());
|
||||||
}
|
}
|
||||||
let lines = suggest.lines().collect::<Vec<&str>>();
|
let lines = suggest.lines().collect::<Vec<&str>>();
|
||||||
let conditions = lines.first().unwrap().trim().replacen("#", "", 1);
|
let conditions = lines.first().unwrap().trim().replacen('#', "", 1);
|
||||||
let conditions = conditions
|
let conditions = conditions.trim_start_matches('[').trim_end_matches(']');
|
||||||
.trim_start_matches('[')
|
let conditions = conditions.split(',').collect::<Vec<&str>>();
|
||||||
.trim_end_matches(']');
|
|
||||||
let conditions = conditions
|
|
||||||
.split(",")
|
|
||||||
.collect::<Vec<&str>>() ;
|
|
||||||
|
|
||||||
for condition in conditions {
|
for condition in conditions {
|
||||||
let (mut condition, arg) = condition.split_once('(').unwrap();
|
let (mut condition, arg) = condition.split_once('(').unwrap();
|
||||||
condition = condition.trim();
|
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('!') {
|
let reverse = match condition.starts_with('!') {
|
||||||
true => {
|
true => {
|
||||||
condition = condition.trim_start_matches('!');
|
condition = condition.trim_start_matches('!');
|
||||||
true
|
true
|
||||||
},
|
}
|
||||||
false => false,
|
false => false,
|
||||||
};
|
};
|
||||||
if eval_condition(condition, arg, command, error_msg) == reverse {
|
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()
|
.output()
|
||||||
.expect("failed to execute process");
|
.expect("failed to execute process");
|
||||||
output.status.success()
|
output.status.success()
|
||||||
},
|
}
|
||||||
"err_contains" => {
|
"err_contains" => error_msg.contains(arg),
|
||||||
error_msg.contains(arg)
|
"cmd_contains" => command.contains(arg),
|
||||||
},
|
_ => unreachable!("Unknown condition when evaluation condition: {}", condition),
|
||||||
"cmd_contains" => {
|
|
||||||
command.contains(arg)
|
|
||||||
},
|
|
||||||
_ => unreachable!("Unknown condition when evaluation condition: {}", condition)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue