From 167036e1447130e9c34c6ef3136867bc80c9b24e Mon Sep 17 00:00:00 2001 From: Nihil Carcosa Date: Wed, 16 Jul 2025 03:08:16 +0200 Subject: [PATCH] minor changes --- Cargo.lock | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 13 ++++++++- src/main.rs | 24 ++++++++++++++-- 3 files changed, 112 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d0a957..ba508d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,10 +89,10 @@ version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -144,6 +144,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a15f3d0fa42283a765e5fb609683ddab4ee4ff245d8db66a24d926c05e518c6" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -162,6 +168,12 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "levenshtein" version = "1.0.5" @@ -174,6 +186,18 @@ version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "memchr" version = "2.7.5" @@ -263,12 +287,62 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "rustversion" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" + +[[package]] +name = "spinners" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0ef947f358b9c238923f764c72a4a9d42f2d637c46e059dbd319d6e7cfb4f82" +dependencies = [ + "lazy_static", + "maplit", + "strum", +] + [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "rustversion", + "syn 1.0.109", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.104" @@ -282,14 +356,16 @@ dependencies = [ [[package]] name = "text-correction" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "fuzzt", "levenshtein", + "log", "num_cpus", "rayon", "regex", + "spinners", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 29ac387..ae78240 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,23 @@ [package] name = "text-correction" -version = "0.1.0" +version = "0.1.1" edition = "2021" +license-file = "LICENSE" +readme = "README.md" +description = "Small CLI tool that corrects a given input file based on a word list given as input." +authors = ["nihil carcosa "] +homepage = "https://valhrafnaz.gay" +repository = "https://git.valhrafnaz.gay/valhrafnaz/text-correction" +categories = ["command-line-utilities"] +keywords = ["text-processing"] +publish = ["gitea"] [dependencies] clap = { version = "4.5.41", features = ["derive"] } fuzzt = "0.3.1" levenshtein = "1.0.5" +log = "0.4.27" num_cpus = "1.17.0" rayon = "1.10.0" regex = "1.11.1" +spinners = "4.1.1" diff --git a/src/main.rs b/src/main.rs index e151a3f..c9dc190 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,12 @@ use clap::{Args, Parser, Subcommand}; use text_correction::utils; use std::time::SystemTime; use std::process::*; +use std::path::Path; +use spinners::{Spinner, Spinners}; +use log::{error, trace}; #[derive(Parser)] -#[command(name = "german word corrector")] +#[command(name = "word corrector")] #[command(version, about, long_about = None)] #[command(next_line_help = true)] struct Cli { @@ -34,7 +37,9 @@ struct FileArgs { #[arg(short,long)] list_path: String, #[arg(short,long)] - output: String + output: String, + #[arg(short,long)] + overwrite: bool } fn main() { @@ -46,7 +51,20 @@ fn main() { println!("{}", out); }, Commands::CorrectFile(args) => { - utils::correct_file_concurr(args.input.clone(), args.list_path.as_str(), args.output.clone()) + if args.overwrite == true { + trace!("Overwriting old file due to cli argument."); + std::fs::remove_file(args.output.clone()).unwrap(); + } else { + trace!("Checking whether destination is writable."); + let path = "./".to_owned() + args.output.as_str(); + if Path::new(path.as_str()).exists() { + error!("File already exists!"); + exit(1); + } + } + let mut sp = Spinner::new(Spinners::Dots, "Processing file...".into()); + utils::correct_file_concurr(args.input.clone(), args.list_path.as_str(), args.output.clone()); + sp.stop_with_message("".into()); }, Commands::BenchFile(args) => { let start_par = SystemTime::now();