Config::load(...) now takes the path to the configuration file.
This commit is contained in:
parent
aa6ff176f2
commit
f8a6987fcf
2 changed files with 6 additions and 6 deletions
|
@ -14,7 +14,7 @@ pub struct IrcBot<'a, T, U> where T: IrcWriter, U: IrcReader {
|
|||
|
||||
impl<'a> IrcBot<'a, BufferedWriter<TcpStream>, BufferedReader<TcpStream>> {
|
||||
pub fn new(process: |&IrcBot<BufferedWriter<TcpStream>, BufferedReader<TcpStream>>, &str, &str, &[&str]|:'a -> IoResult<()>) -> IoResult<IrcBot<'a, BufferedWriter<TcpStream>, BufferedReader<TcpStream>>> {
|
||||
let config = try!(Config::load());
|
||||
let config = try!(Config::load("config.json"));
|
||||
let conn = try!(Connection::connect(config.server[], config.port));
|
||||
Ok(IrcBot {
|
||||
conn: conn,
|
||||
|
@ -123,7 +123,7 @@ impl<'a, T, U> IrcBot<'a, T, U> where T: IrcWriter, U: IrcReader {
|
|||
pub fn from_connection(conn: Connection<T, U>, process: |&IrcBot<T, U>, &str, &str, &[&str]|:'a -> IoResult<()>) -> IoResult<IrcBot<'a, T, U>> {
|
||||
Ok(IrcBot {
|
||||
conn: conn,
|
||||
config: try!(Config::load()),
|
||||
config: try!(Config::load("config.json")),
|
||||
process: RefCell::new(process),
|
||||
chanlists: RefCell::new(HashMap::new()),
|
||||
})
|
||||
|
|
|
@ -86,8 +86,8 @@ pub struct Config {
|
|||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> IoResult<Config> {
|
||||
let mut file = try!(File::open(&Path::new("config.json")));
|
||||
pub fn load(path: &str) -> IoResult<Config> {
|
||||
let mut file = try!(File::open(&Path::new(path)));
|
||||
let data = try!(file.read_to_string());
|
||||
decode(data[]).map_err(|e| IoError {
|
||||
kind: InvalidInput,
|
||||
|
@ -119,12 +119,12 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn load_config() {
|
||||
assert!(Config::load().is_ok());
|
||||
assert!(Config::load("config.json").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_owner() {
|
||||
let cfg = Config::load().unwrap();
|
||||
let cfg = Config::load("config.json").unwrap();
|
||||
assert!(cfg.is_owner("test"));
|
||||
assert!(!cfg.is_owner("test2"));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue