Command-line and Emacs Calendar Client
1open Cmdliner
2open Caledonia_lib
3open Event_args
4
5let run ~event_id ~summary ~start_date ~start_time ~end_date ~end_time ~location
6 ~description ~recur ?timezone ?end_timezone ~fs calendar_dir =
7 let ( let* ) = Result.bind in
8 let filter = Query.with_id event_id in
9 let* results = Query.query_without_recurrence ~fs calendar_dir ~filter () in
10 let* event =
11 match results with
12 | [ event ] -> Ok event
13 | [] -> Error (`Msg ("No events found found for id " ^ event_id))
14 | _ -> Error (`Msg ("More than one found for id " ^ event_id))
15 in
16 let* start = parse_start ~start_date ~start_time ~timezone in
17 let* end_ =
18 let end_date =
19 match end_date with None -> start_date | Some e -> Some e
20 in
21 parse_end ~end_date ~end_time ~timezone ~end_timezone
22 in
23 let* recurrence =
24 match recur with
25 | Some r ->
26 let* p = parse_recurrence r in
27 Ok (Some p)
28 | None -> Ok None
29 in
30 let modifed_event =
31 Event.edit ?summary ?start ?end_ ?location ?description ?recurrence event
32 in
33 let* _ = Calendar_dir.edit_event ~fs calendar_dir modifed_event in
34 Printf.printf "Event %s updated.\n" event_id;
35 Ok ()
36
37let event_id_arg =
38 let doc = "ID of the event to edit" in
39 Arg.(required & pos 0 (some string) None & info [] ~docv:"EVENT_ID" ~doc)
40
41let cmd ~fs calendar_dir =
42 let run event_id summary start_date start_time end_date end_time location
43 description recur timezone end_timezone =
44 match
45 run ~event_id ~summary ~start_date ~start_time ~end_date ~end_time
46 ~location ~description ~recur ?timezone ?end_timezone ~fs calendar_dir
47 with
48 | Error (`Msg msg) ->
49 Printf.eprintf "Error: %s\n%!" msg;
50 1
51 | Ok () -> 0
52 in
53 let term =
54 Term.(
55 const run $ event_id_arg $ optional_summary_arg $ start_date_arg
56 $ start_time_arg $ end_date_arg $ end_time_arg $ location_arg
57 $ description_arg $ recur_arg $ timezone_arg $ end_timezone_arg)
58 in
59 let doc = "Edit an existing calendar event" in
60 let man =
61 [
62 `S Manpage.s_description;
63 `P "Edit an existing event in your calendar by its ID.";
64 `P
65 "Specify the event ID as the first argument, and use options to change \
66 event details.";
67 `S Manpage.s_examples;
68 `I
69 ( "Change the summary of an event:",
70 "caled edit 12345678-1234-5678-1234-567812345678 --summary \"New \
71 Title\"" );
72 `I
73 ( "Change the date and time:",
74 "caled edit 12345678-1234-5678-1234-567812345678 --date 2025-05-01 \
75 --time 15:30" );
76 `I
77 ( "Update the location:",
78 "caled edit 12345678-1234-5678-1234-567812345678 --location \
79 \"Conference Room B\"" );
80 `I
81 ( "Change the description:",
82 "caled edit 12345678-1234-5678-1234-567812345678 --description \
83 \"Updated agenda for the meeting\"" );
84 `S Manpage.s_options;
85 ]
86 @ date_format_manpage_entries @ recurrence_format_manpage_entries
87 @ [ `S Manpage.s_see_also ]
88 in
89 let exit_info =
90 [ Cmd.Exit.info ~doc:"on success." 0; Cmd.Exit.info ~doc:"on error." 1 ]
91 in
92 let info = Cmd.info "edit" ~doc ~man ~exits:exit_info in
93 Cmd.v info term