Skip to content

Commit d1be1ac

Browse files
committed
generate a proper --help/manpage thanks to cmdliner
1 parent 628a026 commit d1be1ac

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

bin/mustache_cli.ml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,51 @@ let run json_filename template_filename =
4343
let run_command =
4444
let open Cmdliner in
4545
let doc = "renders Mustache template from JSON data files" in
46+
let man = [
47+
`S Manpage.s_description;
48+
`P "$(tname) is a command-line tool coming with the $(i,ocaml-mustache) library,
49+
an OCaml implementation of the Mustache template format.
50+
$(tname) takes a data file and a template file as command-line parameters;
51+
it renders the populated template on standard output.";
52+
53+
`P "Mustache is a simple and popular template format,
54+
with library implementations in many programming languages.
55+
It is named from its {{..}} delimiters.";
56+
57+
`I ("Mustache website",
58+
"https://mustache.github.io/");
59+
`I ("Mustache templates documentation",
60+
"https://mustache.github.io/mustache.5.html");
61+
`I ("ocaml-mustache website:",
62+
"https://github.com/rgrinberg/ocaml-mustache");
63+
64+
`P "The $(i,ocaml-mustache) implementation is tested against
65+
the Mustache specification testsuite.
66+
All features are supported, except for lambdas and setting delimiter tags.";
67+
`S Manpage.s_examples;
68+
`Pre
69+
{|
70+
\$ cat data.json
71+
{ "name": "OCaml",
72+
"qualities": [{"name": "simple"}, {"name": "fun"}] }
73+
74+
\$ cat hello.mustache
75+
Hello {{name}}!
76+
Mustache is:
77+
{{#qualities}}
78+
- {{name}}
79+
{{/qualities}}
80+
81+
\$ $(tname) data.json hello.mustache
82+
Hello OCaml!
83+
Mustache is:
84+
- simple
85+
- fun
86+
|};
87+
`S Manpage.s_bugs;
88+
`P "Report bugs on https://github.com/rgrinberg/ocaml-mustache/issues";
89+
]
90+
in
4691
let json_file =
4792
let doc = "data file in JSON format" in
4893
Arg.(required & pos 0 (some file) None & info [] ~docv:"DATA.json" ~doc)
@@ -52,7 +97,7 @@ let run_command =
5297
Arg.(required & pos 1 (some file) None & info [] ~docv:"TEMPLATE.mustache" ~doc)
5398
in
5499
Term.(const run $ json_file $ template_file),
55-
Term.info "mustache" ~doc
100+
Term.info "mustache" ~doc ~man
56101

57102

58103
let () =

0 commit comments

Comments
 (0)