From 89eaef2ae296744b511ede852cb497af0abcc7b7 Mon Sep 17 00:00:00 2001 From: Till Höppner Date: Wed, 3 Feb 2016 04:09:24 +0100 Subject: Add count argument to freq --- src/app/freq.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/app') diff --git a/src/app/freq.rs b/src/app/freq.rs index 9446b50..6d80f2e 100644 --- a/src/app/freq.rs +++ b/src/app/freq.rs @@ -69,9 +69,10 @@ pub fn freq(args: &ArgMatches) { let mut stats: Vec<(String, Person)> = stats.into_iter().collect(); stats.sort_by(|&(_, ref a), &(_, ref b)| b.words.cmp(&a.words)); - for &(ref name, ref stat) in stats.iter() { + let count = value_t!(args, "count", usize).unwrap_or(stats.len()); + for &(ref name, ref stat) in stats.iter().take(count) { let _ = write!(&mut output, - "{}:\n\tTotal lines: {}\n\tLines without alphabetic characters: {}\n\tTotal words: {}\n\tWords per line: {}\n", - name, stat.lines, stat.lines - stat.alpha_lines, stat.words, stat.words as f32 / stat.lines as f32); + "{}:\n\tTotal lines: {}\n\tLines without alphabetic characters: {}\n\tTotal words: {}\n\tWords per line: {}\n", + name, stat.lines, stat.lines - stat.alpha_lines, stat.words, stat.words as f32 / stat.lines as f32); } } -- cgit v1.2.3