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 dir =
|
---|
6 | let dir = if dir = "" then FS.txtdir () else dir in
|
---|
7 | let predicates = A.predicate A.authored authors_opt @ A.predicate A.topics topics_opt in
|
---|
8 | let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
|
---|
9 | let list_text (t, fnames) = Printf.printf "%s %s %s 𐄁 %s%s\n"
|
---|
10 | (Text.short_id t) Date.(pretty_date @@ listing t.Text.date)
|
---|
11 | (Person.Set.to_string ~names_only:true t.Text.authors)
|
---|
12 | t.Text.title (if paths_opt then (List.fold_left (Printf.sprintf "%s\n@ %s") "" fnames) else "")
|
---|
13 | in
|
---|
14 | match order_opt with
|
---|
15 | | false -> FS.iter ~r ~dir ~predicate list_text
|
---|
16 | | true ->
|
---|
17 | let order = match reverse_opt with true -> FS.newest | false -> FS.oldest in
|
---|
18 | match number_opt with
|
---|
19 | | Some number -> FS.iter ~r ~dir ~predicate ~order ~number list_text
|
---|
20 | | None -> FS.iter ~r ~dir ~predicate ~order list_text
|
---|
21 |
|
---|
22 | open Cmdliner
|
---|
23 | let term =
|
---|
24 | let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs") in
|
---|
25 | let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in
|
---|
26 | let time = Arg.(value & flag & info ["t"] ~doc:"sort by time, newest first") in
|
---|
27 | let paths = Arg.(value & flag & info ["p"] ~doc:"show file paths") in
|
---|
28 | let number = Arg.(value & opt (some int) None & info ["n"]
|
---|
29 | ~docv:"number" ~doc:"number of entries to list") in
|
---|
30 | let authed = Arg.(value & opt (some string) None & info ["authored"]
|
---|
31 | ~docv:"comma-separated names" ~doc:"texts by authors") in
|
---|
32 | let topics = Arg.(value & opt (some string) None & info ["topics"]
|
---|
33 | ~docv:"comma-separated topics" ~doc:"texts with topics") in
|
---|
34 | let dir = Arg.(value & pos 0 string "" & info []
|
---|
35 | ~docv:"directory to index") in
|
---|
36 | Term.(const listing $ recurse $ time $ reverse $ number $ paths $ authed $ topics $ dir),
|
---|
37 | Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION";
|
---|
38 | `P "Diplays text id, date, author, title for a directory.
|
---|
39 | If directory argument is ommitted, $txtdir is used, where empty value defaults to ~/.local/share/texts.
|
---|
40 | If -R is used, list header information for texts found in subdirectories too." ]
|
---|