Refactor grouping

This commit is contained in:
2026-03-28 11:20:16 -07:00
parent 9967e066bb
commit 5527b61d39
40 changed files with 466 additions and 630 deletions

View File

@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt::Debug, path::PathBuf};
use crate::{objectpath::ObjectPath, pattern::GroupPattern};
use crate::objectpath::ObjectPath;
mod misc;
pub use misc::*;
@@ -15,6 +15,15 @@ fn default_true() -> bool {
true
}
pub fn default_base() -> String {
"(.*)".to_owned()
}
#[expect(clippy::unwrap_used)]
pub fn default_files() -> HashMap<Label, String> {
[(Label::new("item").unwrap(), "{base}".to_owned())].into()
}
#[test]
#[expect(clippy::expect_used)]
fn init_db_toml_valid() {
@@ -51,9 +60,17 @@ pub enum Source {
/// Must be relative.
path: PathBuf,
/// How to group files into items in this source
#[serde(default)]
pattern: GroupPattern,
/// Regex that extracts an item key from a file path.
/// - File paths are relative to `path`.
/// - The first group in this regex is the file's item key.
#[serde(default = "default_base")]
base_pattern: String,
/// Map of files included in each item.'
/// `{base}` is replaced with the string extraced by base_pattern.
/// Default is `{ item: "{base}" }`
#[serde(default = "default_files")]
files: HashMap<Label, String>,
},
}