Skip to content

Commit

Permalink
create results file if it doesn't exist (#32)
Browse files Browse the repository at this point in the history
* create results file if not present

* update deps
  • Loading branch information
radlinskii authored Oct 19, 2023
1 parent af29592 commit 77c1664
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ edition = "2021"

[dependencies]
anyhow = "1.0.75"
clap = { version = "4.4.3", features = ["derive"] }
clap = { version = "4.4.6", features = ["derive"] }
crossterm = "0.27.0"
dirs = "5.0.1"
mockall = "0.11.4"
predicates = "3.0.3"
predicates = "3.0.4"
rand = "0.8.5"
serde = { version = "1.0.188", features = ["derive"] }
serde = { version = "1.0.189", features = ["derive"] }
serde_json = "1.0.107"
tempfile = "3.8.0"
ratatui = "0.23"
ratatui = "0.23.0"
csv = "1.3.0"
chrono = { version = "0.4.31", features = ["serde"]}
[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

a _very_ minimalistic _cli_ typing test.

![gif demonstraiting how the program works](https://github.com/radlinskii/donkeytype/assets/26116041/4c2a1b6d-e70e-4631-8438-9259cc780a36)
![gif demonstrating how the program works](https://github.com/radlinskii/donkeytype/assets/26116041/4c2a1b6d-e70e-4631-8438-9259cc780a36)

## How it works

Expand Down
21 changes: 18 additions & 3 deletions src/test_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ use ratatui::{
};
use serde::{Deserialize, Serialize};

use std::{fs::create_dir_all, path::PathBuf, thread::sleep, time::Duration};
use std::{
fs::{create_dir_all, File},
path::PathBuf,
thread::sleep,
time::Duration,
};

use crate::{
config::Config,
Expand Down Expand Up @@ -120,8 +125,6 @@ impl TestResults {

/// saves test statistics and configuration to a file in users home directory
pub fn save_to_file(&self) -> Result<(), anyhow::Error> {
create_results_dir_if_not_exist()
.context("Unable to ensure that results directory exist")?;
let results_file_path =
get_results_file_path().context("Unable to ge results file path")?;

Expand Down Expand Up @@ -429,7 +432,19 @@ fn create_results_dir_if_not_exist() -> Result<()> {
Ok(())
}

fn create_results_file_if_not_exist() -> Result<()> {
let results_file_path = get_results_file_path().context("Unable to get results file path")?;

if !results_file_path.exists() {
File::create(results_file_path.clone()).context("Unable to create results file")?;
}

Ok(())
}

pub fn read_previous_results() -> Result<Vec<TestResults>> {
create_results_dir_if_not_exist().context("Unable to ensure that results directory exist")?;
create_results_file_if_not_exist().context("Unable to ensure that results file exist")?;
let results_file_path = get_results_file_path().context("Unable to get results file path")?;

let mut reader =
Expand Down

0 comments on commit 77c1664

Please sign in to comment.