Custom config path can now be set with MAKIMA_CONFIG env var
This commit is contained in:
parent
4bb2525cf6
commit
83f1481288
1 changed files with 22 additions and 1 deletions
23
src/main.rs
23
src/main.rs
|
@ -4,6 +4,7 @@ mod event_reader;
|
|||
mod udev_monitor;
|
||||
mod active_client;
|
||||
|
||||
use std::env;
|
||||
use tokio;
|
||||
use home;
|
||||
use config::Config;
|
||||
|
@ -13,7 +14,27 @@ use crate::udev_monitor::*;
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let config_path = std::fs::read_dir(format!("{}/.config/makima", home::home_dir().unwrap().display())).unwrap();
|
||||
let default_config_path = format!("{}/.config/makima", home::home_dir().unwrap().display());
|
||||
let env_path: String = match env::var("MAKIMA_CONFIG") {
|
||||
Ok(path) => {
|
||||
println!("\nConfig directory set to {:?}.", path);
|
||||
path
|
||||
},
|
||||
Err(_) => {
|
||||
println!("\n\"MAKIMA_CONFIG\" environment variable is not set, defaulting to {:?}.", default_config_path);
|
||||
default_config_path.clone()
|
||||
},
|
||||
};
|
||||
let config_path: std::fs::ReadDir = match std::fs::read_dir(&env_path) {
|
||||
Ok(config_path) => {
|
||||
println!("Scanning for config files...\n");
|
||||
config_path
|
||||
},
|
||||
Err(_) => {
|
||||
println!("Directory not found, falling back to {:?}.\n", default_config_path);
|
||||
std::fs::read_dir(default_config_path).unwrap()
|
||||
},
|
||||
};
|
||||
let mut config_files: Vec<Config> = Vec::new();
|
||||
for file in config_path {
|
||||
let filename: String = file.as_ref().unwrap().file_name().into_string().unwrap();
|
||||
|
|
Loading…
Add table
Reference in a new issue