Expand description
fren - file renamer that understands dates.
Library crate. The CLI binary lives in fren-cli and is a thin consumer
of this library.
§Quick example
use fren_date::{slugify_camel_iso_with_year, SlugOpts};
use slug_preserve::CaseMode;
let legacy_python = SlugOpts {
separator: '_',
case: CaseMode::Capitalize,
split_camel: true,
};
let out = slugify_camel_iso_with_year("Hello World 2024-01-15.txt", &legacy_python, 2024);
assert!(out.starts_with("Hello"));§Library discipline
This crate must obey:
- No
panic!on user input - returnErr(FrenError::*) - No
println!/eprintln!- output flows through trait objects - No global state - all configuration via opts structs
Structs§
- Detected
Date - A date span detected inside a filename.
byte_spanis recorded so a future caller can locate the date and move it within the name. - Execution
Report - Summary of an executed batch.
- Jsonl
LogSink - JSONL log sink that appends to a file in
${XDG_STATE_HOME:-~/.local/state}/fren/log/. - Merge
Move - Outcome of a single file move during a merge.
- Merge
Report - Report from
merge_directories. - Null
LogSink - No-op sink for tests /
--no-log. - Null
Progress Sink - No-op
ProgressSink. Used byexecuteandexecute_with_log. - Plan
Opts - Options for planning a rename batch.
- Rename
Opts - Top-level options for
fren::rename(the high-level convenience entry). - Rename
Plan - A single planned rename operation. Produced by the planner; consumed by the executor in bottom-up order.
- Slug
Opts - Options controlling how a string is slugified.
Enums§
- Case
Mode - How to handle character case in the slugified output.
- Conflict
Policy - Conflict resolution policy when a rename target already exists or two plans target the same path.
- Date
Kind - What kind of date was detected inside a filename.
- Fren
Error - Top-level error for the
frenlibrary. - Item
Kind - What kind of filesystem item a plan refers to.
- LogRecord
- One record in the JSONL stream.
Traits§
- LogSink
- Trait for sinks that record rename events. The default implementation
is
JsonlLogSink; tests can useNullLogSink. - Progress
Sink - Callback invoked after each successful rename during execution.
Functions§
- execute
- Apply a sorted plan vector with no transaction logging.
- execute_
with_ log - Apply a sorted plan vector, recording every rename to
log_sink. - execute_
with_ progress - Apply a sorted plan vector, recording to
log_sinkand callingprogressafter each successful rename. - merge_
directories - Merge
sourcesintotarget. Files already intargetget a_Copy{N}suffix appended to their stem. Directories are created as needed..DS_Storeand similar metadata files are skipped. - plan
- Build a
RenamePlanvector for the given roots. - plan_
with_ year - Variant exposing the “current year” for deterministic testing.
- rename
- High-level entry point: plan + (optionally) execute a rename batch.
- slugify_
camel_ iso - Slugify a string with CamelCase splitting, ISO date detection, and the user’s chosen output separator/case.
- slugify_
camel_ iso_ with_ year - Variant exposing the “current year” so tests can pin time.
- slugify_
str - Slugify a single string with the given options.
- sort_
bottom_ up - Sort a plan vector in-place: deepest first; at equal depth, files before directories.
- unique_
file_ name - Find a unique file name by appending
_Copy,_Copy1,_Copy2, … to the stem until the path no longer exists.