From ee7e6886b96284ad021065834f557691ec4b3854 Mon Sep 17 00:00:00 2001 From: iff Date: Mon, 31 Jul 2023 11:03:50 +0200 Subject: [PATCH] format: remove extra spaces from error output --- README.md | 11 +++++++---- rule_parser/src/lib.rs | 6 +++++- src/shell.rs | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cf62e7f..7d8797a 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,10 @@ Syntax of a rule file (placed under [rules](./rules)): # this field should be the name of the command command = "world" -# you can add as much section of this as you like -[[match_output]] -# the suggestion of this section will be used for the following patterns of the command output +# you can add as many `[[match_err]]` section as you want +[[match_err]] +# the suggestion of this section will be used for the following patterns of the error output +# note that the error is formatted to lowercase without extra spaces pattern = [ "pattern 1", "pattern 2", @@ -44,7 +45,7 @@ pattern = [ # this will change the first argument to `fix`, while keeping the rest intact suggest = "{{command[0]}} fix {{command[2:]}}" -[[match_output]] +[[match_err]] pattern = [ "pattern 1", ] @@ -68,6 +69,8 @@ The suggestion can have additional conditions to check. To specify the condition - `cmd_contains`: Check if the last user input contains the argument - `err_contains`: Check if the error of the command contains the argument + + ## Current Progress We need more rule files! diff --git a/rule_parser/src/lib.rs b/rule_parser/src/lib.rs index 7beb7e2..8b24edb 100644 --- a/rule_parser/src/lib.rs +++ b/rule_parser/src/lib.rs @@ -49,7 +49,11 @@ fn gen_string_hashmap(rules: Vec) -> String { .iter() .map(|x| x.to_lowercase()) .collect::>(); - let suggest = match_err.suggest; + let suggest = match_err. + suggest + .iter() + .map(|x| x.to_lowercase()) + .collect::>(); string_hashmap.push_str(&format!( "(vec![\"{}\"], vec![\"{}\"]),", pattern.join("\", \""), diff --git a/src/shell.rs b/src/shell.rs index 05f30b0..a3843f2 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -61,6 +61,9 @@ pub fn command_output(shell: &str, command: &str) -> String { String::from_utf8_lossy(&output.stderr) .to_string() + .split_whitespace() + .collect::>() + .join(" ") .to_lowercase() }