Skip to content

Commit 3c7ba96

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 3a8fd72 commit 3c7ba96

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-errors"} Print errors that occurred while compiling or linking.
1322
- {!"odoc-html-targets"} Print the files that would be generated by html-generate.
@@ -16,16 +25,24 @@ Odoc is made of several sub-commands.
1625
- {!"odoc-latex-url"} Resolve a reference and output its corresponding url.
1726
- {!"odoc-man-targets"} Print the files that would be generated by man-generate.
1827
- {!"odoc-support-files-targets"} Lists the names of the files that odoc support-files outputs.
28+
29+
Legacy pipeline:
30+
1931
- {!"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.
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
@@ -192,7 +209,7 @@ ENVIRONMENT
192209

193210
]}
194211

195-
{1 odoc link}
212+
{2 odoc link}
196213

197214
{@man[
198215
NAME
@@ -262,7 +279,7 @@ ENVIRONMENT
262279

263280
]}
264281

265-
{1 odoc support-files}
282+
{2 odoc support-files}
266283

267284
{@man[
268285
NAME
@@ -290,7 +307,9 @@ OPTIONS
290307

291308
]}
292309

293-
{1 odoc latex-generate}
310+
{1 Alternative generators}
311+
312+
{2 odoc latex-generate}
294313

295314
{@man[
296315
NAME
@@ -338,7 +357,7 @@ ENVIRONMENT
338357

339358
]}
340359

341-
{1 odoc man-generate}
360+
{2 odoc man-generate}
342361

343362
{@man[
344363
NAME
@@ -383,7 +402,9 @@ ENVIRONMENT
383402

384403
]}
385404

386-
{1 odoc compile-deps}
405+
{1 Scripting}
406+
407+
{2 odoc compile-deps}
387408

388409
{@man[
389410
NAME
@@ -410,7 +431,7 @@ OPTIONS
410431

411432
]}
412433

413-
{1 odoc errors}
434+
{2 odoc errors}
414435

415436
{@man[
416437
NAME
@@ -434,7 +455,7 @@ OPTIONS
434455

435456
]}
436457

437-
{1 odoc html-targets}
458+
{2 odoc html-targets}
438459

439460
{@man[
440461
NAME
@@ -499,7 +520,7 @@ OPTIONS
499520

500521
]}
501522

502-
{1 odoc html-url}
523+
{2 odoc html-url}
503524

504525
{@man[
505526
NAME
@@ -564,7 +585,7 @@ OPTIONS
564585

565586
]}
566587

567-
{1 odoc latex-targets}
588+
{2 odoc latex-targets}
568589

569590
{@man[
570591
NAME
@@ -599,7 +620,7 @@ OPTIONS
599620

600621
]}
601622

602-
{1 odoc latex-url}
623+
{2 odoc latex-url}
603624

604625
{@man[
605626
NAME
@@ -627,7 +648,7 @@ OPTIONS
627648

628649
]}
629650

630-
{1 odoc man-targets}
651+
{2 odoc man-targets}
631652

632653
{@man[
633654
NAME
@@ -659,7 +680,7 @@ OPTIONS
659680

660681
]}
661682

662-
{1 odoc support-files-targets}
683+
{2 odoc support-files-targets}
663684

664685
{@man[
665686
NAME
@@ -687,7 +708,9 @@ OPTIONS
687708

688709
]}
689710

690-
{1 odoc compile-targets}
711+
{1 Legacy pipeline}
712+
713+
{2 odoc compile-targets}
691714

692715
{@man[
693716
NAME
@@ -720,7 +743,7 @@ OPTIONS
720743

721744
]}
722745

723-
{1 odoc html}
746+
{2 odoc html}
724747

725748
{@man[
726749
NAME
@@ -821,7 +844,7 @@ ENVIRONMENT
821844

822845
]}
823846

824-
{1 odoc html-fragment}
847+
{2 odoc html-fragment}
825848

826849
{@man[
827850
NAME
@@ -883,7 +906,7 @@ ENVIRONMENT
883906

884907
]}
885908

886-
{1 odoc latex}
909+
{2 odoc latex}
887910

888911
{@man[
889912
NAME
@@ -955,7 +978,7 @@ ENVIRONMENT
955978

956979
]}
957980

958-
{1 odoc link-deps}
981+
{2 odoc link-deps}
959982

960983
{@man[
961984
NAME
@@ -982,7 +1005,7 @@ OPTIONS
9821005

9831006
]}
9841007

985-
{1 odoc man}
1008+
{2 odoc man}
9861009

9871010
{@man[
9881011
NAME
@@ -1050,7 +1073,9 @@ ENVIRONMENT
10501073

10511074
]}
10521075

1053-
{1 odoc css}
1076+
{1 Deprecated}
1077+
1078+
{2 odoc css}
10541079

10551080
{@man[
10561081
NAME
@@ -1078,7 +1103,7 @@ OPTIONS
10781103

10791104
]}
10801105

1081-
{1 odoc html-deps}
1106+
{2 odoc html-deps}
10821107

10831108
{@man[
10841109
NAME

0 commit comments

Comments
 (0)