Skip to content

Commit

Permalink
Properly display invalid arguments error message instead of uncaught …
Browse files Browse the repository at this point in the history
…exception
  • Loading branch information
gpetiot committed Apr 2, 2024
1 parent d378a81 commit 43abbce
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

0 comments on commit 43abbce

Please sign in to comment.