Command-line and Emacs Calendar Client

search by id

Ryan Gibb 5b56468e b21bc78c

+15 -7
bin/search_cmd.ml
···
open Query_args
let run ?from_str ?to_str ?calendar ?count ?query_text ~summary ~description
-
~location ~format ~today ~tomorrow ~week ~month ~recurring ~non_recurring
-
?timezone ~sort ~fs calendar_dir =
+
~location ~id ~format ~today ~tomorrow ~week ~month ~recurring
+
~non_recurring ?timezone ~sort ~fs calendar_dir =
let ( let* ) = Result.bind in
let filters = ref [] in
let tz = Query_args.parse_timezone ~timezone in
···
| None -> ());
if recurring then filters := Query.recurring_only () :: !filters;
if non_recurring then filters := Query.non_recurring_only () :: !filters;
+
(match id with
+
| Some id -> filters := Query.with_id id :: !filters
+
| None -> ());
let filter = Query.and_filter !filters in
let comparator = Query_args.create_event_comparator sort in
let* results =
···
let non_recurring_arg =
let doc = "Search for non-recurring events only" in
Arg.(value & flag & info [ "non-recurring"; "R" ] ~doc)
+
+
let id_arg =
+
let doc = "Search for an event with a specific ID" in
+
Arg.(value & opt (some string) None & info [ "id"; "i" ] ~docv:"ID" ~doc)
let cmd ~fs calendar_dir =
let run query_text from_str to_str calendar count format summary description
-
location today tomorrow week month recurring non_recurring timezone sort =
+
location id today tomorrow week month recurring non_recurring timezone
+
sort =
match
run ?from_str ?to_str ?calendar ?count ?query_text ~summary ~description
-
~location ~format ~today ~tomorrow ~week ~month ~recurring
+
~location ~id ~format ~today ~tomorrow ~week ~month ~recurring
~non_recurring ?timezone ~sort ~fs calendar_dir
with
| Error (`Msg msg) ->
···
let term =
Term.(
const run $ query_text_arg $ from_arg $ to_arg $ calendar_arg $ count_arg
-
$ format_arg $ summary_arg $ description_arg $ location_arg $ today_arg
-
$ tomorrow_arg $ week_arg $ month_arg $ recurring_arg $ non_recurring_arg
-
$ timezone_arg $ sort_arg)
+
$ format_arg $ summary_arg $ description_arg $ location_arg $ id_arg
+
$ today_arg $ tomorrow_arg $ week_arg $ month_arg $ recurring_arg
+
$ non_recurring_arg $ timezone_arg $ sort_arg)
in
let doc = "Search calendar events for specific text" in
let man =
+1 -1
lib/calendar_dir.ml
···
(`Msg
(Printf.sprintf "Exception processing directory %s: %s"
(snd collection_path) (Printexc.to_string e))))
-
+
let ( let* ) = Result.bind
let get_events ~fs calendar_dir =
+2 -2
lib/calendar_dir.mli
···
fs:[> Eio.Fs.dir_ty ] Eio.Path.t ->
t ->
(Event.t list, [> `Msg of string ]) result
-
(** Get all events in all collections. This will load any
-
Collection.ts that haven't been loaded yet. *)
+
(** Get all events in all collections. This will load any Collection.ts that
+
haven't been loaded yet. *)
val add_event :
fs:[> Eio.Fs.dir_ty ] Eio.Path.t ->
+6 -6
lib/event.ml
···
| s :: _ -> Some s
| _ -> None
-
let get_ical_start event =
-
Date.ptime_of_ical (snd event.dtstart)
-
+
let get_ical_start event = Date.ptime_of_ical (snd event.dtstart)
let get_start t = get_ical_start t.event
let get_ical_end event =
···
| None -> List.rev acc
| Some recur ->
let start = get_ical_start recur in
-
let end_ = match get_ical_end recur with None -> start | Some e -> e in
+
let end_ =
+
match get_ical_end recur with None -> start | Some e -> e
+
in
(* if start >= to then we're outside our (exclusive) date range and we terminate *)
if Ptime.compare start to_ >= 0 then List.rev acc
-
(* if end > from then, *)
+
(* if end > from then, *)
else if
match from with
| Some f -> Ptime.compare end_ f > 0
···
(* we include the event *)
then collect generator (clone_with_event event recur :: acc)
(* otherwise we iterate till the event is in range *)
-
else collect generator acc
+
else collect generator acc
in
let generator =
let ical_event = to_ical_event event in
+2 -5
test/test_calendar_dir.ml
···
in
match Calendar_dir.get_events ~fs calendar_dir with
| Ok events ->
-
Alcotest.(check int)
-
"Should find two events" 32 (List.length events);
+
Alcotest.(check int) "Should find two events" 32 (List.length events);
()
| Error e ->
-
let msg =
-
match e with `Msg m -> m
-
in
+
let msg = match e with `Msg m -> m in
Alcotest.fail ("Error getting collections: " ^ msg)
let calendar_tests fs =