From 6551012a71cf0cf0eecefecb2153a50d5f08f873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Fri, 8 Jul 2022 18:27:32 +0200 Subject: [PATCH] Only use XDG_DATA_HOME. --- src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index ddd1f5a..a121ee9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,25 +71,27 @@ enum Command fn main() { let opts = Opts::from_args(); - let mut hmgr = HabitMgr::new(); - let data_dir:PathBuf = match env::var("XDG_DATA_HOME") { - Ok(s) => PathBuf::from(s).join("htracker"), - Err(_e) => PathBuf::from("./"), - }; + let data_dir = + PathBuf::from( + env::var("XDG_DATA_HOME") + .unwrap_or_else(|err| { panic!("Error: {}", err) })) + .join("htracker"); 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()); } 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) .unwrap_or_else(|err| { panic!("Filesystem error: {}", err) }); } + let mut hmgr = HabitMgr::new(); + match opts.cmd { None => hmgr.list(false, false),