Skip to content

Commit

Permalink
Fix deprecated args (#854)
Browse files Browse the repository at this point in the history
* warn user in case of using deprecated flags

also warns if deprecated parameter is used as flag

* renaming

* renamed
  • Loading branch information
gitoleg authored and ivg committed Aug 10, 2018
1 parent c81a157 commit e73753b
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lib/bap/bap_self.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Create() = struct

let manifest =
try Bundle.manifest bundle
with exn -> Manifest.create main
with _exn -> Manifest.create main

let name = Manifest.name manifest
let version = Manifest.version manifest
Expand Down Expand Up @@ -102,9 +102,15 @@ module Create() = struct
type 'a parser = string -> [ `Ok of 'a | `Error of string ]
type 'a printer = formatter -> 'a -> unit

let warn_if msg name is_used = match msg with
| Some msg when is_used ->
eprintf "WARNING: %S option of plugin %S is deprecated. %s\n"
name plugin_name msg
| _ -> ()

module Converter = struct
type 'a t = {
parser : 'a parser;
parser : 'a parser;
printer : 'a printer;
default : 'a;
}
Expand All @@ -114,14 +120,9 @@ module Create() = struct
let default conv = conv.default

let deprecation_wrap ~converter ?deprecated ~name =
let warn_if_deprecated () =
match deprecated with
| Some msg ->
eprintf "WARNING: %S option of plugin %S is deprecated. %s\n"
name plugin_name msg
| None -> () in
{converter with parser=(fun s -> warn_if_deprecated ();
converter.parser s)}
{converter with
parser=(fun s -> warn_if deprecated name true;
converter.parser s)}

let of_arg (conv:'a Arg.converter) (default:'a) : 'a t =
let parser, printer = conv in
Expand Down Expand Up @@ -199,11 +200,16 @@ module Create() = struct
| None -> Converter.default converter in
let converter = Converter.to_arg converter in
let param = get_param ~converter ~default ~name in
let check x = match as_flag with
| None -> ()
| Some y ->
warn_if deprecated name (phys_equal x y) in
let t =
Arg.(value
@@ opt ?vopt:as_flag converter param
@@ info (name::synonyms) ~doc ~docv) in
main := Term.(const (fun x () ->
check x;
Promise.fulfill promise x) $ t $ (!main));
future

Expand All @@ -219,7 +225,11 @@ module Create() = struct
Arg.(value
@@ opt_all ?vopt:as_flag converter param
@@ info (name::synonyms) ~doc ~docv) in
let check x = match x, as_flag with
| [x], Some y -> warn_if deprecated name (phys_equal x y)
| _ -> () in
main := Term.(const (fun x () ->
check x;
Promise.fulfill promise x) $ t $ (!main));
future

Expand All @@ -233,7 +243,9 @@ module Create() = struct
let param = get_param ~converter ~default:false ~name in
let t =
Arg.(value @@ flag @@ info (name::synonyms) ~doc ~docv) in
let check = warn_if deprecated name in
main := Term.(const (fun x () ->
check (param || x);
Promise.fulfill promise (param || x)) $ t $ (!main));
future

Expand Down Expand Up @@ -268,8 +280,7 @@ module Create() = struct
| [], man -> default_see_also, man
| x -> x in
let tags = [
`P (Manifest.tags manifest |>
String.concat ~sep:", " |>
`P (String.concat tags ~sep:", " |>
sprintf "$(b,tags:) %s") ] in
man @ see_also @ tags

Expand Down

0 comments on commit e73753b

Please sign in to comment.