src/section_config.rs: implement generic lookup

This commit is contained in:
Dietmar Maurer
2020-01-09 17:35:44 +01:00
parent 0eb0e02451
commit a81af92f9d
3 changed files with 23 additions and 22 deletions

View File

@ -80,27 +80,6 @@ pub fn config() -> Result<SectionConfigData, Error> {
CONFIG.parse(REMOTES_CFG_FILENAME, &content)
}
pub fn lookup(remote: &str) -> Result<Remote, Error> {
let remotes = config()?;
let config = match remotes.sections.get(remote) {
Some((type_name, config)) => {
if type_name != "remote" {
bail!("got unexpected type '{}' for remote '{}'", type_name, remote);
}
config
}
None => {
bail!("no such remote '{}'", remote);
}
};
let remote: Remote = serde_json::from_value(config.clone())?;
Ok(remote)
}
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
let raw = CONFIG.write(REMOTES_CFG_FILENAME, &config)?;