37 lines
1.5 KiB
OCaml
37 lines
1.5 KiB
OCaml
let predicate fn opt = Option.(to_list @@ map fn opt)
|
|
|
|
let authored query_string =
|
|
let q = Person.Set.of_query @@ String_set.query query_string in
|
|
fun n -> Person.Set.predicate q n.Text.authors
|
|
|
|
let ided query_string =
|
|
let len = String.length query_string in
|
|
fun n ->
|
|
try String.sub n.Text.id 0 len = query_string
|
|
with Invalid_argument _ -> false
|
|
|
|
let keyworded query_string =
|
|
let q = String_set.query query_string in
|
|
fun n -> String_set.(predicate q (Text.set "Keywords" n))
|
|
|
|
let topics query_string =
|
|
let q = String_set.query query_string in
|
|
fun n -> String_set.(predicate q (Text.set "Topics" n))
|
|
|
|
let apply_sys_util env def_env r order_opt reverse_opt number_opt authors_opt topics_opt id_opt =
|
|
let predicates = if id_opt <> "" then [ ided id_opt ] else []
|
|
@ predicate authored authors_opt
|
|
@ predicate topics topics_opt in
|
|
let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
|
|
let util = try Sys.getenv env with Not_found -> def_env in
|
|
let print_text acc (_t, fnames) = Printf.sprintf "%s %s" acc (List.hd fnames) in
|
|
let paths = match order_opt with
|
|
| false -> File_store.fold ~r ~predicate print_text ""
|
|
| true ->
|
|
let order = match reverse_opt with true -> File_store.newest | false -> File_store.oldest in
|
|
match number_opt with
|
|
| Some number -> File_store.fold ~r ~predicate ~order ~number print_text ""
|
|
| None -> File_store.fold ~r ~predicate ~order print_text ""
|
|
in if paths = "" then ()
|
|
else (ignore @@ Sys.command @@ Printf.sprintf "%s %s" util paths)
|