From 64af383fc635f5a40d3374fec5a8c874e4b57896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Fri, 8 Jul 2022 10:26:01 +0200 Subject: [PATCH] Create data directory in XDG_DATA_HOME --- src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main.rs b/src/main.rs index a2afe85..5c64559 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,10 @@ use structopt::StructOpt; use structopt::clap::AppSettings; +use std::env; +use std::path::PathBuf; +use std::fs; +//use std::result::Result; mod habit; mod habitmgr; @@ -70,6 +74,19 @@ fn main() let opts = Opts::from_args(); let mut hmgr = HabitMgr::new(); + let mut data_dir = PathBuf::from( + env::var("XDG_DATA_HOME") + .unwrap_or("./".to_string())); + // TODO: don't add this if we use ./ + data_dir.push("htracker"); + + if !data_dir.exists() + { + println!("Creating {} data directory.", data_dir.display()); + fs::create_dir_all(data_dir) + .unwrap_or_else(|err| { panic!("Filesystem error: {}", err) }); + } + match opts.cmd { None => hmgr.list(false, false),