@@ -31,6 +31,7 @@ type t =
3131 ; optim : string list on_off
3232 ; quiet : bool
3333 ; werror : bool
34+ ; warnings : (bool * Warning .t ) list
3435 ; custom_header : string option
3536 }
3637
@@ -61,6 +62,35 @@ let disable =
6162 in
6263 Term. (const List. flatten $ arg))
6364
65+ let parse_warning s =
66+ let err s = `Msg (Printf. sprintf " Unknown warning %s" s) in
67+ if String. is_empty s
68+ then Error (err s)
69+ else
70+ match Warning. parse s with
71+ | Some n -> Ok (true , n)
72+ | None -> (
73+ match String. drop_prefix ~prefix: " no-" s with
74+ | Some n -> (
75+ match Warning. parse n with
76+ | Some n -> Ok (false , n)
77+ | None -> Error (err n))
78+ | None -> Error (err s))
79+
80+ let print_warning fmt (b , w ) =
81+ Format. fprintf
82+ fmt
83+ " %s%s"
84+ (match b with
85+ | true -> " "
86+ | false -> " " )
87+ (Warning. name w)
88+
89+ let warnings : (bool * Warning.t) list Term.t =
90+ let doc = " Enable or disable the warnings specified by the argument [$(docv)]." in
91+ let c : 'a Arg.conv = Arg. conv ~docv: " " (parse_warning, print_warning) in
92+ Arg. (value & opt_all c [] & info [ " w" ] ~docv: " WARN" ~doc )
93+
6494let pretty =
6595 let doc = " Pretty print the output." in
6696 Arg. (value & flag & info [ " pretty" ] ~doc )
@@ -91,7 +121,19 @@ let custom_header =
91121let t =
92122 lazy
93123 Term. (
94- const (fun debug enable disable pretty debuginfo noinline quiet werror c_header ->
124+ const
125+ (fun
126+ debug
127+ enable
128+ disable
129+ pretty
130+ debuginfo
131+ noinline
132+ quiet
133+ (warnings : (bool * Warning.t) list )
134+ werror
135+ c_header
136+ ->
95137 let enable = if pretty then " pretty" :: enable else enable in
96138 let enable = if debuginfo then " debuginfo" :: enable else enable in
97139 let disable = if noinline then " inline" :: disable else disable in
@@ -104,6 +146,7 @@ let t =
104146 let disable = disable_if_pretty " share" disable in
105147 { debug = { enable = debug; disable = [] }
106148 ; optim = { enable; disable }
149+ ; warnings
107150 ; quiet
108151 ; werror
109152 ; custom_header = c_header
@@ -115,6 +158,7 @@ let t =
115158 $ debuginfo
116159 $ noinline
117160 $ is_quiet
161+ $ warnings
118162 $ is_werror
119163 $ custom_header)
120164
@@ -125,5 +169,8 @@ let on_off on off t =
125169let eval t =
126170 Config.Flag. (on_off enable disable t.optim);
127171 Debug. (on_off enable disable t.debug);
128- quiet := t.quiet;
129- werror := t.werror
172+ List. iter t.warnings ~f: (function
173+ | true , w -> Warning. enable w
174+ | false , w -> Warning. disable w);
175+ Warning. quiet := t.quiet;
176+ Warning. werror := t.werror
0 commit comments