diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-24 03:42:43 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-24 03:42:43 +0800 |
| commit | 3e30e13e7601884a8f3ec69a7899fd3e8d207e4f (patch) | |
| tree | f44583c81867d2855f6b0cc01604043210d93c25 /src/mem_mgr.rs | |
| parent | 289aa96f02f99bb724013e473725760a86ba6190 (diff) | |
Add optional --about filter to explore and dumpall commands
Diffstat (limited to 'src/mem_mgr.rs')
| -rw-r--r-- | src/mem_mgr.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/mem_mgr.rs b/src/mem_mgr.rs index 8b9d950..c6e442e 100644 --- a/src/mem_mgr.rs +++ b/src/mem_mgr.rs @@ -50,8 +50,9 @@ pub fn handle_read(args: EntryRead, constants: &Constants) -> Next { } #[chain] -pub fn handle_dumpall(_p: EntryDumpAll, constants: &Constants) -> Next { - dumpall(constants).to_render() +pub fn handle_dumpall(args: EntryDumpAll, constants: &Constants) -> Next { + let about = args.pick::<String>("--about").unpack(); + dumpall(constants, about).to_render() } #[derive(Serialize, Groupped)] @@ -214,7 +215,7 @@ fn forget(constants: &Constants, title: String) -> ResultForgotten { } } -fn dumpall(constants: &Constants) -> ResultDumpAll { +fn dumpall(constants: &Constants, about: String) -> ResultDumpAll { let store_root = &constants.store_root; let mut entries = Vec::new(); if let Ok(dir_entries) = std::fs::read_dir(store_root) { @@ -225,6 +226,22 @@ fn dumpall(constants: &Constants) -> ResultDumpAll { if let Some(stem) = path.file_stem() { let title = stem.to_string_lossy().to_string(); let content = std::fs::read_to_string(&path).unwrap_or_default(); + // If about is provided and not empty, do fuzzy matching on lowercase alphanumeric + if !about.is_empty() { + let filter: String = about + .chars() + .filter(|c| c.is_alphanumeric()) + .collect::<String>() + .to_lowercase(); + let title_clean: String = title + .chars() + .filter(|c| c.is_alphanumeric()) + .collect::<String>() + .to_lowercase(); + if !title_clean.contains(&filter) { + continue; + } + } entries.push(DumpEntry { title, content }); } } |
