formatting

This commit is contained in:
iff 2023-07-31 23:48:14 +02:00
parent 7cfe075da6
commit 23b01c4775
5 changed files with 18 additions and 17 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "pay_respects"
version = "0.3.1"
version = "0.3.3"
edition = "2021"
[dependencies]

View file

@ -44,7 +44,7 @@ pub fn handle_args() {
.arg("echo $nu.config-path")
.output()
.expect("Failed to execute process");
let config_path= String::from_utf8_lossy(&output.stdout);
let config_path = String::from_utf8_lossy(&output.stdout);
let mut file = std::fs::OpenOptions::new()
.write(true)
.append(true)
@ -52,8 +52,8 @@ pub fn handle_args() {
.expect("Failed to open config file");
writeln!(file, "{}", alias).expect("Failed to write to config file");
},
"n" | _ => std::process::exit(0),
}
_ => std::process::exit(0),
};
std::process::exit(0);
}

View file

@ -73,9 +73,10 @@ fn check_condition(suggest: &str, command: &str, error_msg: &str) -> Option<Stri
}
}
let conditions = conditions
.trim_start_matches(&['#', '['])
.trim_start_matches(['#', '['])
.trim_end_matches(']')
.split(',').collect::<Vec<&str>>();
.split(',')
.collect::<Vec<&str>>();
for condition in conditions {
let (mut condition, arg) = condition.split_once('(').unwrap();
@ -133,15 +134,15 @@ fn eval_suggest(suggest: &str, last_command: &str) -> String {
let start = {
let mut start = start.parse::<i32>().unwrap_or(0);
if start < 0 {
start = split_command.len() as i32 + start;
}
start += split_command.len() as i32;
}
start as usize
};
let end = {
let mut end = end.parse::<i32>().unwrap_or(split_command.len() as i32 - 1) + 1;
if end < 0 {
end = split_command.len() as i32 + end;
}
end += split_command.len() as i32;
}
end as usize
};
let command = split_command[start..end].join(" ");
@ -175,7 +176,7 @@ fn eval_suggest(suggest: &str, last_command: &str) -> String {
.collect::<Vec<&str>>();
command_index = split[1].parse::<i32>().unwrap();
if command_index < 0 {
command_index = split_command(last_command).len() as i32 + command_index;
command_index += split_command(last_command).len() as i32;
}
} else {
unreachable!("Typo suggestion must have a command index");
@ -258,9 +259,7 @@ fn get_path_files() -> Vec<String> {
}
fn get_directory_files(input: &str) -> Vec<String> {
let mut input = input
.trim_matches(|c| c == '\'' || c == '"')
.to_owned();
let mut input = input.trim_matches(|c| c == '\'' || c == '"').to_owned();
let files = loop {
match std::fs::read_dir(&input) {
Ok(files) => break files,

View file

@ -26,5 +26,7 @@ fn main() {
"No correction found for the command: {}\n",
last_command.red().bold()
);
println!("If you think there should be a correction, please open an issue or send a pull request!");
println!(
"If you think there should be a correction, please open an issue or send a pull request!"
);
}

View file

@ -1,5 +1,5 @@
use colored::*;
use crate::corrections::split_command;
use colored::*;
pub fn highlight_difference(corrected_command: &str, last_command: &str) -> String {
let mut highlighted_command = String::new();
@ -8,7 +8,7 @@ pub fn highlight_difference(corrected_command: &str, last_command: &str) -> Stri
let split_last_command = split_command(last_command);
for new in split_corrected_command {
if new == "" {
if new.is_empty() {
continue;
}
let mut changed = true;