Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[enhance] serverArg: added function write_simple_manpage

  • Loading branch information...
commit ad1c0cd06b5feff0cb5057468fdad7ff77943330 1 parent b79d8ce
Mathieu Baudet authored
Showing with 46 additions and 0 deletions.
  1. +32 −0 libruntime/serverArg.ml
  2. +14 −0 libruntime/serverArg.mli
View
32 libruntime/serverArg.ml
@@ -241,6 +241,38 @@ let doc_string title speclist =
speclist;
Format.flush_str_formatter ()
+let write_simple_manpage
+ ?(nohelp=false)
+ ~cmdname ~section
+ ?centerfooter
+ ?leftfooter ?centerheader
+ ~summary ?synopsis ?description ?options ?(other=[])
+ file
+ =
+ let print_spec buf (names,_,params_doc,doc) =
+ let names_str = List.fold_left (fun str name -> str ^ (BaseString.replace name "-" "\\-") ^ " ") "" names
+ in
+ Printf.bprintf buf ".TP\n%s%s\n%s\n" names_str params_doc doc
+ in
+ let help_dummy_spec = (["--help"; "-help"; "-h"; "-?"], (fun _ -> failwith "help_dummy_spec"), "", "Print this help")
+ in
+ let options_str =
+ begin match options with
+ None -> None
+ | Some(speclist) ->
+ let buf = Buffer.create 10
+ in
+ List.iter (print_spec buf) (if nohelp then speclist else speclist@[help_dummy_spec]);
+ Some(Buffer.contents buf)
+ end
+ in
+ BaseArg.write_simple_manpage
+ ~cmdname ~section
+ ?centerfooter
+ ?leftfooter ?centerheader
+ ~summary ?synopsis ?description ~other:(match options_str with None -> other | Some(str) -> ("OPTIONS", str)::other)
+ file
+
let make_parser ?(final=false) ?(nohelp=false) title speclist acc0 args0 =
let rec do_args (acc,rev_args) = function
| [] -> (Some acc, List.rev rev_args, [])
View
14 libruntime/serverArg.mli
@@ -162,6 +162,20 @@ type 'a arg_parser = string list * ('a -> 'a param_parser) * string * string
val doc_string: string -> 'a arg_parser list -> string
(** Doc string as printed by --help. The first argument is the title. *)
+val write_simple_manpage :
+ ?nohelp:bool ->
+ cmdname:string ->
+ section:int ->
+ ?centerfooter:string ->
+ ?leftfooter:string ->
+ ?centerheader:string ->
+ summary:string ->
+ ?synopsis:string ->
+ ?description:string ->
+ ?options:'a arg_parser list ->
+ ?other:(string * string) list -> out_channel -> unit
+ (** Create a simple manpage. *)
+
val make_parser: ?final:bool -> ?nohelp:bool -> string -> 'a arg_parser list -> 'a -> 'a param_parser
(** Makes a param_parser from a list of arg_parsers. The '-help' and '--help'
options have a default handler that turns off handling of other options,
Please sign in to comment.
Something went wrong with that request. Please try again.