diff options
author | Till Höppner | 2016-02-03 04:09:24 +0100 |
---|---|---|
committer | Till Höppner | 2016-02-03 04:09:24 +0100 |
commit | 89eaef2ae296744b511ede852cb497af0abcc7b7 (patch) | |
tree | ffb67c416d00d66d30996eb3b514090166b223ab /src | |
parent | 8c1430424468e799435f5e1c877f72d0565ff38c (diff) | |
download | ilc-89eaef2ae296744b511ede852cb497af0abcc7b7.tar.gz ilc-89eaef2ae296744b511ede852cb497af0abcc7b7.tar.xz ilc-89eaef2ae296744b511ede852cb497af0abcc7b7.zip |
Add count argument to freq
Diffstat (limited to 'src')
-rw-r--r-- | src/app/freq.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 6 |
2 files changed, 9 insertions, 4 deletions
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); } } diff --git a/src/main.rs b/src/main.rs index 6c87367..11f007f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,7 +83,11 @@ fn main() { .subcommand(SubCommand::with_name("convert") .about("Convert from a source to a target format")) .subcommand(SubCommand::with_name("freq") - .about("Analyse the activity of users by certain metrics")) + .about("Analyse the activity of users by certain metrics") + .arg(Arg::with_name("count") + .help("The number of items to be displayed") + .takes_value(true) + .long("count"))) .subcommand(SubCommand::with_name("seen") .about("Print the last line a nick was active") .arg(Arg::with_name("nick") |