1 | open Logarion
|
---|
2 | module FS = File_store
|
---|
3 | module A = Archive
|
---|
4 |
|
---|
5 | let listing r order_opt reverse_opt number_opt paths_opt authors_opt topics_opt =
|
---|
6 | let predicates = A.predicate A.authored authors_opt @ 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 (t, fnames) = Printf.printf "%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 (if paths_opt then (List.fold_left (Printf.sprintf "%s\n@ %s") "" fnames) else "")
|
---|
12 | in
|
---|
13 | match order_opt with
|
---|
14 | | false -> FS.iter ~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.iter ~r ~predicate ~order ~number list_text
|
---|
19 | | None -> FS.iter ~r ~predicate ~order list_text
|
---|
20 |
|
---|
21 | open Cmdliner
|
---|
22 | let term =
|
---|
23 | let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs") in
|
---|
24 | let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in
|
---|
25 | let time = Arg.(value & flag & info ["t"] ~doc:"sort by time, newest first") in
|
---|
26 | let paths = Arg.(value & flag & info ["p"] ~doc:"show file paths") in
|
---|
27 | let number = Arg.(value & opt (some int) None & info ["n"]
|
---|
28 | ~docv:"number" ~doc:"number of entries to list") in
|
---|
29 | let authed = Arg.(value & opt (some string) None & info ["authored"]
|
---|
30 | ~docv:"comma-separated names" ~doc:"texts by authors") in
|
---|
31 | let topics = Arg.(value & opt (some string) None & info ["topics"]
|
---|
32 | ~docv:"comma-separated topics" ~doc:"texts with topics") in
|
---|
33 | Term.(const listing $ recurse $ time $ reverse $ number $ paths $ authed $ topics),
|
---|
34 | Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION";
|
---|
35 | `P "List header information for current directory. If -R is used, list header
|
---|
36 | information for texts found in subdirectories too, along with their filepaths" ]
|
---|