Only use XDG_DATA_HOME.

This commit is contained in:
Nicolás A. Ortega Froysa 2022-07-08 18:27:32 +02:00
parent 2fbd97a622
commit 6551012a71

View File

@ -71,25 +71,27 @@ enum Command
fn main() fn main()
{ {
let opts = Opts::from_args(); let opts = Opts::from_args();
let mut hmgr = HabitMgr::new();
let data_dir:PathBuf = match env::var("XDG_DATA_HOME") { let data_dir =
Ok(s) => PathBuf::from(s).join("htracker"), PathBuf::from(
Err(_e) => PathBuf::from("./"), env::var("XDG_DATA_HOME")
}; .unwrap_or_else(|err| { panic!("Error: {}", err) }))
.join("htracker");
if data_dir.exists() && data_dir.is_file() if data_dir.exists() && data_dir.is_file()
{ {
panic!("Error: {} file already exists! Please (re)move it.", panic!("Error: file exists at '{}', please (re)move it.",
data_dir.display()); data_dir.display());
} }
else if !data_dir.exists() else if !data_dir.exists()
{ {
println!("Creating {} data directory.", data_dir.display()); println!("First run: files will be stored in {}", data_dir.display());
fs::create_dir_all(data_dir) fs::create_dir_all(data_dir)
.unwrap_or_else(|err| { panic!("Filesystem error: {}", err) }); .unwrap_or_else(|err| { panic!("Filesystem error: {}", err) });
} }
let mut hmgr = HabitMgr::new();
match opts.cmd match opts.cmd
{ {
None => hmgr.list(false, false), None => hmgr.list(false, false),