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),