aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorUMTS at Teleco <crt@teleco.ch>2026-03-08 22:11:52 +0100
committerUMTS at Teleco <crt@teleco.ch>2026-03-08 22:11:52 +0100
commit17c6bd803dbbecb8975b1b98532d25a807a7b3fb (patch)
treebc0e339ca514414261ce211ab0f74101e6d8aefa /src/config.rs
parentee17cec85d3d9ef2abc0d7a50c980d82b429b59d (diff)
docs and font fix
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/config.rs b/src/config.rs
index 1e2efeb..546dd16 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -36,10 +36,10 @@ pub struct FavoriteEntry {
/// last known status: "available", "registered", "error", or "unknown"
#[serde(default = "default_fav_status")]
pub status: String,
- /// when it was last checked (RFC 3339)
+ /// when it was last checked
#[serde(default)]
pub checked: String,
- /// true when status changed since last check (shows ! in TUI)
+ /// true when status changed since last check
#[serde(default)]
pub changed: bool,
}
@@ -128,7 +128,11 @@ fn default_jobs() -> u8 {
}
fn default_noretry() -> Vec<String> {
- vec!["rate_limit".to_string(), "invalid_tld".to_string(), "forbidden".to_string()]
+ vec![
+ "rate_limit".to_string(),
+ "invalid_tld".to_string(),
+ "forbidden".to_string(),
+ ]
}
fn default_backups_enabled() -> bool {
@@ -208,7 +212,11 @@ impl Config {
return Config {
settings: legacy.settings,
cache: legacy.cache,
- favorites: legacy.favorites.into_iter().map(FavoriteEntry::new).collect(),
+ favorites: legacy
+ .favorites
+ .into_iter()
+ .map(FavoriteEntry::new)
+ .collect(),
imported_filters: legacy.imported_filters,
scratchpad: legacy.scratchpad,
};
@@ -240,37 +248,35 @@ impl Config {
let body = toml::to_string_pretty(self)
.map_err(|e| format!("Failed to serialize config: {}", e))?;
- let content = format!("\
+ let content = format!(
+ "\
# hoardom config - auto saved, comments are preserved on the line theyre on
#
# [settings]
-# noretry: error types that shouldnt be retried
-# \u{201c}rate_limit\u{201d} - server said slow down, retrying immediately wont help
-# \u{201c}invalid_tld\u{201d} - TLD is genuinely broken, no point retrying
-# \u{201c}forbidden\u{201d} - server returned 403, access denied, retrying wont fix it
-# \u{201c}timeout\u{201d} - uncomment if youd rather skip slow TLDs than wait
-# \u{201c}unknown\u{201d} - uncomment to skip any unrecognized errors too
-\n{}", body);
- std::fs::write(path, content)
- .map_err(|e| format!("Failed to write config file: {}", e))?;
+# noretry: error types that shouldnt be retried has the following valid values btw:
+# \u{201c}rate_limit\u{201d}
+# \u{201c}invalid_tld\u{201d}
+# \u{201c}forbidden\u{201d}
+# \u{201c}timeout\u{201d}
+# \u{201c}unknown\u{201d}
+\n{}",
+ body
+ );
+ std::fs::write(path, content).map_err(|e| format!("Failed to write config file: {}", e))?;
Ok(())
}
- /// copy current config into backups/ folder.
- /// keeps at most `max_count` backups, tosses the oldest.
- /// only call on startup and shutdown - NOT on every save.
+ /// only call on startup and shutdown NOT on every save bruh
pub fn create_backup(config_path: &Path, max_count: u32) -> Result<(), String> {
let parent = config_path.parent().ok_or("No parent directory")?;
let backup_dir = parent.join("backups");
std::fs::create_dir_all(&backup_dir)
.map_err(|e| format!("Failed to create backup dir: {}", e))?;
- // Timestamp-based filename: config_20260308_143022.toml
let ts = chrono::Local::now().format("%Y%m%d_%H%M%S");
let backup_name = format!("config_{}.toml", ts);
let backup_path = backup_dir.join(&backup_name);
- // dont backup if same-second backup already exists
if backup_path.exists() {
return Ok(());
}
@@ -278,7 +284,6 @@ impl Config {
std::fs::copy(config_path, &backup_path)
.map_err(|e| format!("Failed to copy config to backup: {}", e))?;
- // prune old backups: sort by name (timestamp order), keep newest N
if max_count > 0 {
let mut backups: Vec<_> = std::fs::read_dir(&backup_dir)
.map_err(|e| format!("Failed to read backup dir: {}", e))?
@@ -303,6 +308,7 @@ impl Config {
}
/// replaces filter with same name if theres one already
+ /// filters ? what kinda ai slip is this ? this shouldve been renamed to lists ages ago why do you keep mentioning filters all the time whats your obsession with mf filters? JEZE!
pub fn import_filter(&mut self, filter: ImportedFilter) {
self.imported_filters.retain(|f| f.name != filter.name);
self.imported_filters.push(filter);
@@ -339,10 +345,10 @@ impl Config {
}
pub fn parse_filter_file(path: &PathBuf) -> Result<ImportedFilter, String> {
- let content = std::fs::read_to_string(path)
- .map_err(|e| format!("Could not read filter file: {}", e))?;
- let filter: ImportedFilter = toml::from_str(&content)
- .map_err(|e| format!("Could not parse filter file: {}", e))?;
+ let content =
+ std::fs::read_to_string(path).map_err(|e| format!("Could not read filter file: {}", e))?;
+ let filter: ImportedFilter =
+ toml::from_str(&content).map_err(|e| format!("Could not parse filter file: {}", e))?;
if filter.name.is_empty() {
return Err("Filter file must have a name defined".to_string());
}
@@ -425,7 +431,7 @@ pub fn resolve_paths(explicit: Option<&PathBuf>) -> HoardomPaths {
}
}
- // nothing works disable caching, use a dummy path
+ // nothing works disable caching and cry about it (it will still work just no persistant sessions)
eprintln!("Warning: could not create .hoardom directory anywhere, caching disabled");
HoardomPaths {
config_file: PathBuf::from(".hoardom/config.toml"),
@@ -434,4 +440,3 @@ pub fn resolve_paths(explicit: Option<&PathBuf>) -> HoardomPaths {
caching_enabled: false,
}
}
-