Skip to content

Commit 25a90f3

Browse files
committed
Doc: Manpages: Group commands by sections
Sections are used to group commands by generating doc sections. The TOC looks more readable. The first section is also nicer with some separations between the list items.
1 parent 3cd32e0 commit 25a90f3

File tree

2 files changed

+78
-40
lines changed

2 files changed

+78
-40
lines changed

doc/gen_manpage/gen_manpage.ml

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let cat_command cmd args =
1616
done
1717
with End_of_file -> ())
1818

19-
type cmd = { name : string; section : string; summary : string }
19+
type cmd = { name : string; summary : string }
2020

2121
let section_prefix = "COMMANDS: "
2222

@@ -25,19 +25,19 @@ let parse_man' =
2525
| (kind', line) :: tl when kind = kind' -> collect (line :: acc) kind tl
2626
| tl -> (List.rev acc, tl)
2727
in
28-
let rec commands ~section = function
28+
let rec commands acc = function
2929
| (`Command, line) :: tl ->
3030
let name = List.hd (String.fields ~empty:false line) in
3131
let _, tl = collect [] `Command tl in
3232
let summary, tl = collect [] `Summary tl in
33-
{ name; section; summary = String.concat ~sep:" " summary }
34-
:: commands ~section tl
35-
| tl -> sections tl
33+
commands ({ name; summary = String.concat ~sep:" " summary } :: acc) tl
34+
| tl -> (List.rev acc, tl)
3635
and sections = function
3736
| (`Section, line) :: tl when String.is_prefix ~affix:section_prefix line ->
3837
let first = String.length section_prefix in
3938
let section = String.with_range ~first line in
40-
commands ~section tl
39+
let cmds, tl = commands [] tl in
40+
(section, cmds) :: sections tl
4141
| _ :: tl -> sections tl
4242
| [] -> []
4343
in
@@ -60,19 +60,32 @@ let parse_man inp =
6060
with End_of_file -> ());
6161
parse_man' (List.rev !lines)
6262

63-
let gen_preamble cmds =
64-
Printf.printf "{0 Odoc}\n\n{1 odoc}\nOdoc is made of several sub-commands.\n";
63+
open Printf
64+
65+
let gen_preamble sections =
66+
printf "{0 Odoc}\n\n{1 odoc}\nOdoc is made of several sub-commands.\n";
6567
List.iter
66-
(fun { name; summary; _ } ->
67-
Printf.printf "- {!\"odoc-%s\"} %s\n" name summary)
68-
cmds
68+
(fun (section, cmds) ->
69+
printf "\n%s:\n\n" section;
70+
List.iter
71+
(fun { name; summary; _ } ->
72+
printf "- {!\"odoc-%s\"} %s\n" name summary)
73+
cmds)
74+
sections
6975

70-
let gen_subcommand { name; _ } =
71-
Printf.printf "\n{1 odoc %s}\n\n{@man[\n%!" name;
72-
cat_command "odoc" [ name; "--help" ];
73-
Printf.printf "]}\n"
76+
let gen_manpages sections =
77+
List.iter
78+
(fun (section, cmds) ->
79+
printf "\n{1 %s}\n" section;
80+
List.iter
81+
(fun { name; _ } ->
82+
printf "\n{2 odoc %s}\n\n{@man[\n%!" name;
83+
cat_command "odoc" [ name; "--help" ];
84+
printf "]}\n")
85+
cmds)
86+
sections
7487

7588
let () =
76-
let subcommands = with_process_in "odoc" [ "--help" ] parse_man in
77-
gen_preamble subcommands;
78-
List.iter gen_subcommand subcommands
89+
let sections = with_process_in "odoc" [ "--help" ] parse_man in
90+
gen_preamble sections;
91+
gen_manpages sections

doc/manpage.mld

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
{1 odoc}
44
Odoc is made of several sub-commands.
5+
6+
Compilation pipeline:
7+
58
- {!"odoc-compile"} Compile a .cmti, .cmt, .cmi or .mld file to an .odoc file.
69
- {!"odoc-html-generate"} Generate html files from a .odocl.
710
- {!"odoc-link"} Second stage of compilation. Link a .odoc into a .odocl.
811
- {!"odoc-support-files"} Copy the support files (e.g. default theme, JavaScript files) to the output directory.
12+
13+
Alternative generators:
14+
915
- {!"odoc-latex-generate"} Generate latex files from a .odocl.
1016
- {!"odoc-man-generate"} Generate man files from a .odocl.
17+
18+
Scripting:
19+
1120
- {!"odoc-compile-deps"} List units (with their digest) which needs to be compiled in order to compile this one. The unit itself and its digest is also reported in the output. Dependencies between compile steps are the same as when compiling the ocaml modules.
1221
- {!"odoc-compile-targets"} Print the name of the file produced by compile. If -o is passed, the same path is printed but error checking is performed.
1322
- {!"odoc-errors"} Print errors that occurred while compiling or linking.
@@ -17,15 +26,23 @@ Odoc is made of several sub-commands.
1726
- {!"odoc-latex-url"} Resolve a reference and output its corresponding url.
1827
- {!"odoc-man-targets"} Print the files that would be generated by man-generate.
1928
- {!"odoc-support-files-targets"} Lists the names of the files that odoc support-files outputs.
29+
30+
Legacy pipeline:
31+
2032
- {!"odoc-html"} Render html files from a .odoc. link then html-generate should be used instead.
2133
- {!"odoc-html-fragment"} Generates an html fragment file from an mld one.
2234
- {!"odoc-latex"} Render latex files from a .odoc. link then latex-generate should be used instead.
2335
- {!"odoc-link-deps"} Lists a subset of the packages and modules which need to be in odoc's load path to link the odoc files in the given directory. Additional packages may be required to resolve all references.
2436
- {!"odoc-man"} Render man files from a .odoc. link then man-generate should be used instead.
37+
38+
Deprecated:
39+
2540
- {!"odoc-css"} DEPRECATED: Use odoc support-files to copy the CSS file for the default theme.
2641
- {!"odoc-html-deps"} DEPRECATED: alias for link-deps
2742

28-
{1 odoc compile}
43+
{1 Compilation pipeline}
44+
45+
{2 odoc compile}
2946

3047
{@man[
3148
NAME
@@ -115,7 +132,7 @@ ENVIRONMENT
115132

116133
]}
117134

118-
{1 odoc html-generate}
135+
{2 odoc html-generate}
119136

120137
{@man[
121138
NAME
@@ -188,7 +205,7 @@ ENVIRONMENT
188205

189206
]}
190207

191-
{1 odoc link}
208+
{2 odoc link}
192209

193210
{@man[
194211
NAME
@@ -258,7 +275,7 @@ ENVIRONMENT
258275

259276
]}
260277

261-
{1 odoc support-files}
278+
{2 odoc support-files}
262279

263280
{@man[
264281
NAME
@@ -286,7 +303,9 @@ OPTIONS
286303

287304
]}
288305

289-
{1 odoc latex-generate}
306+
{1 Alternative generators}
307+
308+
{2 odoc latex-generate}
290309

291310
{@man[
292311
NAME
@@ -334,7 +353,7 @@ ENVIRONMENT
334353

335354
]}
336355

337-
{1 odoc man-generate}
356+
{2 odoc man-generate}
338357

339358
{@man[
340359
NAME
@@ -379,7 +398,9 @@ ENVIRONMENT
379398

380399
]}
381400

382-
{1 odoc compile-deps}
401+
{1 Scripting}
402+
403+
{2 odoc compile-deps}
383404

384405
{@man[
385406
NAME
@@ -406,7 +427,7 @@ OPTIONS
406427

407428
]}
408429

409-
{1 odoc compile-targets}
430+
{2 odoc compile-targets}
410431

411432
{@man[
412433
NAME
@@ -439,7 +460,7 @@ OPTIONS
439460

440461
]}
441462

442-
{1 odoc errors}
463+
{2 odoc errors}
443464

444465
{@man[
445466
NAME
@@ -463,7 +484,7 @@ OPTIONS
463484

464485
]}
465486

466-
{1 odoc html-targets}
487+
{2 odoc html-targets}
467488

468489
{@man[
469490
NAME
@@ -524,7 +545,7 @@ OPTIONS
524545

525546
]}
526547

527-
{1 odoc html-url}
548+
{2 odoc html-url}
528549

529550
{@man[
530551
NAME
@@ -585,7 +606,7 @@ OPTIONS
585606

586607
]}
587608

588-
{1 odoc latex-targets}
609+
{2 odoc latex-targets}
589610

590611
{@man[
591612
NAME
@@ -620,7 +641,7 @@ OPTIONS
620641

621642
]}
622643

623-
{1 odoc latex-url}
644+
{2 odoc latex-url}
624645

625646
{@man[
626647
NAME
@@ -648,7 +669,7 @@ OPTIONS
648669

649670
]}
650671

651-
{1 odoc man-targets}
672+
{2 odoc man-targets}
652673

653674
{@man[
654675
NAME
@@ -680,7 +701,7 @@ OPTIONS
680701

681702
]}
682703

683-
{1 odoc support-files-targets}
704+
{2 odoc support-files-targets}
684705

685706
{@man[
686707
NAME
@@ -708,7 +729,9 @@ OPTIONS
708729

709730
]}
710731

711-
{1 odoc html}
732+
{1 Legacy pipeline}
733+
734+
{2 odoc html}
712735

713736
{@man[
714737
NAME
@@ -805,7 +828,7 @@ ENVIRONMENT
805828

806829
]}
807830

808-
{1 odoc html-fragment}
831+
{2 odoc html-fragment}
809832

810833
{@man[
811834
NAME
@@ -867,7 +890,7 @@ ENVIRONMENT
867890

868891
]}
869892

870-
{1 odoc latex}
893+
{2 odoc latex}
871894

872895
{@man[
873896
NAME
@@ -939,7 +962,7 @@ ENVIRONMENT
939962

940963
]}
941964

942-
{1 odoc link-deps}
965+
{2 odoc link-deps}
943966

944967
{@man[
945968
NAME
@@ -966,7 +989,7 @@ OPTIONS
966989

967990
]}
968991

969-
{1 odoc man}
992+
{2 odoc man}
970993

971994
{@man[
972995
NAME
@@ -1034,7 +1057,9 @@ ENVIRONMENT
10341057

10351058
]}
10361059

1037-
{1 odoc css}
1060+
{1 Deprecated}
1061+
1062+
{2 odoc css}
10381063

10391064
{@man[
10401065
NAME
@@ -1062,7 +1087,7 @@ OPTIONS
10621087

10631088
]}
10641089

1065-
{1 odoc html-deps}
1090+
{2 odoc html-deps}
10661091

10671092
{@man[
10681093
NAME

0 commit comments

Comments
 (0)