New edit <ID> command and updated readme
git-svn-id: file:///srv/svn/repo/kosuzu/trunk@25 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
22
cli/read.ml
22
cli/read.ml
@@ -1,24 +1,4 @@
|
||||
open Logarion
|
||||
module FS = File_store
|
||||
module A = Archive
|
||||
|
||||
let print r order_opt reverse_opt number_opt authors_opt topics_opt id_opt =
|
||||
let predicates = if id_opt <> "" then [ A.ided id_opt ] else []
|
||||
@ 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 pager = try Sys.getenv "PAGER" with Not_found -> "less" in
|
||||
let print_text acc (_t, fnames) = Printf.sprintf "%s %s" acc (List.hd fnames) in
|
||||
let paths = match order_opt with
|
||||
| false -> FS.fold ~r ~predicate print_text ""
|
||||
| true ->
|
||||
let order = match reverse_opt with true -> FS.newest | false -> FS.oldest in
|
||||
match number_opt with
|
||||
| Some number -> FS.fold ~r ~predicate ~order ~number print_text ""
|
||||
| None -> FS.fold ~r ~predicate ~order print_text ""
|
||||
in if paths = "" then ()
|
||||
else (ignore @@ Sys.command @@ Printf.sprintf "%s %s" pager paths)
|
||||
|
||||
|
||||
open Cmdliner
|
||||
let term =
|
||||
@@ -32,7 +12,7 @@ let term =
|
||||
~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
|
||||
Term.(const print $ recurse $ time $ reverse $ number $ authed $ topics $ id),
|
||||
Term.(const (Archive.apply_sys_util "PAGER" "less") $ recurse $ time $ reverse $ number $ authed $ topics $ id),
|
||||
Term.info "read" ~doc: "read a text" ~man:[ `S "DESCRIPTION";
|
||||
`P "List header information for current directory. If -R is used, list header
|
||||
information for texts found in subdirectories too, along with their filepaths" ]
|
||||
|
||||
Reference in New Issue
Block a user