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>> {
|
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>>> {
|
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));
|
let conn = try!(Connection::connect(config.server[], config.port));
|
||||||
Ok(IrcBot {
|
Ok(IrcBot {
|
||||||
conn: conn,
|
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>> {
|
pub fn from_connection(conn: Connection<T, U>, process: |&IrcBot<T, U>, &str, &str, &[&str]|:'a -> IoResult<()>) -> IoResult<IrcBot<'a, T, U>> {
|
||||||
Ok(IrcBot {
|
Ok(IrcBot {
|
||||||
conn: conn,
|
conn: conn,
|
||||||
config: try!(Config::load()),
|
config: try!(Config::load("config.json")),
|
||||||
process: RefCell::new(process),
|
process: RefCell::new(process),
|
||||||
chanlists: RefCell::new(HashMap::new()),
|
chanlists: RefCell::new(HashMap::new()),
|
||||||
})
|
})
|
||||||
|
|
|
@ -86,8 +86,8 @@ pub struct Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load() -> IoResult<Config> {
|
pub fn load(path: &str) -> IoResult<Config> {
|
||||||
let mut file = try!(File::open(&Path::new("config.json")));
|
let mut file = try!(File::open(&Path::new(path)));
|
||||||
let data = try!(file.read_to_string());
|
let data = try!(file.read_to_string());
|
||||||
decode(data[]).map_err(|e| IoError {
|
decode(data[]).map_err(|e| IoError {
|
||||||
kind: InvalidInput,
|
kind: InvalidInput,
|
||||||
|
@ -119,12 +119,12 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn load_config() {
|
fn load_config() {
|
||||||
assert!(Config::load().is_ok());
|
assert!(Config::load("config.json").is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_owner() {
|
fn is_owner() {
|
||||||
let cfg = Config::load().unwrap();
|
let cfg = Config::load("config.json").unwrap();
|
||||||
assert!(cfg.is_owner("test"));
|
assert!(cfg.is_owner("test"));
|
||||||
assert!(!cfg.is_owner("test2"));
|
assert!(!cfg.is_owner("test2"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue