Skip to content
Snippets Groups Projects
Commit c69097ff authored by David Bühler's avatar David Bühler
Browse files

[cmdline] Supports invisible and deprecated aliases for command line parameters.

Invisible aliases are not printed in the help message of the plugin or kernel.
Deprecated aliases emit a warning when used.
parent 4ed9c09e
No related branches found
No related tags found
No related merge requests found
...@@ -253,6 +253,11 @@ type option_setting = ...@@ -253,6 +253,11 @@ type option_setting =
| Int of (int -> unit) | Int of (int -> unit)
| String of (string -> unit) | String of (string -> unit)
let option_setting_and_warn warn = function
| Unit f -> Unit (fun () -> warn (); f ())
| Int f -> Int (fun i -> warn (); f i)
| String f -> String (fun s -> warn (); f s)
exception Cannot_parse of string * string exception Cannot_parse of string * string
let raise_error name because = raise (Cannot_parse(name, because)) let raise_error name because = raise (Cannot_parse(name, because))
...@@ -436,7 +441,8 @@ module Plugin: sig ...@@ -436,7 +441,8 @@ module Plugin: sig
val add_group: ?memo:bool -> plugin:string -> string -> string * bool val add_group: ?memo:bool -> plugin:string -> string -> string * bool
val add_option: string -> group:string -> cmdline_option -> unit val add_option: string -> group:string -> cmdline_option -> unit
val add_aliases: val add_aliases:
orig:string -> string -> group:string -> string list -> cmdline_option list orig:string -> string -> group:string -> ?visible:bool -> ?deprecated:bool
-> string list -> cmdline_option list
val replace_option_setting: val replace_option_setting:
string -> plugin:string -> group:string -> option_setting -> unit string -> plugin:string -> group:string -> option_setting -> unit
val replace_option_help: val replace_option_help:
...@@ -525,7 +531,7 @@ end = struct ...@@ -525,7 +531,7 @@ end = struct
(* table name_of_the_original_option --> aliases *) (* table name_of_the_original_option --> aliases *)
let aliases_tbl = Hashtbl.create 7 let aliases_tbl = Hashtbl.create 7
let add_aliases ~orig shortname ~group names = let add_aliases ~orig shortname ~group ?(visible=true) ?(deprecated=false) names =
(* mostly inline [add_option] and perform additional actions *) (* mostly inline [add_option] and perform additional actions *)
let options_group = find_group shortname group in let options_group = find_group shortname group in
let option = List.find (fun o -> o.oname = orig) !options_group in let option = List.find (fun o -> o.oname = orig) !options_group in
...@@ -533,7 +539,19 @@ end = struct ...@@ -533,7 +539,19 @@ end = struct
if name = "" then invalid_arg "empty alias name"; if name = "" then invalid_arg "empty alias name";
Hashtbl.replace all_options name option; Hashtbl.replace all_options name option;
Option_names.add name true; Option_names.add name true;
let alias = { option with oname = name } in let setting =
if deprecated
then
let warn () =
Kernel_log.warning ~once:true
"@[%s is@ a deprecated alias@ for option %s.@ \
Please use %s instead.@]"
name option.oname option.oname
in
option_setting_and_warn warn option.setting
else option.setting
in
let alias = { option with oname = name; ovisible = visible; setting; } in
options_group := alias :: !options_group; options_group := alias :: !options_group;
alias alias
in in
...@@ -723,8 +741,8 @@ let add_option_without_action ...@@ -723,8 +741,8 @@ let add_option_without_action
ohelp = help; ext_help = ext_help; ovisible = visible; ohelp = help; ext_help = ext_help; ovisible = visible;
setting = Unit (fun () -> assert false) } setting = Unit (fun () -> assert false) }
let add_aliases orig ~plugin ~group stage aliases = let add_aliases orig ~plugin ~group ?visible ?deprecated stage aliases =
let l = Plugin.add_aliases ~orig plugin ~group aliases in let l = Plugin.add_aliases ~orig plugin ~group ?visible ?deprecated aliases in
let add = match stage with let add = match stage with
| Early -> Early_Stage.add_for_parsing | Early -> Early_Stage.add_for_parsing
| Extending -> Extending_Stage.add_for_parsing | Extending -> Extending_Stage.add_for_parsing
...@@ -899,7 +917,8 @@ let low_print_option_help fmt print_invisible o = ...@@ -899,7 +917,8 @@ let low_print_option_help fmt print_invisible o =
print_helpline fmt (name ^ ty) o.ohelp o.ext_help; print_helpline fmt (name ^ ty) o.ohelp o.ext_help;
List.iter List.iter
(fun o -> (fun o ->
print_helpline fmt (o.oname ^ ty) ("alias for option " ^ name) "") if print_invisible || o.ovisible then
print_helpline fmt (o.oname ^ ty) ("alias for option " ^ name) "")
(Plugin.find_option_aliases o) (Plugin.find_option_aliases o)
end; end;
true true
......
...@@ -313,13 +313,18 @@ val add_aliases: ...@@ -313,13 +313,18 @@ val add_aliases:
string -> string ->
plugin:string -> plugin:string ->
group:Group.t -> group:Group.t ->
?visible: bool ->
?deprecated: bool ->
stage -> stage ->
string list -> string list ->
unit unit
(** [add_aliases orig plugin group aliases] adds a list of aliases to the given (** [add_aliases orig plugin group aliases] adds a list of aliases to the given
option name [orig]. option name [orig].
If [visible] is set to false, the aliases do not appear in help messages.
If [deprecated] is set to true, the use of the aliases emits a warning.
@Invalid_argument if an alias name is the empty string @Invalid_argument if an alias name is the empty string
@since Carbon-20110201 *) @since Carbon-20110201
@modify Frama-c+dev add [visible] and [deprecated] arguments. *)
val replace_option_setting: val replace_option_setting:
string -> plugin:string -> group:Group.t -> option_setting -> unit string -> plugin:string -> group:Group.t -> option_setting -> unit
......
...@@ -223,14 +223,15 @@ struct ...@@ -223,14 +223,15 @@ struct
~plugin X.option_name Typed_parameter.ty ~journalize:false p ~plugin X.option_name Typed_parameter.ty ~journalize:false p
else p else p
let add_aliases list = let add_aliases ?visible ?deprecated list =
add_aliases list; add_aliases ?visible ?deprecated list;
match !negative_option_ref with match !negative_option_ref with
| None -> () | None -> ()
| Some negative_option -> | Some negative_option ->
let negative_list = List.map negate_name list in let negative_list = List.map negate_name list in
let plugin = P.shortname in let plugin = P.shortname in
Cmdline.add_aliases negative_option ~plugin ~group stage negative_list Cmdline.add_aliases
negative_option ~plugin ~group ?visible ?deprecated stage negative_list
end end
...@@ -1719,8 +1720,8 @@ struct ...@@ -1719,8 +1720,8 @@ struct
f (); f ();
end end
let add_aliases list = let add_aliases ?visible ?deprecated list =
add_aliases list; add_aliases ?visible ?deprecated list;
Output.add_aliases (List.map (fun alias -> alias ^ "-print") list) Output.add_aliases (List.map (fun alias -> alias ^ "-print") list)
end end
......
...@@ -179,10 +179,13 @@ module type S_no_parameter = sig ...@@ -179,10 +179,13 @@ module type S_no_parameter = sig
val equal: t -> t -> bool val equal: t -> t -> bool
val add_aliases: string list -> unit val add_aliases: ?visible: bool -> ?deprecated:bool -> string list -> unit
(** Add some aliases for this option. That is other option names which have (** Add some aliases for this option. That is other option names which have
exactly the same semantics that the initial option. exactly the same semantics that the initial option.
@raise Invalid_argument if one of the strings is empty *) If [visible] is set to false, the aliases do not appear in help messages.
If [deprecated] is set to true, the use of the aliases emits a warning.
@raise Invalid_argument if one of the strings is empty
@modify Frama-c+dev add [visible] and [deprecated] arguments. *)
(**/**) (**/**)
val is_set: unit -> bool val is_set: unit -> bool
......
...@@ -270,8 +270,9 @@ struct ...@@ -270,8 +270,9 @@ struct
let option_name = X.option_name let option_name = X.option_name
let add_aliases = let add_aliases ?visible ?deprecated =
Cmdline.add_aliases option_name ~plugin:P.shortname ~group stage Cmdline.add_aliases
option_name ~plugin:P.shortname ~group stage ?visible ?deprecated
let print_help fmt = let print_help fmt =
Cmdline.print_option_help fmt ~plugin:P.shortname ~group option_name Cmdline.print_option_help fmt ~plugin:P.shortname ~group option_name
......
...@@ -44,7 +44,8 @@ module type S_no_log = sig ...@@ -44,7 +44,8 @@ module type S_no_log = sig
module Config: Parameter_sig.Specific_dir module Config: Parameter_sig.Specific_dir
val help: Cmdline.Group.t val help: Cmdline.Group.t
val messages: Cmdline.Group.t val messages: Cmdline.Group.t
val add_plugin_output_aliases: string list -> unit val add_plugin_output_aliases:
?visible:bool -> ?deprecated:bool -> string list -> unit
end end
module type S = sig module type S = sig
...@@ -795,14 +796,14 @@ struct ...@@ -795,14 +796,14 @@ struct
let is_kernel = is_kernel () in let is_kernel = is_kernel () in
Warn_category.add_set_hook (parse_warn_directives is_kernel) Warn_category.add_set_hook (parse_warn_directives is_kernel)
let add_plugin_output_aliases aliases = let add_plugin_output_aliases ?visible ?deprecated aliases =
let aliases = List.filter (fun alias -> alias <> "") aliases in let aliases = List.filter (fun alias -> alias <> "") aliases in
let optname suffix = List.map (fun alias -> "-" ^ alias ^ suffix) aliases in let optname suffix = List.map (fun alias -> "-" ^ alias ^ suffix) aliases in
Help.add_aliases (optname "-help"); Help.add_aliases ?visible ?deprecated (optname "-help");
Verbose.add_aliases (optname "-verbose"); Verbose.add_aliases ?visible ?deprecated (optname "-verbose");
Debug_category.add_aliases (optname "-msg-key"); Debug_category.add_aliases ?visible ?deprecated (optname "-msg-key");
Warn_category.add_aliases (optname "-warn-key"); Warn_category.add_aliases ?visible ?deprecated (optname "-warn-key");
LogToFile.add_aliases (optname "-log") LogToFile.add_aliases ?visible ?deprecated (optname "-log")
let () = reset_plugin () let () = reset_plugin ()
......
...@@ -64,12 +64,14 @@ module type S_no_log = sig ...@@ -64,12 +64,14 @@ module type S_no_log = sig
(** The group containing options -*-debug and -*-verbose. (** The group containing options -*-debug and -*-verbose.
@since Boron-20100401 *) @since Boron-20100401 *)
val add_plugin_output_aliases: string list -> unit val add_plugin_output_aliases:
(** Adds aliases to the options -plugin-help, -plugin-verbose, -plugin-log, ?visible:bool -> ?deprecated:bool -> string list -> unit
-plugin-msg-key, and -plugin-warn-key. (** Adds aliases to the options -plugin-help, -plugin-verbose, -plugin-log,
[add_plugin_output_aliases [alias]] adds the aliases -alias-help, -plugin-msg-key, and -plugin-warn-key.
-alias-verbose, etc. [add_plugin_output_aliases [alias]] adds the aliases -alias-help,
@since 18.0-Argon *) -alias-verbose, etc.
@since 18.0-Argon
@modify Frama-c+dev add [visible] and [deprecated] arguments. *)
end end
(** Provided plug-general services for plug-ins. (** Provided plug-general services for plug-ins.
......
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