Skip to content
Snippets Groups Projects
Commit b404ec34 authored by Andre Maroneze's avatar Andre Maroneze
Browse files

[Kernel] New option -explain that prints the help message for all given options.

parent 189f9741
No related branches found
No related tags found
No related merge requests found
...@@ -1072,6 +1072,53 @@ let list_all_plugin_options ~print_invisible = ...@@ -1072,6 +1072,53 @@ let list_all_plugin_options ~print_invisible =
end; end;
raise Exit raise Exit
(* ************************************************************************* *)
(** {3 Explain}
Special processing for option "-explain" *)
(* ************************************************************************* *)
let print_help_for_options option_names =
let messages_to_print = Hashtbl.create 5 in
let option_names =
List.filter (fun o -> o <> "-explain") option_names
in
Log.print_on_output
begin fun fmt ->
List.iter (fun plugin ->
Hashtbl.iter
(fun _gname opts ->
List.iter (fun o ->
if List.mem o.oname option_names then
Hashtbl.replace messages_to_print o.oname (o.argname, o.ohelp)
) !opts
) plugin.Plugin.groups
) (Plugin.all_plugins ());
Format.fprintf fmt
"[kernel] Explaining command-line options:@.";
List.iter (fun opt_name ->
let (helparg, help) = Hashtbl.find messages_to_print opt_name in
Format.fprintf fmt "@[<v>%s%s@\n %s@]@." opt_name
(if helparg <> "" then " " ^ helparg else helparg) help
) option_names;
end;
raise Exit
(* [option_re] allows matching an option and extracting its name,
even when there is a '=', e.g. "-kernel-msg-key=-typing".
It also prevents matching negative numbers, as in "-ulevel -1". *)
let option_re = Str.regexp "-\\([a-zA-Z-][a-zA-Z0-9-]*\\)"
let explain_cmdline () =
let option_names =
List.fold_left (fun acc opt ->
if Str.string_match option_re opt 0 then
let opt_name = Str.matched_string opt in
opt_name :: acc
else acc
) [] all_options
in
print_help_for_options (List.rev option_names)
(* (*
Local Variables: Local Variables:
compile-command: "make -C ../../.." compile-command: "make -C ../../.."
......
...@@ -244,6 +244,8 @@ val list_plugins: unit -> exit ...@@ -244,6 +244,8 @@ val list_plugins: unit -> exit
@since Phosphorus-20170501-beta1 *) @since Phosphorus-20170501-beta1 *)
val list_all_plugin_options : print_invisible:bool -> exit val list_all_plugin_options : print_invisible:bool -> exit
val explain_cmdline : unit -> exit
val plugin_help: string -> exit val plugin_help: string -> exit
(** Display the help of the given plug-in (given by its shortname). (** Display the help of the given plug-in (given by its shortname).
@since Beryllium-20090601-beta1 *) @since Beryllium-20090601-beta1 *)
......
...@@ -429,6 +429,26 @@ let run_list_all_plugin_options () = ...@@ -429,6 +429,26 @@ let run_list_all_plugin_options () =
else Cmdline.nop else Cmdline.nop
let () = Cmdline.run_after_exiting_stage run_list_all_plugin_options let () = Cmdline.run_after_exiting_stage run_list_all_plugin_options
let () = Parameter_customize.set_group help
let () = Parameter_customize.set_cmdline_stage Cmdline.Exiting
let () = Parameter_customize.do_not_journalize ()
let () = Parameter_customize.set_negative_option_name ""
module Explain =
False
(struct
let option_name = "-explain"
let help = "prints the help message for each option given in the \
command line"
let module_name = "Explain"
end)
let () =
Cmdline.run_after_exiting_stage (fun () ->
if Explain.get () then Cmdline.explain_cmdline ()
else Cmdline.nop)
(* This option is processed in a special manner in [Cmdline].
Nothing to be done here. *)
(* ************************************************************************* *) (* ************************************************************************* *)
(** {2 Output Messages} *) (** {2 Output Messages} *)
(* ************************************************************************* *) (* ************************************************************************* *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment