summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs42
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)
+ }
+}