From dc3fbcc7465b927fd48868e2e1a5c76ac245e26d Mon Sep 17 00:00:00 2001 From: "Guillaume \"Liam\" Petiot" Date: Tue, 2 Apr 2024 13:49:21 +0100 Subject: [PATCH] Properly display invalid arguments error message instead of uncaught exception (#33) --- bin/main.ml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/main.ml b/bin/main.ml index a566c61..87288da 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -58,13 +58,13 @@ let last_week = Arg.(value & flag doc) let period = - let f from to_ last_week : Period.t = - if last_week then `Last_week + let f from to_ last_week = + if last_week then Ok `Last_week else match (from, to_) with - | None, None -> `Since_last_fetch - | Some x, Some y -> `Range (x, y) - | _ -> Fmt.invalid_arg "--to and --from should be provided together" + | None, None -> Ok `Since_last_fetch + | Some x, Some y -> Ok (`Range (x, y)) + | _ -> Fmt.error_msg "--to and --from should be provided together" in Term.(const f $ from $ to_ $ last_week) @@ -112,6 +112,6 @@ let run period user : unit = in show ~period ~user @@ Yojson.Safe.from_file "activity.json" -let term = Term.(const run $ period $ user) +let term = Term.(const run $ term_result period $ user) let cmd = Cmd.v info term let () = Stdlib.exit @@ Cmd.eval cmd