diff --git a/src/config.rs b/src/config.rs index 23696f4..6cf87f9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -98,13 +98,14 @@ lazy_static! { } pub struct Config { + filename: String, values: RwLock, state: RwLock, } impl Config { - pub fn new() -> Self { - let values = load().unwrap_or_else(|e| { + pub fn new(filename: &str) -> Self { + let values = load(filename).unwrap_or_else(|e| { eprintln!("could not load config: {}", e); process::exit(1); }); @@ -124,6 +125,7 @@ impl Config { } Self { + filename: filename.to_string(), values: RwLock::new(values), state: RwLock::new(userstate), } @@ -159,13 +161,13 @@ impl Config { } pub fn reload(&self) { - let cfg = load().expect("could not reload config"); + let cfg = load(&self.filename).expect("could not reload config"); *self.values.write().expect("can't writelock config values") = cfg } } -fn load() -> Result { - let path = config_path("config.toml"); +fn load(filename: &str) -> Result { + let path = config_path(filename); TOML.load_or_generate_default(path, || Ok(ConfigValues::default()), false) } diff --git a/src/main.rs b/src/main.rs index 1331c12..9689113 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,6 +122,15 @@ async fn main() { .help("custom basepath to config/cache files") .takes_value(true), ) + .arg( + Arg::with_name("config") + .short("c") + .long("config") + .value_name("FILE") + .help("Filename of config file in basepath") + .takes_value(true) + .default_value("config.toml"), + ) .get_matches(); if let Some(filename) = matches.value_of("debug") { @@ -138,7 +147,9 @@ async fn main() { // Things here may cause the process to abort; we must do them before creating curses windows // otherwise the error message will not be seen by a user - let cfg: Arc = Arc::new(Config::new()); + let cfg: Arc = Arc::new(Config::new( + matches.value_of("config").unwrap_or("config.toml"), + )); let cache = Cache::new( Some(config::cache_path("librespot")),