package climate

  1. Overview
  2. Docs

Source file command_doc_spec.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
open! Import

module Value = struct
  type t =
    { name : string
        (* The value name to be used in documentation, such as
           the "MESSAGE" in "--commit MESSAGE" *)
    ; required : bool
    }

  let pp ~format_name ppf t =
    if t.required
    then Format.fprintf ppf "<%s>" (format_name t.name)
    else Format.fprintf ppf "[%s]" (format_name t.name)
  ;;
end

module Positional_arg = struct
  type t =
    { value : Value.t
    ; doc : string option
    }
end

module Positional_args = struct
  type t =
    { fixed : Positional_arg.t list
    ; repeated : Positional_arg.t option
    }

  let pp_usage_args ~format_name ppf t =
    List.iter t.fixed ~f:(fun { Positional_arg.value; _ } ->
      Format.pp_print_string ppf " ";
      Value.pp ~format_name ppf value);
    Option.iter t.repeated ~f:(fun { Positional_arg.value; _ } ->
      Format.pp_print_string ppf " ";
      Value.pp ~format_name ppf value;
      Format.pp_print_string ppf "…")
  ;;
end

module Named_arg = struct
  type t =
    { names : Name.t Nonempty_list.t
    ; value : Value.t option
    ; repeated : bool
    ; default_string : string option
    ; doc : string option
    }
end

module Named_args = struct
  type t = Named_arg.t list
end

module Args = struct
  type t =
    { named : Named_args.t
    ; positional : Positional_args.t
    }

  let pp_usage_args ~format_positional_args ppf t =
    if not (List.is_empty t.named)
    then Format.fprintf ppf " [%s]…" (format_positional_args "OPTION");
    Positional_args.pp_usage_args ~format_name:format_positional_args ppf t.positional
  ;;
end

module Subcommand = struct
  type t =
    { name : Name.t
    ; aliases : Name.t list
    ; doc : string option
    ; args : Args.t
    }
end

module Subcommands = struct
  type t = Subcommand.t list
end

type t =
  { program_name : string
  ; subcommand : string list
  ; doc : string option
  ; args : Args.t
  ; subcommands : Subcommands.t
  }
OCaml

Innovation. Community. Security.