[3] | 1 | open Logarion
|
---|
| 2 | module FS = File_store
|
---|
| 3 | module A = Archive
|
---|
| 4 | let listing r order_opt reverse_opt number_opt authors_opt topics_opt =
|
---|
| 5 | let predicates = A.predicate A.authored authors_opt
|
---|
| 6 | @ A.predicate A.topics topics_opt in
|
---|
| 7 | let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
|
---|
| 8 | let list_text a (t, fnames) = a ^ Printf.sprintf "%s %s %s 𐄁 %s [%s]\n"
|
---|
| 9 | (Text.short_id t) Date.(pretty_date @@ listing t.Text.date)
|
---|
| 10 | (Person.Set.to_string ~names_only:true t.Text.authors)
|
---|
| 11 | t.Text.title (List.hd fnames)
|
---|
| 12 | in
|
---|
| 13 | print_string @@ match order_opt with
|
---|
| 14 | | false -> FS.fold ~r ~predicate list_text ""
|
---|
| 15 | | true ->
|
---|
| 16 | let order = match reverse_opt with true -> FS.newest | false -> FS.oldest in
|
---|
| 17 | match number_opt with
|
---|
| 18 | | Some number -> FS.fold ~r ~predicate ~order ~number list_text ""
|
---|
| 19 | | None -> FS.fold ~r ~predicate ~order list_text ""
|
---|
| 20 |
|
---|
| 21 | open Cmdliner
|
---|
| 22 | let term =
|
---|
| 23 | let recurse = Arg.(value & flag & info ["R"]
|
---|
| 24 | ~doc:"recursive, include texts in subdirectories too") in
|
---|
| 25 | let reverse = Arg.(value & flag & info ["r"]
|
---|
| 26 | ~doc:"reverse order") in
|
---|
| 27 | let time = Arg.(value & flag & info ["t"]
|
---|
| 28 | ~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 listing $ recurse $ time $ reverse $ number $ authed $ topics),
|
---|
| 36 | Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION";
|
---|
| 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" ]
|
---|