2019-12-16 17:37:52 +00:00
|
|
|
open Cmdliner
|
2019-09-20 11:59:44 +02:00
|
|
|
open Main.Display
|
2019-06-28 12:05:04 +00:00
|
|
|
|
2020-06-12 13:33:14 +02:00
|
|
|
let returned_value : (_,_) result -> unit -> unit Term.ret =
|
|
|
|
fun v () -> match v with
|
|
|
|
| Ok _ -> `Ok ()
|
|
|
|
| Error _ -> `Error (false, "error")
|
2020-01-08 10:54:21 +00:00
|
|
|
|
2020-06-12 13:33:14 +02:00
|
|
|
let toplevel : display_format:ex_display_format -> displayable -> (unit -> unit Term.ret) -> unit Term.ret =
|
|
|
|
fun ~display_format disp return ->
|
|
|
|
let (Ex_display_format t) = display_format in
|
|
|
|
let as_str : string =
|
|
|
|
match t with
|
|
|
|
| Human_readable -> convert ~display_format:t disp ;
|
|
|
|
| Dev -> convert ~display_format:t disp ;
|
2020-06-24 12:11:12 +02:00
|
|
|
| Json -> Yojson.to_string @@ convert ~display_format:t disp in
|
2020-06-12 13:33:14 +02:00
|
|
|
Format.printf "%s\n" as_str ;
|
|
|
|
return ()
|
2020-01-08 10:54:21 +00:00
|
|
|
|
2020-06-12 13:33:14 +02:00
|
|
|
let return_result : display_format:ex_display_format -> 'value format -> ('value, Main_errors.Types.all) result -> unit Term.ret =
|
|
|
|
fun ~display_format value_format value ->
|
|
|
|
let format = Display.bind_format value_format Main.Formatter.error_format in
|
|
|
|
toplevel ~display_format (Display.Displayable {value ; format}) (returned_value value)
|