File: print_index.ml

package info (click to toggle)
ocaml-odoc 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,104 kB
  • sloc: ml: 59,291; javascript: 2,572; sh: 566; makefile: 31
file content (41 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download
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
open Compatcmdliner

let run inp =
  let inp = Fpath.v inp in
  let index =
    Odoc_odoc.Odoc_file.load_index inp |> function
    | Result.Ok x -> x
    | _ -> failwith "failed to load index"
  in
  let rec tree_to_yojson
      ({ node; children } : Odoc_index.Entry.t Odoc_utils.Tree.t) :
      Yojson.Safe.t =
    let entry =
      Odoc_json_index.Json_display.of_entry node [] |> Odoc_html.Json.to_string
    in
    `Assoc
      [
        ("node", `String entry);
        ("children", `List (List.map tree_to_yojson children));
      ]
  in
  List.iter
    (fun s ->
      s |> tree_to_yojson
      |> Format.printf "%a" (fun f -> Yojson.Safe.pretty_print f))
    index

let a_inp =
  let doc = "Input file." in
  Arg.(required & pos 0 (some file) None & info ~doc ~docv:"PATH" [])

let term =
  let doc =
    "Print the content of occurrences files into a text format. For tests"
  in
  Term.(const run $ a_inp, info "occurrences_print" ~doc)

let () =
  match Term.eval term with
  | `Ok () -> ()
  | (`Version | `Help | `Error _) as x -> Term.exit x