Command-line and Emacs Calendar Client
1open Cmdliner 2open Caledonia_lib 3open Event_args 4 5let run ~summary ~start_date ~start_time ~end_date ~end_time ~location 6 ~description ~recur ~calendar_name ?timezone ?end_timezone ~fs calendar_dir 7 = 8 let ( let* ) = Result.bind in 9 let* start = parse_start ~start_date ~start_time ~timezone in 10 let* start = 11 match start with 12 | Some s -> Ok s 13 | None -> Error (`Msg "Start date required") 14 in 15 let* end_ = 16 let end_date = 17 match end_date with None -> start_date | Some e -> Some e 18 in 19 parse_end ~end_date ~end_time ~timezone ~end_timezone 20 in 21 let* recurrence = 22 match recur with 23 | Some r -> 24 let* p = parse_recurrence r in 25 Ok (Some p) 26 | None -> Ok None 27 in 28 let calendar_name = calendar_name in 29 let event = 30 Event.create ~fs 31 ~calendar_dir_path:(Calendar_dir.get_path calendar_dir) 32 ~summary ~start ?end_ ?location ?description ?recurrence calendar_name 33 in 34 let* _ = Calendar_dir.add_event ~fs calendar_dir event in 35 Printf.printf "Event created with ID: %s\n" (Event.get_id event); 36 Ok () 37 38let cmd ~fs calendar_dir = 39 let run summary start_date start_time end_date end_time location description 40 recur calendar_name timezone end_timezone = 41 match 42 run ~summary ~start_date ~start_time ~end_date ~end_time ~location 43 ~description ~recur ~calendar_name ?timezone ?end_timezone ~fs 44 calendar_dir 45 with 46 | Error (`Msg msg) -> 47 Printf.eprintf "Error: %s\n%!" msg; 48 1 49 | Ok () -> 0 50 in 51 let term = 52 Term.( 53 const run $ required_summary_arg $ start_date_arg $ start_time_arg 54 $ end_date_arg $ end_time_arg $ location_arg $ description_arg $ recur_arg 55 $ calendar_name_arg $ timezone_arg $ end_timezone_arg) 56 in 57 let doc = "Add a new calendar event" in 58 let man = 59 [ 60 `S Manpage.s_description; 61 `P "Add a new event to your calendar."; 62 `P 63 "Specify the event summary (title) as the first argument, and use \ 64 options to set other details."; 65 `S Manpage.s_examples; 66 `I 67 ( "Add a event for today:", 68 "caled add \"Meeting\" --date today --time 14:00" ); 69 `I 70 ( "Add an event with a specific date and time:", 71 "caled add \"Dentist Appointment\" --date 2025-04-15 --time 10:30" ); 72 `I 73 ( "Add an event with an end time:", 74 "caled add \"Conference\" --date 2025-05-20 --time 09:00 --end-date \ 75 2025-05-22 --end-time 17:00" ); 76 `I 77 ( "Add an event with location and description:", 78 "caled add \"Lunch with Bob\" --date 2025-04-02 --time 12:30 \ 79 --location \"Pasta Restaurant\" --description \"Discuss project \ 80 plans\"" ); 81 `I 82 ( "Add an event to a specific calendar:", 83 "caled add \"Work Meeting\" --date 2025-04-03 --time 15:00 \ 84 --calendar work" ); 85 `S Manpage.s_options; 86 ] 87 @ date_format_manpage_entries @ recurrence_format_manpage_entries 88 @ [ `S Manpage.s_see_also ] 89 in 90 let exit_info = 91 [ Cmd.Exit.info ~doc:"on success." 0; Cmd.Exit.info ~doc:"on error." 1 ] 92 in 93 let info = Cmd.info "add" ~doc ~man ~exits:exit_info in 94 Cmd.v info term