File: help.ml

package info (click to toggle)
ocaml-dune 2.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 14,064 kB
  • sloc: ml: 70,777; lisp: 466; ansic: 241; sh: 209; makefile: 119; python: 38; cpp: 17; javascript: 6
file content (127 lines) | stat: -rw-r--r-- 5,082 bytes parent folder | download | duplicates (2)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
open Stdune
open Import

let config =
  ( ("dune-config", 5, "", "Dune", "Dune manual")
  , [ `S Manpage.s_name
    ; `P {|dune-config - configuring the dune build system|}
    ; `S Manpage.s_synopsis
    ; `Pre "~/.config/dune/config"
    ; `S Manpage.s_description
    ; `P
        {|Unless $(b,--no-config) or $(b,-p) is passed, Dune will read a
           configuration file from the user home directory. This file is used
           to control various aspects of the behavior of Dune.|}
    ; `P
        {|The configuration file is normally $(b,~/.config/dune/config) on
           Unix systems and $(b,Local Settings/dune/config) in the User home
           directory on Windows. However, it is possible to specify an
           alternative configuration file with the $(b,--config-file) option.|}
    ; `P
        {|The first line of the file must be of the form (lang dune X.Y)
           where X.Y is the version of the dune language used in the file.|}
    ; `P
        {|The rest of the file must be written in S-expression syntax and be
           composed of a list of stanzas. The following sections describe
           the stanzas available.|}
    ; `S "CACHING"
    ; `P {|Syntax: $(b,\(cache ENABLED\))|}
    ; `P
        {| This stanza determines whether dune's build caching is enabled.
           See https://dune.readthedocs.io/en/stable/caching.html for details.
           Valid values for $(b, ENABLED) are $(b, enabled) or $(b, disabled).|}
    ; `S "DISPLAY MODES"
    ; `P {|Syntax: $(b,\(display MODE\))|}
    ; `P
        {|This stanza controls how Dune reports what it is doing to the user.
           This parameter can also be set from the command line via $(b,--display MODE).
           The following display modes are available:|}
    ; `Blocks
        (List.map
           ~f:(fun (x, desc) -> `I (sprintf "$(b,%s)" x, desc))
           [ ( "progress"
             , {|This is the default, Dune shows and update a
               status line as build goals are being completed.|}
             )
           ; ("quiet", {|Only display errors.|})
           ; ( "short"
             , {|Print one line per command being executed, with the
               binary name on the left and the reason it is being executed for
               on the right.|}
             )
           ; ( "verbose"
             , {|Print the full command lines of programs being
               executed by Dune, with some colors to help differentiate
               programs.|}
             )
           ])
    ; `P
        {|Note that when the selected display mode is $(b,progress) and the
           output is not a terminal then the $(b,quiet) mode is selected
           instead. This rule doesn't apply when running Dune inside Emacs.
           Dune detects whether it is executed from inside Emacs or not by
           looking at the environment variable $(b,INSIDE_EMACS) that is set by
           Emacs. If you want the same behavior with another editor, you can set
           this variable. If your editor already sets another variable,
           please open a ticket on the ocaml/dune GitHub project so that we can
           add support for it.|}
    ; `S "JOBS"
    ; `P {|Syntax: $(b,\(jobs NUMBER\))|}
    ; `P
        {|Set the maximum number of jobs Dune might run in parallel.
           This can also be set from the command line via $(b,-j NUMBER).|}
    ; `P {|The default for this value is 4.|}
    ; `S "SANDBOXING"
    ; `P {|Syntax: $(b,\(sandboxing_preference MODE ...\))|}
    ; `P
        {|Controls the sandboxing mode preference order used by dune. Dune will
use the earliest item from this list that's allowed by the action dependency
specification, or fall back on the hard-coded default. See $(b,man dune-build)
 for the description of individual modes.|}
    ; Common.footer
    ] )

type what =
  | Man of Manpage.t
  | List_topics

let commands = [ ("config", Man config); ("topics", List_topics) ]

let doc = "Additional Dune help"

let man =
  [ `S "DESCRIPTION"
  ; `P
      {|$(b,dune help TOPIC) provides additional help on the given topic.
            The following topics are available:|}
  ; `Blocks
      (List.concat_map commands ~f:(fun (s, what) ->
           match what with
           | List_topics -> []
           | Man ((title, _, _, _, _), _) -> [ `I (sprintf "$(b,%s)" s, title) ]))
  ; Common.footer
  ]

let info = Term.info "help" ~doc ~man

let term =
  Term.ret
  @@ let+ man_format = Arg.man_format
     and+ what =
       Arg.(value & pos 0 (some (enum commands)) None & info [] ~docv:"TOPIC")
     and+ () = Common.build_info in
     match what with
     | None -> `Help (man_format, Some "help")
     | Some (Man man_page) ->
       Format.printf "%a@?" (Manpage.print man_format) man_page;
       `Ok ()
     | Some List_topics ->
       List.filter_map commands ~f:(fun (s, what) ->
           match what with
           | List_topics -> None
           | _ -> Some s)
       |> List.sort ~compare:String.compare
       |> String.concat ~sep:"\n" |> print_endline;
       `Ok ()

let command = (term, info)