Check before unwrapping in stats (#717)
Should fix the error @pdecat found!
This commit is contained in:
parent
5cb43772dc
commit
1f7d3a34e7
1 changed files with 7 additions and 3 deletions
|
@ -26,9 +26,13 @@ pub struct Cmd {
|
||||||
fn compute_stats(history: &[History], count: usize) -> Result<()> {
|
fn compute_stats(history: &[History], count: usize) -> Result<()> {
|
||||||
let mut commands = HashMap::<&str, usize>::new();
|
let mut commands = HashMap::<&str, usize>::new();
|
||||||
for i in history {
|
for i in history {
|
||||||
*commands
|
let command = i.command.split_ascii_whitespace().next();
|
||||||
.entry(i.command.split_ascii_whitespace().next().unwrap())
|
|
||||||
.or_default() += 1;
|
if command.is_none() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
*commands.entry(command.unwrap()).or_default() += 1;
|
||||||
}
|
}
|
||||||
let unique = commands.len();
|
let unique = commands.len();
|
||||||
let mut top = commands.into_iter().collect::<Vec<_>>();
|
let mut top = commands.into_iter().collect::<Vec<_>>();
|
||||||
|
|
Loading…
Reference in a new issue