mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 06:20:09 +01:00
chore: lib docs
This commit is contained in:
parent
2056c679f4
commit
3d80ecf9b8
1 changed files with 11 additions and 5 deletions
|
|
@ -37,6 +37,8 @@ pub fn cmd_regex(regex: &str, command: &str) -> String {
|
||||||
cmd.join(" ")
|
cmd.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the output of a shell command as a vector of strings
|
||||||
|
/// Each string is a line of output
|
||||||
pub fn eval_shell_command(shell: &str, command: &str) -> Vec<String> {
|
pub fn eval_shell_command(shell: &str, command: &str) -> Vec<String> {
|
||||||
let output = std::process::Command::new(shell)
|
let output = std::process::Command::new(shell)
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
|
|
@ -51,6 +53,7 @@ pub fn eval_shell_command(shell: &str, command: &str) -> Vec<String> {
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Split the full command into command and arguments
|
||||||
pub fn split_command(command: &str) -> Vec<String> {
|
pub fn split_command(command: &str) -> Vec<String> {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
eprintln!("command: {command}");
|
eprintln!("command: {command}");
|
||||||
|
|
@ -114,11 +117,12 @@ pub fn best_matches_path(typo: &str, executables: &[String]) -> Option<Vec<Strin
|
||||||
find_similars(typo, executables, Some(3))
|
find_similars(typo, executables, Some(3))
|
||||||
}
|
}
|
||||||
|
|
||||||
// higher the threshold, the stricter the comparison
|
/// Find the best match for a typo given a list of candidates
|
||||||
// 1: anything
|
/// higher the threshold, stricter the comparison
|
||||||
// 2: 50%
|
/// 1: anything
|
||||||
// 3: 33%
|
/// 2: 50%
|
||||||
// ... etc
|
/// 3: 33%
|
||||||
|
/// ... etc
|
||||||
pub fn find_similar(typo: &str, candidates: &[String], threshold: Option<usize>) -> Option<String> {
|
pub fn find_similar(typo: &str, candidates: &[String], threshold: Option<usize>) -> Option<String> {
|
||||||
let threshold = threshold.unwrap_or(2);
|
let threshold = threshold.unwrap_or(2);
|
||||||
let mut min_distance = typo.chars().count() / threshold + 1;
|
let mut min_distance = typo.chars().count() / threshold + 1;
|
||||||
|
|
@ -139,6 +143,8 @@ pub fn find_similar(typo: &str, candidates: &[String], threshold: Option<usize>)
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Similar to `find_similar`, but returns a vector of all candidates
|
||||||
|
/// with the same minimum distance
|
||||||
pub fn find_similars(
|
pub fn find_similars(
|
||||||
typo: &str,
|
typo: &str,
|
||||||
candidates: &[String],
|
candidates: &[String],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue