···4040 let kind = "option name" in
4141 Cmdliner_base.err_multi_def ~kind name Cmdliner_info.Arg.doc a a'
42424343-module Amap = Cmdliner_info.Arg.Map
4444-4545-type arg = (* unconverted argument data as found on the command line. *)
4646-| O of (int * string * (string option)) list (* (pos, name, value) of opt. *)
4747-| P of string list
4343+type arg = Cmdliner_info.Cline.arg
4444+type t = Cmdliner_info.Cline.t
48454949-type t = arg Amap.t (* command line, maps arg_infos to arg value. *)
4646+let get_arg cline a : arg =
4747+ try Cmdliner_info.Arg.Map.find a cline with Not_found -> assert false
50485151-let get_arg cl a = try Amap.find a cl with Not_found -> assert false
5252-let opt_arg cl a = match get_arg cl a with O l -> l | _ -> assert false
5353-let pos_arg cl a = match get_arg cl a with P l -> l | _ -> assert false
5454-let actual_args cl a = match get_arg cl a with
4949+let opt_arg cline a = match get_arg cline a with O l -> l | _ -> assert false
5050+let pos_arg cline a = match get_arg cline a with P l -> l | _ -> assert false
5151+let actual_args cline a = match get_arg cline a with
5552| P args -> args
5653| O l ->
5754 let extract_args (_pos, name, value) =
···6360 (* from [args] returns a trie mapping the names of optional arguments to
6461 their arg_info, a list with all arg_info for positional arguments and
6562 a cmdline mapping each arg_info to an empty [arg]. *)
6666- let rec loop optidx posidx cl = function
6767- | [] -> optidx, posidx, cl
6363+ let rec loop optidx posidx cline = function
6464+ | [] -> optidx, posidx, cline
6865 | a :: l ->
6966 match Cmdliner_info.Arg.is_pos a with
7070- | true -> loop optidx (a :: posidx) (Amap.add a (P []) cl) l
6767+ | true ->
6868+ let cline = Cmdliner_info.Arg.Map.add a (P [] : arg) cline in
6969+ loop optidx (a :: posidx) cline l
7170 | false ->
7271 let add t name = match Cmdliner_trie.add t name a with
7372 | `New t -> t
···7574 in
7675 let names = Cmdliner_info.Arg.opt_names a in
7776 let optidx = List.fold_left add optidx names in
7878- loop optidx posidx (Amap.add a (O []) cl) l
7777+ let cline = Cmdliner_info.Arg.Map.add a (O [] : arg) cline in
7878+ loop optidx posidx cline l
7979 in
8080- loop Cmdliner_trie.empty [] Amap.empty (Cmdliner_info.Arg.Set.elements args)
8080+ let cline = Cmdliner_info.Arg.Map.empty in
8181+ loop Cmdliner_trie.empty [] cline (Cmdliner_info.Arg.Set.elements args)
81828283(* Optional argument parsing *)
8384···178179 comp_request ~prefix:name Opt_name
179180 end
180181181181-let parse_opt_args ~peek_opts ~legacy_prefixes ~for_completion optidx cl args =
182182+let parse_opt_args
183183+ ~peek_opts ~legacy_prefixes ~for_completion optidx cline args
184184+ =
182185 (* returns an updated [cl] cmdline according to the options found in [args]
183186 with the trie index [optidx]. Positional arguments are returned in order
184187 in a list. *)
185185- let rec loop errs k cl pargs = function
186186- | [] -> List.rev errs, cl, false, List.rev pargs
187187- | "--" :: args -> List.rev errs, cl, true, (List.rev_append pargs args)
188188+ let rec loop errs k cline pargs = function
189189+ | [] -> List.rev errs, cline, false, List.rev pargs
190190+ | "--" :: args -> List.rev errs, cline, true, (List.rev_append pargs args)
188191 | s :: args ->
189192 let do_parse =
190193 is_opt s &&
···192195 if not (has_complete_prefix s) then true else
193196 is_opt_to_complete s)
194197 in
195195- if not do_parse then loop errs (k + 1) cl (s :: pargs) args else
198198+ if not do_parse then loop errs (k + 1) cline (s :: pargs) args else
196199 let name, value, is_completion = parse_opt_arg s in
197200 match Cmdliner_trie.find ~legacy_prefixes optidx name with
198201 | Ok arg_info ->
···201204 then try_complete_opt_value arg_info name value args
202205 else parse_opt_value ~for_completion arg_info name value args
203206 in
204204- let arg = O ((k, name, value) :: opt_arg cl arg_info) in
205205- loop errs (k + 1) (Amap.add arg_info arg cl) pargs args
207207+ let arg : arg = O ((k, name, value) :: opt_arg cline arg_info) in
208208+ let cline = Cmdliner_info.Arg.Map.add arg_info arg cline in
209209+ loop errs (k + 1) cline pargs args
206210 | Error `Not_found when for_completion ->
207211 if not is_completion
208208- then (* XXX unclear *) loop errs (k + 1) cl (s :: pargs) args else
212212+ then (* XXX unclear *) loop errs (k + 1) cline (s :: pargs) args else
209213 let prefix = name ^ Option.value ~default:"" value in
210214 comp_request ~prefix Opt_name
211215 | Error `Not_found when peek_opts ->
212212- loop errs (k + 1) cl pargs args
216216+ loop errs (k + 1) cline pargs args
213217 | Error `Not_found ->
214218 let hints = hint_matching_opt optidx s in
215219 let err = Cmdliner_base.err_unknown ~kind:"option" ~hints name in
216216- loop (err :: errs) (k + 1) cl pargs args
220220+ loop (err :: errs) (k + 1) cline pargs args
217221 | Error `Ambiguous (* Only on legacy prefixes *) ->
218222 let ambs = Cmdliner_trie.ambiguities optidx name in
219223 let ambs = List.sort compare ambs in
220224 let err = Cmdliner_base.err_ambiguous ~kind:"option" name ~ambs in
221221- loop (err :: errs) (k + 1) cl pargs args
225225+ loop (err :: errs) (k + 1) cline pargs args
222226 in
223223- let errs, cl, has_dashdash, pargs = loop [] 0 cl [] args in
224224- if errs = [] then Ok (cl, has_dashdash, pargs) else
227227+ let errs, cline, has_dashdash, pargs = loop [] 0 cline [] args in
228228+ if errs = [] then Ok (cline, has_dashdash, pargs) else
225229 let err = String.concat "\n" errs in
226226- Error (err, cl, has_dashdash, pargs)
230230+ Error (err, cline, has_dashdash, pargs)
227231228232let take_range ~for_completion start stop l =
229233 let rec loop i acc = function
···237241 in
238242 loop 0 [] l
239243240240-let process_pos_args ~for_completion posidx cl ~has_dashdash pargs =
244244+let process_pos_args ~for_completion posidx cline ~has_dashdash pargs =
241245 (* returns an updated [cl] cmdline in which each positional arg mentioned
242246 in the list index posidx, is given a value according the list
243247 of positional arguments values [pargs]. *)
244248 if pargs = [] then
245249 let misses = List.filter Cmdliner_info.Arg.is_req posidx in
246246- if misses = [] then Ok cl else
247247- Error (Cmdliner_msg.err_pos_misses misses, cl)
250250+ if misses = [] then Ok cline else
251251+ Error (Cmdliner_msg.err_pos_misses misses, cline)
248252 else
249253 let last = List.length pargs - 1 in
250254 let pos rev k = if rev then last - k else k in
251251- let rec loop misses cl max_spec = function
252252- | [] -> misses, cl, max_spec
255255+ let rec loop misses cline max_spec = function
256256+ | [] -> misses, cline, max_spec
253257 | a :: al ->
254258 let apos = Cmdliner_info.Arg.pos_kind a in
255259 let rev = Cmdliner_info.Arg.pos_rev apos in
···267271 comp_request ~after_dashdash:has_dashdash ~prefix kind
268272 in
269273 let max_spec = max stop max_spec in
270270- let cl = Amap.add a (P args) cl in
274274+ let cline = Cmdliner_info.Arg.Map.add a (P args : arg) cline in
271275 let misses = match Cmdliner_info.Arg.is_req a && args = [] with
272276 | true -> a :: misses
273277 | false -> misses
274278 in
275275- loop misses cl max_spec al
279279+ loop misses cline max_spec al
276280 in
277277- let misses, cl, max_spec = loop [] cl (-1) posidx in
281281+ let misses, cline, max_spec = loop [] cline (-1) posidx in
278282 let consume_excess () =
279283 match take_range ~for_completion (max_spec + 1) last pargs with
280284 | `Range args -> args
···283287 in
284288 if misses <> [] then begin
285289 let _ : string list = consume_excess () in
286286- Error (Cmdliner_msg.err_pos_misses misses, cl)
290290+ Error (Cmdliner_msg.err_pos_misses misses, cline)
287291 end else
288288- if last <= max_spec then Ok cl else
289289- Error (Cmdliner_msg.err_pos_excess (consume_excess ()), cl)
292292+ if last <= max_spec then Ok cline else
293293+ Error (Cmdliner_msg.err_pos_excess (consume_excess ()), cline)
290294291295let create ?(peek_opts = false) ~legacy_prefixes ~for_completion al args =
292296 try
293293- let optidx, posidx, cl = arg_info_indexes al in
297297+ let optidx, posidx, cline = arg_info_indexes al in
294298 let r =
295295- parse_opt_args ~for_completion ~peek_opts ~legacy_prefixes optidx cl args
299299+ parse_opt_args
300300+ ~for_completion ~peek_opts ~legacy_prefixes optidx cline args
296301 in
297302 match r with
298298- | Ok (cl, has_dashdash, _) when peek_opts -> `Ok cl
299299- | Ok (cl, has_dashdash, pargs) ->
303303+ | Ok (cline, has_dashdash, _) when peek_opts -> `Ok cline
304304+ | Ok (cline, has_dashdash, pargs) ->
300305 let r =
301301- process_pos_args ~for_completion posidx cl ~has_dashdash pargs
306306+ process_pos_args ~for_completion posidx cline ~has_dashdash pargs
302307 in
303308 if not for_completion
304309 then (match r with Ok v -> `Ok v | Error v -> `Error v)
···314319 | Some prefix ->
315320 comp_request ~after_dashdash:has_dashdash ~prefix Opt_name
316321 end
317317- | Error (errs, cl, has_dashdash, pargs) ->
322322+ | Error (errs, cline, has_dashdash, pargs) ->
318323 let _ : _ result =
319319- process_pos_args ~for_completion posidx cl ~has_dashdash pargs
324324+ process_pos_args ~for_completion posidx cline ~has_dashdash pargs
320325 in
321321- `Error (errs, cl)
326326+ `Error (errs, cline)
322327 with Completion_requested c -> `Complete c
323328324329(* Deprecations *)
325330326331type deprecated = Cmdliner_info.Arg.t * arg
327332328328-let deprecated ~env cl =
333333+let deprecated ~env cline =
329334 let add ~env info arg acc =
330330- let deprecation_invoked = match arg with
335335+ let deprecation_invoked = match (arg : arg) with
331336 | O [] | P [] -> (* nothing on the cli for the argument *)
332337 begin match Cmdliner_info.Arg.env info with
333338 | None -> false
···340345 in
341346 if deprecation_invoked then (info, arg) :: acc else acc
342347 in
343343- List.rev (Amap.fold (add ~env) cl [])
348348+ List.rev (Cmdliner_info.Arg.Map.fold (add ~env) cline [])
344349345350let pp_deprecated ~subst ppf (info, arg) =
346351 let open Cmdliner_base in
347352 let plural l = if List.length l > 1 then "s" else "" in
348353 let subst = Cmdliner_info.Arg.doclang_subst ~subst info in
349349- match arg with
354354+ match (arg : arg) with
350355 | O [] | P [] ->
351356 let env = Option.get (Cmdliner_info.Arg.env info) in
352357 let msg = Cmdliner_info.Env.styled_deprecated ~errs:ppf ~subst env in
+11
vendor/opam/cmdliner/src/cmdliner_info.ml
···345345 let escaped_name i = Cmdliner_manpage.escape i.name
346346end
347347348348+(* Command lines *)
349349+350350+module Cline = struct
351351+ type arg = (* unconverted argument data as found on the command line. *)
352352+ | O of (int * string * (string option)) list (* (pos, name, value) of opt. *)
353353+ | P of string list
354354+355355+ type t = arg Arg.Map.t (* command line, maps arg_infos to arg value. *)
356356+end
357357+358358+348359(* Evaluation *)
349360350361module Eval = struct
+10
vendor/opam/cmdliner/src/cmdliner_info.mli
···212212 errs:Format.formatter -> subst:Cmdliner_manpage.subst -> t -> string
213213end
214214215215+216216+(** Untyped command line parses. *)
217217+module Cline : sig
218218+ type arg = (* unconverted argument data as found on the command line. *)
219219+ | O of (int * string * (string option)) list (* (pos, name, value) of opt. *)
220220+ | P of string list
221221+222222+ type t = arg Arg.Map.t (* command line, maps arg_infos to arg value. *)
223223+end
224224+215225(** Evaluation. *)
216226module Eval : sig
217227 type t