use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; use confy::ConfyError; use serde::{Deserialize, Serialize}; #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Config { repositories: HashSet, passwords: HashMap, String)>, passphrases: HashMap, } impl Config { pub fn load() -> Result { confy::load("git-autosave", "git-autosaved") } pub fn save(&self) -> Result<(), ConfyError> { confy::store("git-autosave", "git-autosaved", self) } pub fn repositories(&self) -> &HashSet { &self.repositories } pub fn repositories_mut(&mut self) -> &mut HashSet { &mut self.repositories } pub fn username_for_url(&self, url: &str) -> Option<&String> { self.passwords.get(url)?.0.as_ref() } pub fn password_for_url(&self, url: &str) -> Option<&String> { Some(&self.passwords.get(url)?.1) } pub fn passphrase_for_key(&self, key: &Path) -> Option<&String> { self.passphrases.get(key) } }