
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/kosuzu/trunk@65 eb64cd80-c68d-6f47-b6a3-0ada418499da
41 lines
2.1 KiB
OCaml
41 lines
2.1 KiB
OCaml
open Logarion
|
|
module FS = File_store
|
|
module A = Archive
|
|
|
|
let listing r order_opt reverse_opt number_opt paths_opt authors_opt topics_opt dir =
|
|
let dir = if dir = "" then FS.txtdir () else dir in
|
|
let predicates = A.predicate A.authored authors_opt @ A.predicate A.topics topics_opt in
|
|
let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
|
|
let list_text (t, fnames) = Printf.printf "%s | %s | %s | %s %s\n"
|
|
(Text.short_id t) Date.(pretty_date @@ listing t.Text.date)
|
|
(Person.Set.to_string ~names_only:true t.Text.authors)
|
|
t.Text.title (if paths_opt then (List.fold_left (Printf.sprintf "%s\n@ %s") "" fnames) else "")
|
|
in
|
|
match order_opt with
|
|
| false -> FS.iter ~r ~dir ~predicate list_text
|
|
| true ->
|
|
let order = match reverse_opt with true -> FS.newest | false -> FS.oldest in
|
|
match number_opt with
|
|
| Some number -> FS.iter ~r ~dir ~predicate ~order ~number list_text
|
|
| None -> FS.iter ~r ~dir ~predicate ~order list_text
|
|
|
|
open Ocmd
|
|
let term =
|
|
let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs") in
|
|
let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in
|
|
let time = Arg.(value & flag & info ["t"] ~doc:"sort by time, newest first") in
|
|
let paths = Arg.(value & flag & info ["p"] ~doc:"show file paths") in
|
|
let number = Arg.(value & opt (some int) None & info ["n"]
|
|
~docv:"number" ~doc:"number of entries to list") in
|
|
let authed = Arg.(value & opt (some string) None & info ["authored"]
|
|
~docv:"comma-separated names" ~doc:"texts by authors") in
|
|
let topics = Arg.(value & opt (some string) None & info ["topics"]
|
|
~docv:"comma-separated topics" ~doc:"texts with topics") in
|
|
let dir = Arg.(value & pos 0 string "" & info []
|
|
~docv:"directory to index") in
|
|
Term.(const listing $ recurse $ time $ reverse $ number $ paths $ authed $ topics $ dir),
|
|
Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION";
|
|
`P "Diplays text id, date, author, title for a directory.
|
|
If directory argument is ommitted, TXTDIR is used, where empty value defaults to ~/.local/share/texts.
|
|
If -R is used, list header information for texts found in subdirectories too." ]
|