mirror of
https://github.com/xqtc161/meowlog.git
synced 2024-11-23 18:29:08 +01:00
Create files in .local on first run
This commit is contained in:
parent
2010c906b1
commit
519f3d2165
|
@ -2,7 +2,7 @@ use chrono::{NaiveDateTime, Utc};
|
|||
use color_eyre::Section;
|
||||
use inquire;
|
||||
use serde::{self, Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, process::exit};
|
||||
use strum::{EnumIter, IntoEnumIterator};
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -54,8 +54,15 @@ pub fn add_ingestion() {
|
|||
} else {
|
||||
std::fs::File::create(INGESTIONS_FILE.to_string()).unwrap();
|
||||
ingesstions_bytes_loaded_des = HashMap::new();
|
||||
let ingesstions_bytes_loaded_ser =
|
||||
bincode::serialize(&ingesstions_bytes_loaded_des).unwrap();
|
||||
std::fs::write(INGESTIONS_FILE.to_string(), ingesstions_bytes_loaded_ser).unwrap();
|
||||
}
|
||||
let substances = crate::substances::substances_to_vec();
|
||||
if substances.is_empty() {
|
||||
eprintln!("Add a substance before you log an ingestions");
|
||||
exit(1)
|
||||
}
|
||||
let substance = inquire::Select::new("What did yout ingest?", substances)
|
||||
.prompt()
|
||||
.unwrap();
|
||||
|
@ -139,3 +146,9 @@ pub fn list_ingestions() -> Result<(), std::io::Error> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn create_ingestions_file() -> Result<(), std::io::Error> {
|
||||
let hash: HashMap<Uuid, Ingestion> = HashMap::new();
|
||||
let hash_ser = bincode::serialize(&hash).unwrap();
|
||||
std::fs::write(INGESTIONS_FILE.to_string(), hash_ser)
|
||||
}
|
||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -4,7 +4,7 @@ use std::{collections::HashMap, path::Path};
|
|||
use bincode::serialize;
|
||||
use chrono::Utc;
|
||||
use clap::{Parser, Subcommand};
|
||||
use config::LOCAL_PATH;
|
||||
use config::{INGESTIONS_FILE, LOCAL_PATH, SUBSTANCES_FILE};
|
||||
use git2;
|
||||
use inquire;
|
||||
use serde::{self, Deserialize, Serialize};
|
||||
|
@ -64,6 +64,34 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if !substances::path_exists(SUBSTANCES_FILE.to_string()) {
|
||||
match substances::create_substances_file() {
|
||||
Ok(_) => {
|
||||
println!(
|
||||
"Created substances file at {:?}",
|
||||
SUBSTANCES_FILE.to_string()
|
||||
)
|
||||
}
|
||||
Err(_) => {
|
||||
eprintln!("Could not create substances file");
|
||||
panic!()
|
||||
}
|
||||
};
|
||||
}
|
||||
if !substances::path_exists(INGESTIONS_FILE.to_string()) {
|
||||
match ingestions::create_ingestions_file() {
|
||||
Ok(_) => {
|
||||
println!(
|
||||
"Created ingestions file at {:?}",
|
||||
INGESTIONS_FILE.to_string()
|
||||
)
|
||||
}
|
||||
Err(_) => {
|
||||
eprintln!("Could not create substances file");
|
||||
panic!()
|
||||
}
|
||||
};
|
||||
}
|
||||
let cli = Cli::parse();
|
||||
|
||||
match &cli.command {
|
||||
|
|
|
@ -106,3 +106,9 @@ pub fn substances_to_vec() -> Vec<String> {
|
|||
}
|
||||
sub_vec
|
||||
}
|
||||
|
||||
pub fn create_substances_file() -> Result<(), std::io::Error> {
|
||||
let hash: HashMap<Uuid, Substance> = HashMap::new();
|
||||
let hash_ser = bincode::serialize(&hash).unwrap();
|
||||
std::fs::write(SUBSTANCES_FILE.to_string(), hash_ser)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue