[9] | 1 | open Logarion
|
---|
| 2 | module FS = File_store
|
---|
| 3 | module A = Archive
|
---|
| 4 |
|
---|
| 5 | let print r order_opt reverse_opt number_opt authors_opt topics_opt id_opt =
|
---|
| 6 | let predicates = if id_opt <> "" then [ A.ided id_opt ] else []
|
---|
| 7 | @ A.predicate A.authored authors_opt
|
---|
| 8 | @ A.predicate A.topics topics_opt in
|
---|
| 9 | let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
|
---|
| 10 | let pager = try Sys.getenv "PAGER" with Not_found -> "less" in
|
---|
| 11 | let print_text acc (_t, fnames) = Printf.sprintf "%s %s" acc (List.hd fnames) in
|
---|
| 12 | let paths = match order_opt with
|
---|
| 13 | | false -> FS.fold ~r ~predicate print_text ""
|
---|
| 14 | | true ->
|
---|
| 15 | let order = match reverse_opt with true -> FS.newest | false -> FS.oldest in
|
---|
| 16 | match number_opt with
|
---|
| 17 | | Some number -> FS.fold ~r ~predicate ~order ~number print_text ""
|
---|
| 18 | | None -> FS.fold ~r ~predicate ~order print_text ""
|
---|
| 19 | in if paths = "" then ()
|
---|
| 20 | else (ignore @@ Sys.command @@ Printf.sprintf "%s %s" pager paths)
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | open Cmdliner
|
---|
| 24 | let term =
|
---|
| 25 | let id = Arg.(value & pos 0 string "" & info [] ~docv:"text ID") in
|
---|
| 26 | let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs") in
|
---|
| 27 | let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in
|
---|
| 28 | let time = Arg.(value & flag & info ["t"] ~doc:"sort by time, newest first") in
|
---|
| 29 | let number = Arg.(value & opt (some int) None & info ["n"]
|
---|
| 30 | ~docv:"number" ~doc:"number of entries to list") in
|
---|
| 31 | let authed = Arg.(value & opt (some string) None & info ["authored"]
|
---|
| 32 | ~docv:"comma-separated names" ~doc:"texts by authors") in
|
---|
| 33 | let topics = Arg.(value & opt (some string) None & info ["topics"]
|
---|
| 34 | ~docv:"comma-separated topics" ~doc:"texts with topics") in
|
---|
| 35 | Term.(const print $ recurse $ time $ reverse $ number $ authed $ topics $ id),
|
---|
[10] | 36 | Term.info "read" ~doc: "read a text" ~man:[ `S "DESCRIPTION";
|
---|
[9] | 37 | `P "List header information for current directory. If -R is used, list header
|
---|
| 38 | information for texts found in subdirectories too, along with their filepaths" ]
|
---|