Skip to content

Commit

Permalink
ENH: Unpack the command output for "conda mistype" (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizvbo authored Mar 25, 2024
1 parent 1a3978e commit c8008a3
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/rules/conda_mistype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ pub fn match_rule(command: &mut CrabCommand, system_shell: Option<&dyn Shell>) -
}

pub fn get_new_command(command: &mut CrabCommand, system_shell: Option<&dyn Shell>) -> Vec<String> {
let re = Regex::new(r"'conda ([^']*)'").unwrap();
let matches = re
.captures_iter(command.output.as_ref().unwrap())
.map(|cap| cap[1].to_owned())
.collect::<Vec<_>>();
let broken_cmd = matches[0].clone();
let correct_cmd = matches[1].clone();
vec![command.script.replace(&broken_cmd, &correct_cmd)]
if let Some(output) = &command.output {
let re = Regex::new(r"'conda ([^']*)'").unwrap();
let matches = re
.captures_iter(output)
.map(|cap| cap[1].to_owned())
.collect::<Vec<_>>();
let broken_cmd = matches[0].clone();
let correct_cmd = matches[1].clone();
vec![command.script.replace(&broken_cmd, &correct_cmd)]
} else {
Vec::<String>::new()
}
}

pub fn get_rule() -> Rule {
Expand Down

0 comments on commit c8008a3

Please sign in to comment.