@@ -40,11 +40,66 @@ let run json_filename template_filename =
4040 Mustache. pp_render_error err;
4141 exit 2
4242
43- let usage () =
44- print_endline " Usage: mustache-cli json_filename template_filename"
43+ let run_command =
44+ let open Cmdliner in
45+ 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
91+ let json_file =
92+ let doc = "data file in JSON format" in
93+ Arg. (required & pos 0 (some file ) None & info [] ~docv :"DATA.json" ~doc )
94+ in
95+ let template_file =
96+ let doc = "mustache template" in
97+ Arg. (required & pos 1 (some file ) None & info [] ~docv :"TEMPLATE.mustache" ~doc )
98+ in
99+ Term. (const run $ json_file $ template_file ),
100+ Term. info "mustache" ~doc ~man
101+
45102
46103let () =
47- match Sys. argv with
48- | [| _ ; json_filename ; template_filename |]
49- -> run json_filename template_filename
50- | _ -> usage ()
104+ let open Cmdliner in
105+ Term. exit @@ Term. eval run_command
0 commit comments