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] [package]
name = "pay_respects" name = "pay_respects"
version = "0.3.1" version = "0.3.3"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View file

@ -44,7 +44,7 @@ pub fn handle_args() {
.arg("echo $nu.config-path") .arg("echo $nu.config-path")
.output() .output()
.expect("Failed to execute process"); .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() let mut file = std::fs::OpenOptions::new()
.write(true) .write(true)
.append(true) .append(true)
@ -52,8 +52,8 @@ pub fn handle_args() {
.expect("Failed to open config file"); .expect("Failed to open config file");
writeln!(file, "{}", alias).expect("Failed to write to 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); 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 let conditions = conditions
.trim_start_matches(&['#', '[']) .trim_start_matches(['#', '['])
.trim_end_matches(']') .trim_end_matches(']')
.split(',').collect::<Vec<&str>>(); .split(',')
.collect::<Vec<&str>>();
for condition in conditions { for condition in conditions {
let (mut condition, arg) = condition.split_once('(').unwrap(); let (mut condition, arg) = condition.split_once('(').unwrap();
@ -133,15 +134,15 @@ fn eval_suggest(suggest: &str, last_command: &str) -> String {
let start = { let start = {
let mut start = start.parse::<i32>().unwrap_or(0); let mut start = start.parse::<i32>().unwrap_or(0);
if start < 0 { if start < 0 {
start = split_command.len() as i32 + start; start += split_command.len() as i32;
} }
start as usize start as usize
}; };
let end = { let end = {
let mut end = end.parse::<i32>().unwrap_or(split_command.len() as i32 - 1) + 1; let mut end = end.parse::<i32>().unwrap_or(split_command.len() as i32 - 1) + 1;
if end < 0 { if end < 0 {
end = split_command.len() as i32 + end; end += split_command.len() as i32;
} }
end as usize end as usize
}; };
let command = split_command[start..end].join(" "); let command = split_command[start..end].join(" ");
@ -175,7 +176,7 @@ fn eval_suggest(suggest: &str, last_command: &str) -> String {
.collect::<Vec<&str>>(); .collect::<Vec<&str>>();
command_index = split[1].parse::<i32>().unwrap(); command_index = split[1].parse::<i32>().unwrap();
if command_index < 0 { 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 { } else {
unreachable!("Typo suggestion must have a command index"); 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> { fn get_directory_files(input: &str) -> Vec<String> {
let mut input = input let mut input = input.trim_matches(|c| c == '\'' || c == '"').to_owned();
.trim_matches(|c| c == '\'' || c == '"')
.to_owned();
let files = loop { let files = loop {
match std::fs::read_dir(&input) { match std::fs::read_dir(&input) {
Ok(files) => break files, Ok(files) => break files,

View file

@ -26,5 +26,7 @@ fn main() {
"No correction found for the command: {}\n", "No correction found for the command: {}\n",
last_command.red().bold() 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 crate::corrections::split_command;
use colored::*;
pub fn highlight_difference(corrected_command: &str, last_command: &str) -> String { pub fn highlight_difference(corrected_command: &str, last_command: &str) -> String {
let mut highlighted_command = String::new(); 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); let split_last_command = split_command(last_command);
for new in split_corrected_command { for new in split_corrected_command {
if new == "" { if new.is_empty() {
continue; continue;
} }
let mut changed = true; let mut changed = true;