Feat: Add word counter binary.

This commit is contained in:
Ian Rettig
2025-06-11 11:25:34 -04:00
parent 28d6c8cccd
commit 0f24dd22a7
+22
View File
@@ -0,0 +1,22 @@
use clap::Parser;
use std::path::PathBuf;
/// Count the number of lines in a file
#[derive(Parser)]
#[command(arg_required_else_help = true)]
struct Cli {
/// The path to the file to read
file: PathBuf,
}
fn main() {
let args = Cli::parse();
let mut word_count = 0;
let file = args.file;
for line in std::fs::read_to_string(&file).unwrap().lines() {
word_count += line.split(' ').count();
}
println!("Words in {}: {}", file.to_str().unwrap(), word_count)
}