refactor: move cli argument parsing to main

Command line arguments are part of the OS process and should be under
main.
This commit is contained in:
Thomas Frans
2023-05-24 00:02:43 +02:00
committed by Henrik Friedrichsen
parent ae090b6073
commit abffb3c2a9
4 changed files with 39 additions and 23 deletions

View File

@@ -169,14 +169,14 @@ lazy_static! {
}
pub struct Config {
filename: String,
filename: PathBuf,
values: RwLock<ConfigValues>,
state: RwLock<UserState>,
}
impl Config {
pub fn new(filename: &str) -> Self {
let values = load(filename).unwrap_or_else(|e| {
pub fn new(filename: PathBuf) -> Self {
let values = load(&filename.to_string_lossy()).unwrap_or_else(|e| {
eprintln!("could not load config: {e}");
process::exit(1);
});
@@ -200,7 +200,7 @@ impl Config {
}
Self {
filename: filename.to_string(),
filename,
values: RwLock::new(values),
state: RwLock::new(userstate),
}
@@ -239,7 +239,7 @@ impl Config {
}
pub fn reload(&self) {
let cfg = load(&self.filename).expect("could not reload config");
let cfg = load(&self.filename.to_string_lossy()).expect("could not reload config");
*self.values.write().expect("can't writelock config values") = cfg
}
}