Skip to content

Commit 6fd4447

Browse files
committed
Render manpages into the documentation
The output of every 'odoc cmd --help' is wrapped into code blocks and concatenated into a page in the documentation.
1 parent 55c410b commit 6fd4447

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

doc/dune

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
(rule
2+
(action
3+
(with-stdout-to
4+
manpage.mld
5+
(pipe-stdout
6+
(run odoc)
7+
(run gen_manpage/gen_manpage.exe)))))
8+
19
(documentation
210
(package odoc)
311
(mld_files

doc/gen_manpage/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(executable
2+
(name gen_manpage)
3+
(libraries astring))

doc/gen_manpage/gen_manpage.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(** Expect the output of [odoc] on standard input. Called like that, Odoc will
2+
output the list of subcommands. *)
3+
4+
open Astring
5+
6+
let gen_preamble _cmds =
7+
Printf.printf "{0 Odoc}\n\nOdoc is made of several sub-commands."
8+
9+
let gen_subcommand cmd =
10+
Printf.printf "\n{1 odoc %s}\n\n{@man[\n%!" cmd;
11+
ignore (Sys.command (Filename.quote_command "odoc" [ cmd; "--help" ]));
12+
Printf.printf "]}\n"
13+
14+
let () =
15+
let line0 = input_line stdin in
16+
let subcommands =
17+
match String.cut ~sep:":" line0 with
18+
| Some (_, s) -> String.cuts ~sep:"," s |> List.map String.trim
19+
| None -> assert false
20+
in
21+
gen_preamble subcommands;
22+
List.iter gen_subcommand subcommands

doc/odoc.mld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ To start contributing to [odoc], please see our {{!page-contributing}contributor
5050
{1 Page index}
5151

5252
The main other pages of this site:
53+
- {!page-manpage} Man pages
5354
- {!page-odoc_for_authors} Odoc For Authors
5455
- {!page-features} Language Features
5556
- {!page-driver} Reference Driver

0 commit comments

Comments
 (0)