Skip to content

Commit

Permalink
Look for config file specified on command line.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonTeixidor committed Feb 18, 2017
1 parent a57fe4b commit 3e5fce8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::error::Error;
use std::path::PathBuf;
use std::path::{PathBuf, Path};
use std::convert::From;
use std::fs::metadata;
use std::mem::swap;
Expand Down Expand Up @@ -42,7 +42,7 @@ impl Default for SpotifydConfig {
}
}

fn get_config_file() -> Result<PathBuf, Box<Error>> {
pub fn get_config_file() -> Result<PathBuf, Box<Error>> {
let etc_conf = format!("/etc/{}", CONFIG_FILE);
let xdg_dirs = try!(xdg::BaseDirectories::with_prefix("spotifyd"));
xdg_dirs.find_config_file(CONFIG_FILE)
Expand All @@ -64,12 +64,12 @@ fn update<T>(r: &mut T, val: Option<T>) {
}
}

pub fn get_config() -> SpotifydConfig {
pub fn get_config<P: AsRef<Path>>(config_path: Option<P>) -> SpotifydConfig {
let mut config = SpotifydConfig::default();

let config_path = match get_config_file() {
Ok(c) => c,
Err(_) => {
let config_path = match config_path {
Some(c) => c,
None => {
info!("Couldn't find config file, continuing with default configuration.");
return config;
}
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::convert::From;
use std::error::Error;
use std::path::PathBuf;

use librespot::spirc::SpircManager;
use librespot::session::Session;
Expand Down Expand Up @@ -94,7 +95,10 @@ fn main() {
});
}));

let config = config::get_config();
let config_file = matches.opt_str("config")
.map(|s| PathBuf::from(s))
.or_else(|| config::get_config_file().ok());
let config = config::get_config(config_file);

let cache = config.cache;
let backend = config.backend;
Expand Down

0 comments on commit 3e5fce8

Please sign in to comment.