format: remove extra spaces from error output

This commit is contained in:
iff 2023-07-31 11:03:50 +02:00
parent b16dc1dd5b
commit ee7e6886b9
3 changed files with 15 additions and 5 deletions

View file

@ -34,9 +34,10 @@ Syntax of a rule file (placed under [rules](./rules)):
# this field should be the name of the command # this field should be the name of the command
command = "world" command = "world"
# you can add as much section of this as you like # you can add as many `[[match_err]]` section as you want
[[match_output]] [[match_err]]
# the suggestion of this section will be used for the following patterns of the command output # 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 = [
"pattern 1", "pattern 1",
"pattern 2", "pattern 2",
@ -44,7 +45,7 @@ pattern = [
# this will change the first argument to `fix`, while keeping the rest intact # this will change the first argument to `fix`, while keeping the rest intact
suggest = "{{command[0]}} fix {{command[2:]}}" suggest = "{{command[0]}} fix {{command[2:]}}"
[[match_output]] [[match_err]]
pattern = [ pattern = [
"pattern 1", "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 - `cmd_contains`: Check if the last user input contains the argument
- `err_contains`: Check if the error of the command contains the argument - `err_contains`: Check if the error of the command contains the argument
## Current Progress ## Current Progress
We need more rule files! We need more rule files!

View file

@ -49,7 +49,11 @@ fn gen_string_hashmap(rules: Vec<Rule>) -> String {
.iter() .iter()
.map(|x| x.to_lowercase()) .map(|x| x.to_lowercase())
.collect::<Vec<String>>(); .collect::<Vec<String>>();
let suggest = match_err.suggest; let suggest = match_err.
suggest
.iter()
.map(|x| x.to_lowercase())
.collect::<Vec<String>>();
string_hashmap.push_str(&format!( string_hashmap.push_str(&format!(
"(vec![\"{}\"], vec![\"{}\"]),", "(vec![\"{}\"], vec![\"{}\"]),",
pattern.join("\", \""), pattern.join("\", \""),

View file

@ -61,6 +61,9 @@ pub fn command_output(shell: &str, command: &str) -> String {
String::from_utf8_lossy(&output.stderr) String::from_utf8_lossy(&output.stderr)
.to_string() .to_string()
.split_whitespace()
.collect::<Vec<&str>>()
.join(" ")
.to_lowercase() .to_lowercase()
} }