Create data directory in XDG_DATA_HOME

This commit is contained in:
Nicolás A. Ortega Froysa 2022-07-08 10:26:01 +02:00
parent 9f4b8d5e7a
commit 64af383fc6

View File

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