Check before unwrapping in stats (#717)

Should fix the error @pdecat found!
This commit is contained in:
Ellie Huxtable 2023-02-14 09:45:55 +00:00 committed by GitHub
parent 5cb43772dc
commit 1f7d3a34e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,9 +26,13 @@ pub struct Cmd {
fn compute_stats(history: &[History], count: usize) -> Result<()> {
let mut commands = HashMap::<&str, usize>::new();
for i in history {
*commands
.entry(i.command.split_ascii_whitespace().next().unwrap())
.or_default() += 1;
let command = i.command.split_ascii_whitespace().next();
if command.is_none() {
continue;
}
*commands.entry(command.unwrap()).or_default() += 1;
}
let unique = commands.len();
let mut top = commands.into_iter().collect::<Vec<_>>();