diff --git a/Cargo.toml b/Cargo.toml index 9b38217..0142cbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "4.5.4", features = ["derive", "string"] } +clap = { version = "4.5.4", features = ["derive"] } dashmap = { version = "5.5.3", features = ["serde"] } futures = "0.3.30" indicatif = "0.17.8" diff --git a/src/main.rs b/src/main.rs index d1178cc..b5a36d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::cell::RefCell; use std::collections::{BTreeMap, HashMap, VecDeque}; use std::env::current_dir; use std::fmt::Write; +use std::fs::read_to_string; use std::io; use std::path::PathBuf; use std::rc::{Rc, Weak}; @@ -21,13 +22,11 @@ use tracing::Instrument; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Args { - #[arg(short, long, default_value = - current_dir().unwrap().into_os_string())] + #[arg(short, long, default_value_os_t = current_dir().unwrap())] directory: PathBuf, - #[arg(short, long, default_value = "16")] + #[arg(short, long, default_value_t = 16)] jobs: usize, - #[arg(short = 'f', long, default_value = - current_dir().unwrap().join("keywords.txt").into_os_string())] + #[arg(short = 'f', long, default_value_os_t = current_dir().unwrap().join("keywords.txt"))] keywords_file: PathBuf, #[arg(last = true)] keywords: Vec, @@ -35,10 +34,9 @@ struct Args { static ARGS: Lazy = Lazy::new(|| { let mut args = Args::parse(); - if args.keywords_file.exists() { - let content = - std::fs::read_to_string(&args.keywords_file).expect("failed to read keywords file"); - args.keywords.extend(content.lines().map(|s| s.to_string())); + if args.keywords.is_empty() && args.keywords_file.exists() { + let content = read_to_string(&args.keywords_file).expect("failed to read keywords file"); + args.keywords = content.split_whitespace().map(|s| s.to_string()).collect(); } args });