Remove keywords parameter from cli

This commit is contained in:
orbifx 2021-10-02 14:39:28 +01:00
parent 118da141a2
commit f4aedda237

View File

@ -5,29 +5,25 @@ open Logarion
module A = Logarion.Archive.Make(File_store) module A = Logarion.Archive.Make(File_store)
(* TODO: merge in lib/ so other modules can use (.e.g HTTP pull) *) (* TODO: merge in lib/ so other modules can use (.e.g HTTP pull) *)
let text_list order_opt reverse_opt field_opt authors_opt keywords_opt topics_opt = let text_list order_opt reverse_opt values_opt authors_opt topics_opt =
match A.of_path (Sys.getcwd ()) with match A.of_path (Sys.getcwd ()) with
| Error msg -> prerr_endline msg | Error msg -> prerr_endline msg
| Ok archive -> | Ok archive ->
let predicates = let predicates = A.predicate A.authored authors_opt @ A.predicate A.topics topics_opt in
A.predicate A.authored authors_opt
@ A.predicate A.keyworded keywords_opt
@ A.predicate A.topics topics_opt
in
let predicate text = List.fold_left (fun a e -> a && e text) true predicates in let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
let print_fold ~predicate fn = let print_fold ~predicate fn =
let ts = A.fold ~predicate fn String_set.empty archive in let ts = A.fold ~predicate fn String_set.empty archive in
String_set.iter (print_endline) ts String_set.iter (print_endline) ts
in in
let list_text (_t, fname) = print_endline fname in let list_text (t, fname) = print_endline (Text.short_id t ^ " " ^ fname) in
match field_opt with match values_opt with
| Some "keywords"-> print_fold ~predicate (fun a (e,_) -> (String_set.union a (Text.set "keywords" e)))
| Some "topics" -> print_fold ~predicate (fun a (e,_) -> (String_set.union a (Text.set "topics" e))) | Some "topics" -> print_fold ~predicate (fun a (e,_) -> (String_set.union a (Text.set "topics" e)))
| Some "authors" -> | Some "authors" ->
let s = A.fold ~predicate (fun a (e,_) -> Person.Set.union a e.Text.authors) Person.Set.empty archive in let s = A.fold ~predicate (fun a (e,_) -> Person.Set.union a e.Text.authors) Person.Set.empty archive in
print_endline @@ Person.Set.to_string s print_endline @@ Person.Set.to_string s
| Some x -> prerr_endline @@ "Unrecognised field: " ^ x | Some x -> prerr_endline @@ "Unrecognised field: " ^ x
| None -> match order_opt with false -> A.iter ~predicate list_text archive | None -> match order_opt with
| false -> A.iter ~predicate list_text archive
| true -> | true ->
let order = match reverse_opt with true -> A.newest | false -> A.oldest in let order = match reverse_opt with true -> A.newest | false -> A.oldest in
A.iter ~predicate ~order list_text archive A.iter ~predicate ~order list_text archive
@ -35,11 +31,10 @@ let text_list order_opt reverse_opt field_opt authors_opt keywords_opt topics_op
let list_term = let list_term =
let time = Arg.(value & flag & info ["t"] ~doc:"Sort by time, newest first") in let time = Arg.(value & flag & info ["t"] ~doc:"Sort by time, newest first") in
let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in
let field = Arg.(value & opt (some string) None & info ["f"; "field"] ~docv:"FIELD" ~doc:"what to list") in let values = Arg.(value & opt (some string) None & info ["values"] ~docv:"HEADER-FIELD" ~doc:"unique values for header field") in
let authors = Arg.(value & opt (some string) None & info ["a"; "authors"] ~docv:"AUTHORS" ~doc:"texts with authors") in let authed = Arg.(value & opt (some string) None & info ["authored"] ~docv:"AUTHORS" ~doc:"texts by authors") in
let keywords= Arg.(value & opt (some string) None & info ["k"; "keywords"] ~docv:"KEYWORDS" ~doc:"texts with keywords") in
let topics = Arg.(value & opt (some string) None & info ["topics"] ~docv:"TOPICS" ~doc:"texts with topics") in let topics = Arg.(value & opt (some string) None & info ["topics"] ~docv:"TOPICS" ~doc:"texts with topics") in
Term.(const text_list $ time $ reverse $ field $ authors $ keywords $ topics), Term.(const text_list $ time $ reverse $ values $ authed $ topics),
Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION"; `P "List texts" ] Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION"; `P "List texts" ]
let print_last () = let print_last () =