package pplumbing

  1. Overview
  2. Docs

Source file cmdlang_cmdliner_runner.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(*********************************************************************************)
(*  pplumbing - Utility libraries to use with [pp]                               *)
(*  SPDX-FileCopyrightText: 2024-2025 Mathieu Barbin <mathieu.barbin@gmail.com>  *)
(*  SPDX-License-Identifier: MIT                                                 *)
(*********************************************************************************)

let run ?exn_handler cmd ~name ~version =
  match
    Err.protect ?exn_handler (fun () ->
      Cmdliner.Cmd.eval
        ~catch:false
        (Cmdlang_to_cmdliner.Translate.command cmd ~name ~version))
  with
  | Ok code | Error code ->
    (* We allow the function to terminate normally when [code=0]. This is
       because [bisect_ppx] instruments the out-edge of calls to [run] in
       executables. If we never return, it would create false negatives in test
       coverage. We may revisit this decision in the future if the context
       changes. *)
    if code <> 0 then exit code
;;
OCaml

Innovation. Community. Security.