From 77c16643012d3c869e185ff6c7c07a6dd1bd31bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radli=C5=84ski=20Ignacy?= Date: Thu, 19 Oct 2023 09:53:43 +0200 Subject: [PATCH] create results file if it doesn't exist (#32) * create results file if not present * update deps --- Cargo.lock | 34 +++++++++++++++++----------------- Cargo.toml | 8 ++++---- README.md | 2 +- src/test_results.rs | 21 ++++++++++++++++++--- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c9786c..c88de21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,9 +28,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.5.0" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ "anstyle", "anstyle-parse", @@ -66,9 +66,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "2.1.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", "windows-sys", @@ -89,7 +89,7 @@ dependencies = [ "anstyle", "bstr", "doc-comment", - "predicates 3.0.3", + "predicates 3.0.4", "predicates-core", "predicates-tree", "wait-timeout", @@ -165,9 +165,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.3" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ed82781cea27b43c9b106a979fe450a13a31aab0500595fb3fc06616de08e6" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", "clap_derive", @@ -175,9 +175,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.2" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ "anstream", "anstyle", @@ -306,7 +306,7 @@ dependencies = [ "csv", "dirs", "mockall", - "predicates 3.0.3", + "predicates 3.0.4", "rand", "ratatui", "serde", @@ -604,14 +604,14 @@ dependencies = [ [[package]] name = "predicates" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09963355b9f467184c04017ced4a2ba2d75cbcb4e7462690d388233253d4b1a9" +checksum = "6dfc28575c2e3f19cb3c73b93af36460ae898d426eba6fc15b9bd2a5220758a0" dependencies = [ "anstyle", "difflib", "float-cmp", - "itertools 0.10.5", + "itertools 0.11.0", "normalize-line-endings", "predicates-core", "regex", @@ -789,18 +789,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index e9c4f50..b4e164f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/README.md b/README.md index 1fb9ccf..4b8e76b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/test_results.rs b/src/test_results.rs index b77f361..e9164eb 100644 --- a/src/test_results.rs +++ b/src/test_results.rs @@ -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, @@ -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")?; @@ -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> { + 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 =