twixter

A twtxt command line client in Rust

git clone git://git.shimmy1996.com/twixter.git

config.rs (1426B)

    1 use std::collections::HashMap;
    2 use std::path::Path;
    3 
    4 #[derive(Debug)]
    5 pub struct Config {
    6     pub nick: String,
    7     pub twtfile: String,
    8     pub twturl: String,
    9     pub pre_tweet_hook: String,
   10     pub post_tweet_hook: String,
   11     pub limit_timeline: usize,
   12     pub use_abs_time: bool,
   13     pub following: HashMap<String, String>,
   14 }
   15 
   16 impl Config {
   17     pub fn new(config_path: &Path) -> Config {
   18         use ini::Ini;
   19 
   20         let config = Ini::load_from_file(config_path).unwrap();
   21         let twtxt_config = config.section(Some("twtxt".to_owned())).unwrap();
   22 
   23         let following = config
   24             .section(Some("following".to_owned()))
   25             .unwrap()
   26             .to_owned();
   27         // Parse hook commands.
   28         let pre_tweet_hook = strfmt::strfmt(&twtxt_config["pre_tweet_hook"], twtxt_config).unwrap();
   29         let post_tweet_hook =
   30             strfmt::strfmt(&twtxt_config["post_tweet_hook"], twtxt_config).unwrap();
   31 
   32         Config {
   33             nick: twtxt_config["nick"].to_owned(),
   34             twtfile: twtxt_config["twtfile"].to_owned(),
   35             twturl: twtxt_config["twturl"].to_owned(),
   36             pre_tweet_hook: pre_tweet_hook,
   37             post_tweet_hook: post_tweet_hook,
   38             limit_timeline: twtxt_config["limit_timeline"].parse::<usize>().unwrap(),
   39             use_abs_time: twtxt_config["use_abs_time"].parse::<bool>().unwrap(),
   40             following: following,
   41         }
   42     }
   43 }