Something went wrong. Try again.
How a command-line program ends
Something went wrong. Try again.
785 B · 31 lines
OCaml
at main
1234567891011121314151617181920212223242526272829303132(* A command whose term answers its exit status, run through [Cli_exit.run'] with [~parse_error]. *)
open Cmdliner
let count = let doc = "Write $(docv) numbered lines." in Arg.(value & opt int 0 & info [ "count" ] ~docv:"N" ~doc)
let refuse = let doc = "End with an error of the term's own." in Arg.(value & flag & info [ "refuse" ] ~doc)
let run n refuse = if refuse then `Error (false, "the term refused") else ( for i = 1 to n do Fmt.pr "line %d@." i done; `Ok 0)
let parse_error message = Fmt.pr "refused: %s@." message; 2
let () = let doc = "A listing, and what a command line that does not parse ends as." in Cli_exit.run' ~parse_error (Cmd.v (Cmd.info "parse-probe" ~doc) Term.(ret (const run $ count $ refuse)))