The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move Cmdliner_cline.t definition to Cmdliner_info (#215)

+78 -52
+57 -52
vendor/opam/cmdliner/src/cmdliner_cline.ml
··· 40 40 let kind = "option name" in 41 41 Cmdliner_base.err_multi_def ~kind name Cmdliner_info.Arg.doc a a' 42 42 43 - module Amap = Cmdliner_info.Arg.Map 44 - 45 - type arg = (* unconverted argument data as found on the command line. *) 46 - | O of (int * string * (string option)) list (* (pos, name, value) of opt. *) 47 - | P of string list 43 + type arg = Cmdliner_info.Cline.arg 44 + type t = Cmdliner_info.Cline.t 48 45 49 - type t = arg Amap.t (* command line, maps arg_infos to arg value. *) 46 + let get_arg cline a : arg = 47 + try Cmdliner_info.Arg.Map.find a cline with Not_found -> assert false 50 48 51 - let get_arg cl a = try Amap.find a cl with Not_found -> assert false 52 - let opt_arg cl a = match get_arg cl a with O l -> l | _ -> assert false 53 - let pos_arg cl a = match get_arg cl a with P l -> l | _ -> assert false 54 - let actual_args cl a = match get_arg cl a with 49 + let opt_arg cline a = match get_arg cline a with O l -> l | _ -> assert false 50 + let pos_arg cline a = match get_arg cline a with P l -> l | _ -> assert false 51 + let actual_args cline a = match get_arg cline a with 55 52 | P args -> args 56 53 | O l -> 57 54 let extract_args (_pos, name, value) = ··· 63 60 (* from [args] returns a trie mapping the names of optional arguments to 64 61 their arg_info, a list with all arg_info for positional arguments and 65 62 a cmdline mapping each arg_info to an empty [arg]. *) 66 - let rec loop optidx posidx cl = function 67 - | [] -> optidx, posidx, cl 63 + let rec loop optidx posidx cline = function 64 + | [] -> optidx, posidx, cline 68 65 | a :: l -> 69 66 match Cmdliner_info.Arg.is_pos a with 70 - | true -> loop optidx (a :: posidx) (Amap.add a (P []) cl) l 67 + | true -> 68 + let cline = Cmdliner_info.Arg.Map.add a (P [] : arg) cline in 69 + loop optidx (a :: posidx) cline l 71 70 | false -> 72 71 let add t name = match Cmdliner_trie.add t name a with 73 72 | `New t -> t ··· 75 74 in 76 75 let names = Cmdliner_info.Arg.opt_names a in 77 76 let optidx = List.fold_left add optidx names in 78 - loop optidx posidx (Amap.add a (O []) cl) l 77 + let cline = Cmdliner_info.Arg.Map.add a (O [] : arg) cline in 78 + loop optidx posidx cline l 79 79 in 80 - loop Cmdliner_trie.empty [] Amap.empty (Cmdliner_info.Arg.Set.elements args) 80 + let cline = Cmdliner_info.Arg.Map.empty in 81 + loop Cmdliner_trie.empty [] cline (Cmdliner_info.Arg.Set.elements args) 81 82 82 83 (* Optional argument parsing *) 83 84 ··· 178 179 comp_request ~prefix:name Opt_name 179 180 end 180 181 181 - let parse_opt_args ~peek_opts ~legacy_prefixes ~for_completion optidx cl args = 182 + let parse_opt_args 183 + ~peek_opts ~legacy_prefixes ~for_completion optidx cline args 184 + = 182 185 (* returns an updated [cl] cmdline according to the options found in [args] 183 186 with the trie index [optidx]. Positional arguments are returned in order 184 187 in a list. *) 185 - let rec loop errs k cl pargs = function 186 - | [] -> List.rev errs, cl, false, List.rev pargs 187 - | "--" :: args -> List.rev errs, cl, true, (List.rev_append pargs args) 188 + let rec loop errs k cline pargs = function 189 + | [] -> List.rev errs, cline, false, List.rev pargs 190 + | "--" :: args -> List.rev errs, cline, true, (List.rev_append pargs args) 188 191 | s :: args -> 189 192 let do_parse = 190 193 is_opt s && ··· 192 195 if not (has_complete_prefix s) then true else 193 196 is_opt_to_complete s) 194 197 in 195 - if not do_parse then loop errs (k + 1) cl (s :: pargs) args else 198 + if not do_parse then loop errs (k + 1) cline (s :: pargs) args else 196 199 let name, value, is_completion = parse_opt_arg s in 197 200 match Cmdliner_trie.find ~legacy_prefixes optidx name with 198 201 | Ok arg_info -> ··· 201 204 then try_complete_opt_value arg_info name value args 202 205 else parse_opt_value ~for_completion arg_info name value args 203 206 in 204 - let arg = O ((k, name, value) :: opt_arg cl arg_info) in 205 - loop errs (k + 1) (Amap.add arg_info arg cl) pargs args 207 + let arg : arg = O ((k, name, value) :: opt_arg cline arg_info) in 208 + let cline = Cmdliner_info.Arg.Map.add arg_info arg cline in 209 + loop errs (k + 1) cline pargs args 206 210 | Error `Not_found when for_completion -> 207 211 if not is_completion 208 - then (* XXX unclear *) loop errs (k + 1) cl (s :: pargs) args else 212 + then (* XXX unclear *) loop errs (k + 1) cline (s :: pargs) args else 209 213 let prefix = name ^ Option.value ~default:"" value in 210 214 comp_request ~prefix Opt_name 211 215 | Error `Not_found when peek_opts -> 212 - loop errs (k + 1) cl pargs args 216 + loop errs (k + 1) cline pargs args 213 217 | Error `Not_found -> 214 218 let hints = hint_matching_opt optidx s in 215 219 let err = Cmdliner_base.err_unknown ~kind:"option" ~hints name in 216 - loop (err :: errs) (k + 1) cl pargs args 220 + loop (err :: errs) (k + 1) cline pargs args 217 221 | Error `Ambiguous (* Only on legacy prefixes *) -> 218 222 let ambs = Cmdliner_trie.ambiguities optidx name in 219 223 let ambs = List.sort compare ambs in 220 224 let err = Cmdliner_base.err_ambiguous ~kind:"option" name ~ambs in 221 - loop (err :: errs) (k + 1) cl pargs args 225 + loop (err :: errs) (k + 1) cline pargs args 222 226 in 223 - let errs, cl, has_dashdash, pargs = loop [] 0 cl [] args in 224 - if errs = [] then Ok (cl, has_dashdash, pargs) else 227 + let errs, cline, has_dashdash, pargs = loop [] 0 cline [] args in 228 + if errs = [] then Ok (cline, has_dashdash, pargs) else 225 229 let err = String.concat "\n" errs in 226 - Error (err, cl, has_dashdash, pargs) 230 + Error (err, cline, has_dashdash, pargs) 227 231 228 232 let take_range ~for_completion start stop l = 229 233 let rec loop i acc = function ··· 237 241 in 238 242 loop 0 [] l 239 243 240 - let process_pos_args ~for_completion posidx cl ~has_dashdash pargs = 244 + let process_pos_args ~for_completion posidx cline ~has_dashdash pargs = 241 245 (* returns an updated [cl] cmdline in which each positional arg mentioned 242 246 in the list index posidx, is given a value according the list 243 247 of positional arguments values [pargs]. *) 244 248 if pargs = [] then 245 249 let misses = List.filter Cmdliner_info.Arg.is_req posidx in 246 - if misses = [] then Ok cl else 247 - Error (Cmdliner_msg.err_pos_misses misses, cl) 250 + if misses = [] then Ok cline else 251 + Error (Cmdliner_msg.err_pos_misses misses, cline) 248 252 else 249 253 let last = List.length pargs - 1 in 250 254 let pos rev k = if rev then last - k else k in 251 - let rec loop misses cl max_spec = function 252 - | [] -> misses, cl, max_spec 255 + let rec loop misses cline max_spec = function 256 + | [] -> misses, cline, max_spec 253 257 | a :: al -> 254 258 let apos = Cmdliner_info.Arg.pos_kind a in 255 259 let rev = Cmdliner_info.Arg.pos_rev apos in ··· 267 271 comp_request ~after_dashdash:has_dashdash ~prefix kind 268 272 in 269 273 let max_spec = max stop max_spec in 270 - let cl = Amap.add a (P args) cl in 274 + let cline = Cmdliner_info.Arg.Map.add a (P args : arg) cline in 271 275 let misses = match Cmdliner_info.Arg.is_req a && args = [] with 272 276 | true -> a :: misses 273 277 | false -> misses 274 278 in 275 - loop misses cl max_spec al 279 + loop misses cline max_spec al 276 280 in 277 - let misses, cl, max_spec = loop [] cl (-1) posidx in 281 + let misses, cline, max_spec = loop [] cline (-1) posidx in 278 282 let consume_excess () = 279 283 match take_range ~for_completion (max_spec + 1) last pargs with 280 284 | `Range args -> args ··· 283 287 in 284 288 if misses <> [] then begin 285 289 let _ : string list = consume_excess () in 286 - Error (Cmdliner_msg.err_pos_misses misses, cl) 290 + Error (Cmdliner_msg.err_pos_misses misses, cline) 287 291 end else 288 - if last <= max_spec then Ok cl else 289 - Error (Cmdliner_msg.err_pos_excess (consume_excess ()), cl) 292 + if last <= max_spec then Ok cline else 293 + Error (Cmdliner_msg.err_pos_excess (consume_excess ()), cline) 290 294 291 295 let create ?(peek_opts = false) ~legacy_prefixes ~for_completion al args = 292 296 try 293 - let optidx, posidx, cl = arg_info_indexes al in 297 + let optidx, posidx, cline = arg_info_indexes al in 294 298 let r = 295 - parse_opt_args ~for_completion ~peek_opts ~legacy_prefixes optidx cl args 299 + parse_opt_args 300 + ~for_completion ~peek_opts ~legacy_prefixes optidx cline args 296 301 in 297 302 match r with 298 - | Ok (cl, has_dashdash, _) when peek_opts -> `Ok cl 299 - | Ok (cl, has_dashdash, pargs) -> 303 + | Ok (cline, has_dashdash, _) when peek_opts -> `Ok cline 304 + | Ok (cline, has_dashdash, pargs) -> 300 305 let r = 301 - process_pos_args ~for_completion posidx cl ~has_dashdash pargs 306 + process_pos_args ~for_completion posidx cline ~has_dashdash pargs 302 307 in 303 308 if not for_completion 304 309 then (match r with Ok v -> `Ok v | Error v -> `Error v) ··· 314 319 | Some prefix -> 315 320 comp_request ~after_dashdash:has_dashdash ~prefix Opt_name 316 321 end 317 - | Error (errs, cl, has_dashdash, pargs) -> 322 + | Error (errs, cline, has_dashdash, pargs) -> 318 323 let _ : _ result = 319 - process_pos_args ~for_completion posidx cl ~has_dashdash pargs 324 + process_pos_args ~for_completion posidx cline ~has_dashdash pargs 320 325 in 321 - `Error (errs, cl) 326 + `Error (errs, cline) 322 327 with Completion_requested c -> `Complete c 323 328 324 329 (* Deprecations *) 325 330 326 331 type deprecated = Cmdliner_info.Arg.t * arg 327 332 328 - let deprecated ~env cl = 333 + let deprecated ~env cline = 329 334 let add ~env info arg acc = 330 - let deprecation_invoked = match arg with 335 + let deprecation_invoked = match (arg : arg) with 331 336 | O [] | P [] -> (* nothing on the cli for the argument *) 332 337 begin match Cmdliner_info.Arg.env info with 333 338 | None -> false ··· 340 345 in 341 346 if deprecation_invoked then (info, arg) :: acc else acc 342 347 in 343 - List.rev (Amap.fold (add ~env) cl []) 348 + List.rev (Cmdliner_info.Arg.Map.fold (add ~env) cline []) 344 349 345 350 let pp_deprecated ~subst ppf (info, arg) = 346 351 let open Cmdliner_base in 347 352 let plural l = if List.length l > 1 then "s" else "" in 348 353 let subst = Cmdliner_info.Arg.doclang_subst ~subst info in 349 - match arg with 354 + match (arg : arg) with 350 355 | O [] | P [] -> 351 356 let env = Option.get (Cmdliner_info.Arg.env info) in 352 357 let msg = Cmdliner_info.Env.styled_deprecated ~errs:ppf ~subst env in
+11
vendor/opam/cmdliner/src/cmdliner_info.ml
··· 345 345 let escaped_name i = Cmdliner_manpage.escape i.name 346 346 end 347 347 348 + (* Command lines *) 349 + 350 + module Cline = struct 351 + type arg = (* unconverted argument data as found on the command line. *) 352 + | O of (int * string * (string option)) list (* (pos, name, value) of opt. *) 353 + | P of string list 354 + 355 + type t = arg Arg.Map.t (* command line, maps arg_infos to arg value. *) 356 + end 357 + 358 + 348 359 (* Evaluation *) 349 360 350 361 module Eval = struct
+10
vendor/opam/cmdliner/src/cmdliner_info.mli
··· 212 212 errs:Format.formatter -> subst:Cmdliner_manpage.subst -> t -> string 213 213 end 214 214 215 + 216 + (** Untyped command line parses. *) 217 + module Cline : sig 218 + type arg = (* unconverted argument data as found on the command line. *) 219 + | O of (int * string * (string option)) list (* (pos, name, value) of opt. *) 220 + | P of string list 221 + 222 + type t = arg Arg.Map.t (* command line, maps arg_infos to arg value. *) 223 + end 224 + 215 225 (** Evaluation. *) 216 226 module Eval : sig 217 227 type t