diff options
author | Philippe Normand <philn@igalia.com> | 2024-01-24 19:37:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-24 19:37:05 +0000 |
commit | 079a078fdbfca0743dc22f9e83c86702b9f9b996 (patch) | |
tree | 1e12c63a4e5ce7089ad7fad962ece62819aaa2c5 | |
parent | bdc533d2bc615df614e24fb4055bf68349e6cf88 (diff) |
stats: Misc improvements (#1613)
* fix(stats): Don't bail/error if no command is found
An empty history shouldn't be source of error when printing stats.
* fix(stats): Improve help message a bit.
It wasn't clear what the period format could be.
-rw-r--r-- | atuin/src/command/client/stats.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/atuin/src/command/client/stats.rs b/atuin/src/command/client/stats.rs index 969ab1ae..e8fff45f 100644 --- a/atuin/src/command/client/stats.rs +++ b/atuin/src/command/client/stats.rs @@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet}; use atuin_common::utils::Escapable as _; use clap::Parser; use crossterm::style::{Color, ResetColor, SetAttribute, SetForegroundColor}; -use eyre::{bail, Result}; +use eyre::Result; use interim::parse_date_string; use atuin_client::{ @@ -16,7 +16,7 @@ use time::{Duration, OffsetDateTime, Time}; #[derive(Parser, Debug)] #[command(infer_subcommands = true)] pub struct Cmd { - /// compute statistics for the specified period, leave blank for statistics since the beginning + /// Compute statistics for the specified period, leave blank for statistics since the beginning. See https://docs.atuin.sh/reference/stats/ for more details. period: Vec<String>, /// How many top commands to list @@ -24,7 +24,7 @@ pub struct Cmd { count: usize, } -fn compute_stats(settings: &Settings, history: &[History], count: usize) -> Result<()> { +fn compute_stats(settings: &Settings, history: &[History], count: usize) { let mut commands = HashSet::<&str>::with_capacity(history.len()); let mut prefixes = HashMap::<&str, usize>::with_capacity(history.len()); for i in history { @@ -41,7 +41,8 @@ fn compute_stats(settings: &Settings, history: &[History], count: usize) -> Resu top.sort_unstable_by_key(|x| std::cmp::Reverse(x.1)); top.truncate(count); if top.is_empty() { - bail!("No commands found"); + println!("No commands found"); + return; } let max = top.iter().map(|x| x.1).max().unwrap(); @@ -74,8 +75,6 @@ fn compute_stats(settings: &Settings, history: &[History], count: usize) -> Resu } println!("Total commands: {}", history.len()); println!("Unique commands: {unique}"); - - Ok(()) } impl Cmd { @@ -114,7 +113,7 @@ impl Cmd { let end = start + Duration::days(1); db.range(start, end).await? }; - compute_stats(settings, &history, self.count)?; + compute_stats(settings, &history, self.count); Ok(()) } } |