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