···98989999let flag a =
100100 if Cmdliner_def.Arg_info.is_pos a then invalid_arg err_not_opt else
101101- let convert ei cl = match Cmdliner_cline.opt_arg cl a with
101101+ let convert ei cl = match Cmdliner_def.Cline.get_opt_arg cl a with
102102 | [] -> try_env ei a env_bool_parse ~absent:false
103103 | [_, _, None] -> Ok true
104104 | [_, f, Some v] -> parse_error (Cmdliner_msg.err_flag_value f v)
···110110let flag_all a =
111111 if Cmdliner_def.Arg_info.is_pos a then invalid_arg err_not_opt else
112112 let a = Cmdliner_def.Arg_info.make_all_opts a in
113113- let convert ei cl = match Cmdliner_cline.opt_arg cl a with
113113+ let convert ei cl = match Cmdliner_def.Cline.get_opt_arg cl a with
114114 | [] -> try_env ei a (parse_to_list env_bool_parse) ~absent:[]
115115 | l ->
116116 try
···127127 let convert _ cl =
128128 let rec aux fv = function
129129 | (v, a) :: rest ->
130130- begin match Cmdliner_cline.opt_arg cl a with
130130+ begin match Cmdliner_def.Cline.get_opt_arg cl a with
131131 | [] -> aux fv rest
132132 | [_, f, None] ->
133133 begin match fv with
···151151 let convert _ cl =
152152 let rec aux acc = function
153153 | (fv, a) :: rest ->
154154- begin match Cmdliner_cline.opt_arg cl a with
154154+ begin match Cmdliner_def.Cline.get_opt_arg cl a with
155155 | [] -> aux acc rest
156156 | l ->
157157 let fval (k, f, v) = match v with
···188188 | "" -> Conv.docv conv | docv -> docv
189189 in
190190 let a = Cmdliner_def.Arg_info.make_opt ~docv ~absent ~kind a in
191191- let convert ei cl = match Cmdliner_cline.opt_arg cl a with
191191+ let convert ei cl = match Cmdliner_def.Cline.get_opt_arg cl a with
192192 | [] -> try_env ei a (Conv.parser conv) ~absent:v
193193 | [_, f, Some v] ->
194194 (try Ok (parse_opt_value (Conv.parser conv) f v) with
···217217 | "" -> Conv.docv conv | docv -> docv
218218 in
219219 let a = Cmdliner_def.Arg_info.make_opt_all ~docv ~absent ~kind a in
220220- let convert ei cl = match Cmdliner_cline.opt_arg cl a with
220220+ let convert ei cl = match Cmdliner_def.Cline.get_opt_arg cl a with
221221 | [] -> try_env ei a (parse_to_list (Conv.parser conv)) ~absent:v
222222 | l ->
223223 let parse (k, f, v) = match v with
···249249 | "" -> Conv.docv conv | docv -> docv
250250 in
251251 let a = Cmdliner_def.Arg_info.make_pos_abs ~docv ~absent ~pos a in
252252- let convert ei cl = match Cmdliner_cline.pos_arg cl a with
252252+ let convert ei cl = match Cmdliner_def.Cline.get_pos_arg cl a with
253253 | [] -> try_env ei a (Conv.parser conv) ~absent:v
254254 | [v] ->
255255 (try Ok (parse_pos_value (Conv.parser conv) a v) with
···264264 | "" -> Conv.docv conv | docv -> docv
265265 in
266266 let a = Cmdliner_def.Arg_info.make_pos ~docv ~pos a in
267267- let convert ei cl = match Cmdliner_cline.pos_arg cl a with
267267+ let convert ei cl = match Cmdliner_def.Cline.get_pos_arg cl a with
268268 | [] -> try_env ei a (parse_to_list (Conv.parser conv)) ~absent:v
269269 | l ->
270270 try Ok (List.rev (List.rev_map (parse_pos_value (Conv.parser conv) a) l))
+34-94
vendor/opam/cmdliner/src/cmdliner_cline.ml
···5566(* A command line stores pre-parsed information about the command
77 line's arguments in a more structured way. Given the
88- Cmdliner_info.arg values mentioned in a term and Sys.argv
99- (without exec name) we parse the command line into a map of
1010- Cmdliner_info.arg values to [arg] values (see below). This map is used by
1111- the term's closures to retrieve and convert command line arguments
1212- (see the Cmdliner_arg module). *)
88+ Cmdliner_def.Arg_info.t values mentioned in a term and Sys.argv
99+ (without exec name) we parse the command line into
1010+ [Cmdliner_def.Cline.t] which is map of [Cmdliner_def.Arg_info.t]
1111+ values to [Cmdliner_def.Cline.arg] values. This map is used by the
1212+ term's closures to retrieve and convert command line arguments (see
1313+ the [Cmdliner_arg] module). *)
13141415(* Completion *)
1516···36373738(* Command lines *)
38393939-let err_multi_opt_name_def name a a' =
4040- let kind = "option name" in
4141- Cmdliner_base.err_multi_def ~kind name Cmdliner_def.Arg_info.doc a a'
4242-4343-type arg = Cmdliner_def.Cline.arg
4444-type t = Cmdliner_def.Cline.t
4545-4646-let get_arg cline a : arg =
4747- try Cmdliner_def.Arg_info.Map.find a cline with Not_found -> assert false
4848-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
5252-| P args -> args
5353-| O l ->
5454- let extract_args (_pos, name, value) =
5555- name :: (match value with None -> [] | Some v -> [v])
5656- in
5757- List.concat (List.map extract_args l)
4040+let err_multi_opt_name_def name arg_info arg_info' =
4141+ Cmdliner_base.err_multi_def ~kind:"option name" name
4242+ Cmdliner_def.Arg_info.doc arg_info arg_info'
58435959-let arg_info_indexes args =
4444+let arg_info_indexes arg_infos =
6045 (* from [args] returns a trie mapping the names of optional arguments to
6146 their arg_info, a list with all arg_info for positional arguments and
6247 a cmdline mapping each arg_info to an empty [arg]. *)
6348 let rec loop optidx posidx cline = function
6449 | [] -> optidx, posidx, cline
6565- | a :: l ->
6666- match Cmdliner_def.Arg_info.is_pos a with
5050+ | arg_info :: l ->
5151+ match Cmdliner_def.Arg_info.is_pos arg_info with
6752 | true ->
6868- let cline = Cmdliner_def.Arg_info.Map.add a (P [] : arg) cline in
6969- loop optidx (a :: posidx) cline l
5353+ let cline = Cmdliner_def.Cline.add arg_info (P []) cline in
5454+ loop optidx (arg_info :: posidx) cline l
7055 | false ->
7171- let add t name = match Cmdliner_trie.add t name a with
5656+ let add t name = match Cmdliner_trie.add t name arg_info with
7257 | `New t -> t
7373- | `Replaced (a', _) -> invalid_arg (err_multi_opt_name_def name a a')
5858+ | `Replaced (a', _) ->
5959+ invalid_arg (err_multi_opt_name_def name arg_info a')
7460 in
7575- let names = Cmdliner_def.Arg_info.opt_names a in
6161+ let names = Cmdliner_def.Arg_info.opt_names arg_info in
7662 let optidx = List.fold_left add optidx names in
7777- let cline = Cmdliner_def.Arg_info.Map.add a (O [] : arg) cline in
6363+ let cline = Cmdliner_def.Cline.add arg_info (O []) cline in
7864 loop optidx posidx cline l
7965 in
8080- let cline = Cmdliner_def.Arg_info.Map.empty in
8181- loop Cmdliner_trie.empty [] cline (Cmdliner_def.Arg_info.Set.elements args)
6666+ let cline = Cmdliner_def.Cline.empty in
6767+ let arg_infos = Cmdliner_def.Arg_info.Set.elements arg_infos in
6868+ loop Cmdliner_trie.empty [] cline arg_infos
82698370(* Optional argument parsing *)
8471···10794 with Not_found -> s, None, is_completion
1089510996let hint_matching_opt optidx s =
110110- (* hint options that could match [s] in [optidx]. FIXME explain this is
111111- a bit obscure. *)
9797+ (* hint option names that could match [s] in [optidx]. *)
11298 if String.length s <= 2 then [] else
11399 let short_opt, long_opt =
114100 if s.[1] <> '-'
···204190 then try_complete_opt_value cline arg_info name value args
205191 else parse_opt_value ~for_completion cline arg_info name value args
206192 in
207207- let arg : arg = O ((k, name, value) :: opt_arg cline arg_info) in
208208- let cline = Cmdliner_def.Arg_info.Map.add arg_info arg cline in
193193+ let arg : Cmdliner_def.Cline.arg =
194194+ O ((k, name, value) ::
195195+ Cmdliner_def.Cline.get_opt_arg cline arg_info)
196196+ in
197197+ let cline = Cmdliner_def.Cline.add arg_info arg cline in
209198 loop errs (k + 1) cline pargs args
210199 | Error `Not_found when for_completion ->
211200 if not is_completion
···266255 | Some n -> pos rev (Cmdliner_def.Arg_info.pos_start apos + n - 1)
267256 in
268257 let start, stop = if rev then stop, start else start, stop in
269269- let args =
270270- match take_range ~for_completion start stop pargs with
271271- | `Range args -> args
272272- | `Complete token ->
273273- let kind = Cmdliner_def.Complete.Opt_name_or_pos_value a in
274274- comp_request ~after_dashdash:has_dashdash cline ~token kind
258258+ let args = match take_range ~for_completion start stop pargs with
259259+ | `Range args -> args
260260+ | `Complete token ->
261261+ let kind = Cmdliner_def.Complete.Opt_name_or_pos_value a in
262262+ comp_request ~after_dashdash:has_dashdash cline ~token kind
275263 in
276264 let max_spec = max stop max_spec in
277277- let cline = Cmdliner_def.Arg_info.Map.add a (P args : arg) cline in
265265+ let cline = Cmdliner_def.Cline.add a (P args) cline in
278266 let misses = match Cmdliner_def.Arg_info.is_req a && args = [] with
279267 | true -> a :: misses
280268 | false -> misses
···329317 in
330318 `Error (errs, cline)
331319 with Completion_requested c -> `Complete c
332332-333333-(* Deprecations *)
334334-335335-type deprecated = Cmdliner_def.Arg_info.t * arg
336336-337337-let deprecated ~env cline =
338338- let add ~env info arg acc =
339339- let deprecation_invoked = match (arg : arg) with
340340- | O [] | P [] -> (* nothing on the cli for the argument *)
341341- begin match Cmdliner_def.Arg_info.env info with
342342- | None -> false
343343- | Some ienv ->
344344- (* the parse uses the env var if defined which may be deprecated *)
345345- Option.is_some (Cmdliner_def.Env.info_deprecated ienv) &&
346346- Option.is_some (env (Cmdliner_def.Env.info_var ienv))
347347- end
348348- | _ -> Option.is_some (Cmdliner_def.Arg_info.deprecated info)
349349- in
350350- if deprecation_invoked then (info, arg) :: acc else acc
351351- in
352352- List.rev (Cmdliner_def.Arg_info.Map.fold (add ~env) cline [])
353353-354354-let pp_deprecated ~subst ppf (info, arg) =
355355- let open Cmdliner_base in
356356- let plural l = if List.length l > 1 then "s" else "" in
357357- let subst = Cmdliner_def.Arg_info.doclang_subst ~subst info in
358358- match (arg : arg) with
359359- | O [] | P [] ->
360360- let env = Option.get (Cmdliner_def.Arg_info.env info) in
361361- let msg = Cmdliner_def.Env.styled_deprecated ~errs:ppf ~subst env in
362362- Fmt.pf ppf "@[%a @[environment variable %a: %a@]@]"
363363- Fmt.deprecated () Fmt.code (Cmdliner_def.Env.info_var env)
364364- Fmt.styled_text msg
365365- | O os ->
366366- let plural = plural os in
367367- let names = List.map (fun (_, n, _) -> n) os in
368368- let msg = Cmdliner_def.Arg_info.styled_deprecated ~errs:ppf ~subst info in
369369- Fmt.pf ppf "@[%a @[option%s %a: %a@]@]"
370370- Fmt.deprecated () plural Fmt.(list ~sep:sp code_or_quote) names
371371- Fmt.styled_text msg
372372- | P args ->
373373- let plural = plural args in
374374- let msg =
375375- Cmdliner_def.Arg_info.styled_deprecated ~errs:ppf ~subst info
376376- in
377377- Fmt.pf ppf "@[%a @[argument%s %a: %a@]@]"
378378- Fmt.deprecated () plural Fmt.(list ~sep:sp code_or_quote) args
379379- Fmt.styled_text msg
+2-25
vendor/opam/cmdliner/src/cmdliner_cline.mli
···11111212(** {1:cli Command lines} *)
13131414-type t = Cmdliner_def.Cline.t
1515-1614val create :
1715 ?peek_opts:bool -> legacy_prefixes:bool -> for_completion:bool ->
1816 Cmdliner_def.Arg_info.Set.t -> string list ->
1919- [ `Ok of t
1717+ [ `Ok of Cmdliner_def.Cline.t
2018 | `Complete of Cmdliner_def.Complete.t
2121- | `Error of string * t ]
2222-2323-val opt_arg :
2424- t -> Cmdliner_def.Arg_info.t -> (int * string * (string option)) list
2525-2626-val pos_arg : t -> Cmdliner_def.Arg_info.t -> string list
2727-val actual_args : t -> Cmdliner_def.Arg_info.t -> string list
2828-(** Actual command line arguments from the command line *)
2929-3030-(** {1:deprecations Deprecations} *)
3131-3232-type deprecated
3333-(** The type for deprecation invocations. This include both environment
3434- variable deprecations and argument deprecations. *)
3535-3636-val deprecated : env:(string -> string option) -> t -> deprecated list
3737-(** [deprecated ~env cli] are the deprecated invocations that occur
3838- when parsing [cli]. *)
3939-4040-val pp_deprecated :
4141- subst:Cmdliner_manpage.subst -> deprecated Cmdliner_base.Fmt.t
4242-(** [pp_deprecated] formats deprecations. *)
1919+ | `Error of string * Cmdliner_def.Cline.t ]
+1-1
vendor/opam/cmdliner/src/cmdliner_completion.ml
···7788let cons_if b v l = if b then v :: l else l
991010-type dir =
1010+type directive =
1111| Dirs | Files | Group of string * (string * string) list
1212| Restart | Message of string
1313
+69
vendor/opam/cmdliner/src/cmdliner_def.ml
···321321 | P of string list
322322323323 type t = Arg_info.cline
324324+325325+ let empty = Arg_info.Map.empty
326326+ let add = Arg_info.Map.add
327327+ let fold = Arg_info.Map.fold
328328+ let get_arg cline a : arg =
329329+ try Arg_info.Map.find a cline with Not_found -> assert false
330330+331331+ let get_opt_arg cline a =
332332+ match get_arg cline a with O l -> l | _ -> assert false
333333+334334+ let get_pos_arg cline a =
335335+ match get_arg cline a with P l -> l | _ -> assert false
336336+337337+ let actual_args cline a = match get_arg cline a with
338338+ | P args -> args
339339+ | O l ->
340340+ let extract_args (_pos, name, value) =
341341+ name :: (match value with None -> [] | Some v -> [v])
342342+ in
343343+ List.concat (List.map extract_args l)
344344+345345+ (* Deprecations *)
346346+347347+ type deprecated = Arg_info.t * arg
348348+349349+ let deprecated ~env cline =
350350+ let add ~env info arg acc =
351351+ let deprecation_invoked = match (arg : arg) with
352352+ | O [] | P [] -> (* nothing on the cli for the argument *)
353353+ begin match Arg_info.env info with
354354+ | None -> false
355355+ | Some ienv ->
356356+ (* the parse uses the env var if defined which may be
357357+ deprecated *)
358358+ Option.is_some (Env.info_deprecated ienv) &&
359359+ Option.is_some (env (Env.info_var ienv))
360360+ end
361361+ | _ -> Option.is_some (Arg_info.deprecated info)
362362+ in
363363+ if deprecation_invoked then (info, arg) :: acc else acc
364364+ in
365365+ List.rev (fold (add ~env) cline [])
366366+367367+ let pp_deprecated ~subst ppf (info, arg) =
368368+ let open Cmdliner_base in
369369+ let plural l = if List.length l > 1 then "s" else "" in
370370+ let subst = Arg_info.doclang_subst ~subst info in
371371+ match (arg : arg) with
372372+ | O [] | P [] ->
373373+ let env = Option.get (Arg_info.env info) in
374374+ let msg = Env.styled_deprecated ~errs:ppf ~subst env in
375375+ Fmt.pf ppf "@[%a @[environment variable %a: %a@]@]"
376376+ Fmt.deprecated () Fmt.code (Env.info_var env)
377377+ Fmt.styled_text msg
378378+ | O os ->
379379+ let plural = plural os in
380380+ let names = List.map (fun (_, n, _) -> n) os in
381381+ let msg = Arg_info.styled_deprecated ~errs:ppf ~subst info in
382382+ Fmt.pf ppf "@[%a @[option%s %a: %a@]@]"
383383+ Fmt.deprecated () plural Fmt.(list ~sep:sp code_or_quote) names
384384+ Fmt.styled_text msg
385385+ | P args ->
386386+ let plural = plural args in
387387+ let msg =
388388+ Arg_info.styled_deprecated ~errs:ppf ~subst info
389389+ in
390390+ Fmt.pf ppf "@[%a @[argument%s %a: %a@]@]"
391391+ Fmt.deprecated () plural Fmt.(list ~sep:sp code_or_quote) args
392392+ Fmt.styled_text msg
324393end
325394326395(* Evaluation *)
+25-3
vendor/opam/cmdliner/src/cmdliner_def.mli
···117117 val styled_doc :
118118 errs:Format.formatter -> subst:Cmdliner_manpage.subst -> t -> string
119119120120- module Map : Map.S with type key := t
121121-122120 type 'a conv
123121 type e_conv = Conv : 'a conv -> e_conv
124122···178176 | P of string list (** *)
179177 (** Unconverted argument data as found on the command line. *)
180178181181- type t = arg Arg_info.Map.t (* command line, maps arg_infos to arg value. *)
179179+ type t (* command line, maps arg_infos to arg value. *)
180180+ val empty : t
181181+ val add : Arg_info.t -> arg -> t -> t
182182+ val get_arg : t -> Arg_info.t -> arg
183183+ val get_opt_arg : t -> Arg_info.t -> (int * string * (string option)) list
184184+ val get_pos_arg : t -> Arg_info.t -> string list
185185+ val actual_args : t -> Arg_info.t -> string list
186186+ (** Actual command line arguments from the command line *)
187187+188188+ val fold : (Arg_info.t -> arg -> 'b -> 'b) -> t -> 'b -> 'b
189189+190190+ (** {1:deprecations Deprecations} *)
191191+192192+ type deprecated
193193+ (** The type for deprecation invocations. This include both environment
194194+ variable deprecations and argument deprecations. *)
195195+196196+ val deprecated :
197197+ env:(string -> string option) -> t -> deprecated list
198198+ (** [deprecated ~env cli] are the deprecated invocations that occur
199199+ when parsing [cli]. *)
200200+201201+ val pp_deprecated :
202202+ subst:Cmdliner_manpage.subst -> deprecated Cmdliner_base.Fmt.t
203203+ (** [pp_deprecated] formats deprecations. *)
182204end
183205184206(** Evaluation. *)
+7-8
vendor/opam/cmdliner/src/cmdliner_eval.ml
···111111112112let do_deprecated_msgs ~env err_ppf cl eval =
113113 let cmd_info = Cmdliner_def.Eval.cmd eval in
114114- let deprecated = Cmdliner_cline.deprecated ~env cl in
114114+ let deprecated = Cmdliner_def.Cline.deprecated ~env cl in
115115 match Cmdliner_def.Cmd_info.deprecated cmd_info, deprecated with
116116 | None, [] -> ()
117117 | depr_cmd, deprs ->
···130130 Fmt.pf ppf "@[%a command %a:@[ %a@]@]"
131131 Fmt.deprecated () Fmt.code_or_quote name Fmt.styled_text msg
132132 in
133133- let pp_deprs = Fmt.list (Cmdliner_cline.pp_deprecated ~subst) in
133133+ let pp_deprs = Fmt.list (Cmdliner_def.Cline.pp_deprecated ~subst) in
134134 Fmt.pf err_ppf "@[%a @[<v>%a%a%a@]@]@."
135135 Cmdliner_msg.pp_exec_msg eval pp_cmd_msg cmd_info
136136 pp_sep () pp_deprs deprs
···175175 let kind = "command" in
176176 let err = Cmdliner_base.err_unknown ~kind ~dom ~hints arg in
177177 let try_stdopts =
178178- (* When we users writes cmd no_such_cmd --help it's
179179- better to show the unknown command error message
180180- rather than get into the help of the parent
181181- command. Otherwise one gets confused into thinking
182182- the command exists and/or annoyed not be reading
183183- the right man page. *)
178178+ (* When one writes [cmd no_such_cmd --help] it's better
179179+ to show the unknown command error message rather
180180+ than get into the help of the parent command. Otherwise
181181+ one gets confused into thinking the command exists and/or
182182+ annoyed not to be reading the right man page. *)
184183 false
185184 in
186185 ancestors, current_cmd, args, Error (`Parse (try_stdopts, err))
+1-1
vendor/opam/cmdliner/src/cmdliner_term.ml
···8282 match v ei cl with
8383 | Ok x ->
8484 let actual_args arg_info _ acc =
8585- let args = Cmdliner_cline.actual_args cl arg_info in
8585+ let args = Cmdliner_def.Cline.actual_args cl arg_info in
8686 List.rev_append args acc
8787 in
8888 let used =
+1-1
vendor/opam/cmdliner/src/cmdliner_term.mli
···1010 | `Help of Cmdliner_manpage.format * string option ]
11111212type 'a parser =
1313- Cmdliner_def.Eval.t -> Cmdliner_cline.t ->
1313+ Cmdliner_def.Eval.t -> Cmdliner_def.Cline.t ->
1414 ('a, [ `Parse of string | term_escape ]) result
1515(** Type type for command line parser. given static information about
1616 the command line and a command line to parse returns an OCaml value. *)