diff options
| author | Mica White <botahamec@outlook.com> | 2026-03-30 21:28:48 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2026-03-30 21:28:48 -0400 |
| commit | 96f63ec38fcdc8194a52c2b34b32f6e88ae64c34 (patch) | |
| tree | db669dec8823dd18099af3a28020e235ef238e4a /src/config.rs | |
| parent | b464fb60ac8295ef3678f59898c89e0a912457d2 (diff) | |
Refactor magic strings
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..9ede643 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,42 @@ +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<PathBuf>, + passwords: HashMap<String, (Option<String>, String)>, + passphrases: HashMap<PathBuf, String>, +} + +impl Config { + pub fn load() -> Result<Config, ConfyError> { + confy::load("git-autosave", "git-autosaved") + } + + pub fn save(&self) -> Result<(), ConfyError> { + confy::store("git-autosave", "git-autosaved", self) + } + + pub fn repositories(&self) -> &HashSet<PathBuf> { + &self.repositories + } + + pub fn repositories_mut(&mut self) -> &mut HashSet<PathBuf> { + &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) + } +} |
