[manual] add --help-format option

Summary:
Allows one to dump the manuals in various formats:
- plain: plain text
- pager: default, display the man page in all its glory inside a pager
- groff: the source code of the man page
- auto: pager or plain

Reviewed By: mbouaziz

Differential Revision: D5027636

fbshipit-source-id: 3b97edc
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent 709376945f
commit d508b0880d

@ -816,7 +816,7 @@ let wrap_line indent_string wrap_length line0 =
List.fold ~f:add_word_to_paragraph ~init:([], false, "", 0) words in
List.rev (line::rev_lines)
let show_manual ?internal_section default_doc command_opt =
let show_manual ?internal_section format default_doc command_opt =
let command_doc = match command_opt with
| None ->
default_doc
@ -865,5 +865,5 @@ let show_manual ?internal_section default_doc command_opt =
!sections hidden in
let blocks = [`Blocks command_doc.manual_pre_options; `Blocks option_blocks;
`Blocks command_doc.manual_post_options] in
Cmdliner.Manpage.print `Auto Format.std_formatter (command_doc.title, blocks);
Cmdliner.Manpage.print format Format.std_formatter (command_doc.title, blocks);
()

@ -227,6 +227,8 @@ val parse : ?config_file:string -> usage:Arg.usage_msg -> parse_mode -> command
(** [is_env_var_set var] is true if $[var]=1 *)
val is_env_var_set : string -> bool
(** Display the manual of [command] to the user, or [command_doc] if [command] is None. If
[internal_section] is true, add a section about internal (hidden) options. *)
val show_manual : ?internal_section:string -> command_doc -> command option -> unit
(** Display the manual of [command] to the user, or [command_doc] if [command] is None. [format] is
used as for [Cmdliner.Manpage.print]. If [internal_section] is specified, add a section titled
[internal_section] about internal (hidden) options. *)
val show_manual : ?internal_section:string -> Cmdliner.Manpage.format -> command_doc
-> command option -> unit

@ -978,6 +978,14 @@ and help =
(Printf.sprintf "Show this manual with all internal options in the %s section" manual_internal);
var
and help_format =
CLOpt.mk_symbol ~long:"help-format"
~symbols:[("auto", `Auto); ("groff", `Groff); ("pager", `Pager); ("plain", `Plain)]
~eq:PVariant.(=) ~default:`Auto
~in_help:(List.map CLOpt.all_commands ~f:(fun command -> command, manual_generic))
"Show this help in the specified format. $(b,auto) sets the format to $(b,plain) if the \
environment variable $(b,TERM) is \"dumb\" or undefined, and to $(b,pager) otherwise."
and icfg_dotty_outfile =
CLOpt.mk_path_opt ~long:"icfg-dotty-outfile" ~meta:"path"
"If set, specifies path where .dot file should be written, it overrides the path for all \
@ -1548,9 +1556,9 @@ let post_parsing_initialization command_opt =
);
(match !help with
| `Help ->
CLOpt.show_manual CommandDoc.infer command_opt
CLOpt.show_manual !help_format CommandDoc.infer command_opt
| `HelpFull ->
CLOpt.show_manual ~internal_section:manual_internal CommandDoc.infer command_opt
CLOpt.show_manual ~internal_section:manual_internal !help_format CommandDoc.infer command_opt
| `None ->
()
);

Loading…
Cancel
Save