source: code/trunk/cli/listing.ml@ 68

Last change on this file since 68 was 66, checked in by Izuru Yakumo, 8 months ago

Migrate the codebase to the latest revision of Cmdliner

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 2.2 KB
Line 
1open Logarion
2module FS = File_store
3module A = Archive
4
5let 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
22open Cmdliner
23
24let recurse = Arg.(value & flag & info ["R"] ~doc: "Recurse into subdirectories")
25let reverse = Arg.(value & flag & info ["r"] ~doc: "Reverse order")
26let time = Arg.(value & flag & info ["t"] ~doc: "Sort by time, newest first")
27let paths = Arg.(value & flag & info ["p"] ~doc: "Show file paths")
28let number = Arg.(value & opt (some int) None & info ["n"] ~docv: "number" ~doc: "Number of entries to list")
29let authed = Arg.(value & opt (some string) None & info ["authored"] ~docv: "comma-separated names" ~doc: "Texts by authors")
30let topics = Arg.(value & opt (some string) None & info ["topics"] ~docv: "comma-separated topics" ~doc: "Texts by topics")
31let dir = Arg.(value & pos 0 string "" & info [] ~docv: "directory to index")
32
33let listing_t = Term.(const listing $ recurse $ time $ reverse $ number $ paths $ authed $ topics $ dir)
34
35let cmd =
36 let doc = "List texts" in
37 let man = [
38 `S Manpage.s_description;
39 `P "Displays text id, date, author, title for a directory.";
40 `P "If directory argument is omitted, TXTDIR is used, where empty value defaults to ~/.local/share/texts.";
41 `P "If -R is used, list header information for texts found in subdirectories, too." ]
42 in
43 let info = Cmd.info "list" ~version:"%%VERSION%%" ~doc ~man in
44 Cmd.v info listing_t
Note: See TracBrowser for help on using the repository browser.