Only use XDG_DATA_HOME.
This commit is contained in:
parent
2fbd97a622
commit
6551012a71
16
src/main.rs
16
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),
|
||||
|
Loading…
Reference in New Issue
Block a user