From 1d26ca5c7ecec06978daad08b7875426078e8732 Mon Sep 17 00:00:00 2001 From: iff Date: Tue, 19 Nov 2024 03:09:55 +0100 Subject: [PATCH] fix: actually using the regex capture --- rules/cargo.toml | 55 ++-------------------------------------------- src/suggestions.rs | 12 +++++----- 2 files changed, 8 insertions(+), 59 deletions(-) diff --git a/rules/cargo.toml b/rules/cargo.toml index 9f16553..5b6f076 100644 --- a/rules/cargo.toml +++ b/rules/cargo.toml @@ -2,61 +2,10 @@ command = "cargo" [[match_err]] pattern = [ - "no such command" + "did you mean" ] suggest = [ ''' -{{command[0]}} {{typo[1]( -add, -b, -bench, -build, -c, -check, -clean, -clippy, -config, -d, -doc, -expand, -fetch, -fix, -fmt, -generate-lockfile, -git-checkout, -help, -init, -install, -lipo, -locate-project, -login, -logout, -make, -metadata, -miri, -new, -owner, -package, -pkgid, -publish, -r, -read-manifest, -remove, -report, -rm, -run, -rustc, -rustdoc, -search, -t, -test, -tree, -uninstall, -update, -vendor, -verify-project, -version, -yank -)}} {{command[2:]}}''' +{{command[0]}} {{err::(?:did you mean `)(.*)(?:`)}} {{command[2:]}} ''' ] diff --git a/src/suggestions.rs b/src/suggestions.rs index 724ff97..3e2bec9 100644 --- a/src/suggestions.rs +++ b/src/suggestions.rs @@ -81,8 +81,8 @@ pub fn check_executable(shell: &str, executable: &str) -> bool { pub fn opt_regex(regex: &str, command: &mut String) -> String { let regex = Regex::new(regex).unwrap(); let opts = regex - .find_iter(command) - .map(|cap| cap.as_str().to_owned()) + .captures_iter(command) + .map(|cap| cap.get(1).unwrap().as_str().to_owned()) .collect::>(); for opt in opts.clone() { *command = command.replace(&opt, ""); @@ -94,8 +94,8 @@ pub fn opt_regex(regex: &str, command: &mut String) -> String { pub fn err_regex(regex: &str, error_msg: &str) -> String { let regex = Regex::new(regex).unwrap(); let err = regex - .find_iter(error_msg) - .map(|cap| cap.as_str().to_owned()) + .captures_iter(error_msg) + .map(|cap| cap.get(1).unwrap().as_str().to_owned()) .collect::>(); err.join(" ") @@ -104,8 +104,8 @@ pub fn err_regex(regex: &str, error_msg: &str) -> String { pub fn cmd_regex(regex: &str, command: &str) -> String { let regex = Regex::new(regex).unwrap(); let err = regex - .find_iter(command) - .map(|cap| cap.as_str().to_owned()) + .captures_iter(command) + .map(|cap| cap.get(1).unwrap().as_str().to_owned()) .collect::>(); err.join(" ")