Skip to content

Commit

Permalink
show: don't obligate to have the colon on fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Jun 13, 2019
1 parent fc1f000 commit de9fed2
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/client/opamListCommand.ml
Expand Up @@ -432,24 +432,19 @@ let field_names = [
]

let string_of_field = function
| Field s -> s^":"
| Field s -> s
| f -> List.assoc f field_names

let field_of_string =
let names_fields = List.map (fun (a,b) -> b, a) field_names in
let opam_fields = List.map fst OpamFile.OPAM.fields in
fun s ->
if OpamStd.String.ends_with ~suffix:":" s then
Field (OpamStd.String.remove_suffix ~suffix:":" s)
else
try List.assoc s names_fields
with Not_found ->
OpamConsole.error_and_exit `Bad_arguments
"No printer for %S%s" s
(if not (OpamStd.String.ends_with ~suffix:":" s) &&
List.mem_assoc s (OpamFile.OPAM.fields)
then Printf.sprintf ". Did you mean the opam field \"%s:\" \
(with a colon)?" s
else "")
match List.find_opt (fun x -> s = x || s = x^":") opam_fields with
| Some field -> Field field
| None ->
try List.assoc s names_fields
with Not_found ->
OpamConsole.error_and_exit `Bad_arguments "No printer for %S" s

let version_color st nv =
let installed = (* (in any switch) *)
Expand Down

0 comments on commit de9fed2

Please sign in to comment.