2017-10-19 14:04:58 +00:00
|
|
|
use toml;
|
|
|
|
|
|
|
|
use settings::SettingsLoader;
|
2017-10-20 15:06:05 +00:00
|
|
|
use super::vim_plug;
|
2017-10-19 14:04:58 +00:00
|
|
|
|
2017-10-20 15:06:05 +00:00
|
|
|
pub struct Store {
|
|
|
|
settings: Settings,
|
|
|
|
}
|
2017-10-18 14:49:56 +00:00
|
|
|
|
|
|
|
impl Store {
|
2017-10-20 15:06:05 +00:00
|
|
|
pub fn load() -> Self {
|
|
|
|
Store { settings: Settings::load() }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn load_from_plug(vim_plug: &vim_plug::Manager) -> Self {
|
|
|
|
let settings = match vim_plug.get_plugs() {
|
|
|
|
Err(msg) => {
|
|
|
|
error!("{}", msg);
|
|
|
|
Settings::empty()
|
|
|
|
}
|
|
|
|
Ok(plugs) => {
|
|
|
|
let plugs = plugs
|
|
|
|
.iter()
|
|
|
|
.map(|vpi| PlugInfo::new(vpi.name.to_owned(), vpi.uri.to_owned()))
|
|
|
|
.collect();
|
|
|
|
Settings::new(plugs)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Store { settings }
|
2017-10-19 14:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
struct Settings {
|
|
|
|
plugs: Vec<PlugInfo>,
|
|
|
|
}
|
|
|
|
|
2017-10-20 15:06:05 +00:00
|
|
|
impl Settings {
|
|
|
|
fn new(plugs: Vec<PlugInfo>) -> Self {
|
|
|
|
Settings { plugs }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 14:04:58 +00:00
|
|
|
impl SettingsLoader for Settings {
|
|
|
|
const SETTINGS_FILE: &'static str = "plugs.toml";
|
|
|
|
|
|
|
|
fn empty() -> Self {
|
|
|
|
Settings { plugs: vec![] }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, String> {
|
|
|
|
toml::from_str(&s).map_err(|e| format!("{}", e))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct PlugInfo {
|
|
|
|
name: String,
|
|
|
|
url: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PlugInfo {
|
|
|
|
pub fn new(name: String, url: String) -> Self {
|
|
|
|
PlugInfo { name, url }
|
2017-10-18 14:49:56 +00:00
|
|
|
}
|
|
|
|
}
|