feat: add source file tracking to rem type
Add a `source` field to `Remind.rem` to track the originating iCalendar filename (basename without extension). Thread the basename through `remind_of_event` so each reminder records which file it came from.
This commit is contained in:
@@ -326,7 +326,7 @@ let all_collectors : collector list =
|
||||
simple_recurrence;
|
||||
]
|
||||
|
||||
let remind_of_event (ev : Icalendar.event list) : (Remind.rem, error) result =
|
||||
let remind_of_event (source : string) (ev : Icalendar.event list) : (Remind.rem, error) result =
|
||||
let () = if List.length ev = 0 then failwith "No events provided" in
|
||||
|
||||
let master, recurrence =
|
||||
@@ -339,7 +339,7 @@ let remind_of_event (ev : Icalendar.event list) : (Remind.rem, error) result =
|
||||
end
|
||||
in
|
||||
|
||||
let rem = { Remind.empty with Remind.recurring = recurrence } in
|
||||
let rem = { Remind.empty with Remind.source; Remind.recurring = recurrence } in
|
||||
|
||||
ListLabels.fold_left ~init:(Ok rem) all_collectors ~f:(fun rem_or_error pred ->
|
||||
match rem_or_error with
|
||||
|
||||
@@ -20,6 +20,7 @@ let ical2rem ical_files =
|
||||
try
|
||||
Printf.eprintf "\nProcessing file: %s\n" filename;
|
||||
let file_content = read_file filename in
|
||||
let basename = Filename.remove_extension (Filename.basename filename) in
|
||||
match Icalendar.parse file_content with
|
||||
| Error e ->
|
||||
if e <> ": not enough input" then prerr_endline ("Error parsing iCalendar file: " ^ e);
|
||||
@@ -39,7 +40,7 @@ let ical2rem ical_files =
|
||||
|
||||
let good_rems =
|
||||
Map.fold ~init:[] events_map ~f:(fun ~key:uid ~data:events good_rems ->
|
||||
let rem_or_error = EventPredicates.remind_of_event events in
|
||||
let rem_or_error = EventPredicates.remind_of_event basename events in
|
||||
match rem_or_error with
|
||||
| Ok rem -> rem :: good_rems
|
||||
| Error (EventPredicates.Invalid_date s) ->
|
||||
|
||||
@@ -11,6 +11,7 @@ type simple_weekly = {
|
||||
(** A simple weekly REM command *)
|
||||
|
||||
type rem = {
|
||||
source : string; (** Source file or identifier for the reminder *)
|
||||
original_uuid : string; (** Original UID from the iCalendar event *)
|
||||
summary : string; (** Summary or title of the reminder *)
|
||||
date : Timedesc.Date.t; (** Date specification (day, month, year) *)
|
||||
@@ -28,6 +29,7 @@ type rem = {
|
||||
|
||||
let empty =
|
||||
{
|
||||
source = "";
|
||||
original_uuid = "";
|
||||
summary = "";
|
||||
date = Timedesc.Date.Ymd.make_exn ~year:1970 ~month:1 ~day:1;
|
||||
|
||||
Reference in New Issue
Block a user