Skip to content

Commit

Permalink
feat: Config detection in home .config folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mochalins committed Nov 14, 2022
1 parent d6e51fa commit 438271e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ impl Config {

// Check local working directory for config file
if config_path.is_none() {
let local_config_path = env::current_dir();
let local_config_path = env::current_exe();
if let Ok(p) = local_config_path {
let mut local_config_path = p;
local_config_path.push("gid.toml");
local_config_path.set_file_name("gid.toml");
if let Ok(true) = local_config_path.try_exists() {
config_path = Some(local_config_path);
}
Expand All @@ -70,7 +70,21 @@ impl Config {

// Check config directory for config file
if config_path.is_none() {
// TODO
let home_env = if env::consts::OS == "windows" {
"USERPROFILE"
} else {
"HOME"
};
let home_path = env::var(home_env);
if let Ok(s) = home_path {
let mut home_config_path = PathBuf::from(&s);
home_config_path.push(".config");
home_config_path.push("gid");
home_config_path.push("gid.toml");
if let Ok(true) = home_config_path.try_exists() {
config_path = Some(home_config_path);
}
}
}
config_path
}
Expand Down

0 comments on commit 438271e

Please sign in to comment.