Txt read & optional path printing for txt list
This commit is contained in:
parent
3545c3f19f
commit
b38baf8268
2
cli/dune
2
cli/dune
|
@ -1,5 +1,5 @@
|
||||||
(executable
|
(executable
|
||||||
(name txt)
|
(name txt)
|
||||||
(public_name txt)
|
(public_name txt)
|
||||||
(modules txt authors convert conversion file index last listing new topics html atom gemini publish pull)
|
(modules txt authors convert conversion file index last listing new topics html atom gemini publish pull read)
|
||||||
(libraries text_parse.converter text_parse.parsers logarion msgpck curl str cmdliner))
|
(libraries text_parse.converter text_parse.parsers logarion msgpck curl str cmdliner))
|
||||||
|
|
|
@ -1,38 +1,36 @@
|
||||||
open Logarion
|
open Logarion
|
||||||
module FS = File_store
|
module FS = File_store
|
||||||
module A = Archive
|
module A = Archive
|
||||||
let listing r order_opt reverse_opt number_opt authors_opt topics_opt =
|
|
||||||
let predicates = A.predicate A.authored authors_opt
|
let listing r order_opt reverse_opt number_opt paths_opt authors_opt topics_opt =
|
||||||
@ A.predicate A.topics topics_opt 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 predicate text = List.fold_left (fun a e -> a && e text) true predicates in
|
||||||
let list_text a (t, fnames) = a ^ Printf.sprintf "%s %s %s 𐄁 %s [%s]\n"
|
let list_text (t, fnames) = Printf.printf "%s %s %s 𐄁 %s%s\n"
|
||||||
(Text.short_id t) Date.(pretty_date @@ listing t.Text.date)
|
(Text.short_id t) Date.(pretty_date @@ listing t.Text.date)
|
||||||
(Person.Set.to_string ~names_only:true t.Text.authors)
|
(Person.Set.to_string ~names_only:true t.Text.authors)
|
||||||
t.Text.title (List.hd fnames)
|
t.Text.title (if paths_opt then (List.fold_left (Printf.sprintf "%s\n@ %s") "" fnames) else "")
|
||||||
in
|
in
|
||||||
print_string @@ match order_opt with
|
match order_opt with
|
||||||
| false -> FS.fold ~r ~predicate list_text ""
|
| false -> FS.iter ~r ~predicate list_text
|
||||||
| true ->
|
| true ->
|
||||||
let order = match reverse_opt with true -> FS.newest | false -> FS.oldest in
|
let order = match reverse_opt with true -> FS.newest | false -> FS.oldest in
|
||||||
match number_opt with
|
match number_opt with
|
||||||
| Some number -> FS.fold ~r ~predicate ~order ~number list_text ""
|
| Some number -> FS.iter ~r ~predicate ~order ~number list_text
|
||||||
| None -> FS.fold ~r ~predicate ~order list_text ""
|
| None -> FS.iter ~r ~predicate ~order list_text
|
||||||
|
|
||||||
open Cmdliner
|
open Cmdliner
|
||||||
let term =
|
let term =
|
||||||
let recurse = Arg.(value & flag & info ["R"]
|
let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs") in
|
||||||
~doc:"recursive, include texts in subdirectories too") in
|
let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in
|
||||||
let reverse = Arg.(value & flag & info ["r"]
|
let time = Arg.(value & flag & info ["t"] ~doc:"sort by time, newest first") in
|
||||||
~doc:"reverse order") in
|
let paths = Arg.(value & flag & info ["p"] ~doc:"show file paths") in
|
||||||
let time = Arg.(value & flag & info ["t"]
|
|
||||||
~doc:"Sort by time, newest first") in
|
|
||||||
let number = Arg.(value & opt (some int) None & info ["n"]
|
let number = Arg.(value & opt (some int) None & info ["n"]
|
||||||
~docv:"number" ~doc:"number of entries to list") in
|
~docv:"number" ~doc:"number of entries to list") in
|
||||||
let authed = Arg.(value & opt (some string) None & info ["authored"]
|
let authed = Arg.(value & opt (some string) None & info ["authored"]
|
||||||
~docv:"comma-separated names" ~doc:"texts by authors") in
|
~docv:"comma-separated names" ~doc:"texts by authors") in
|
||||||
let topics = Arg.(value & opt (some string) None & info ["topics"]
|
let topics = Arg.(value & opt (some string) None & info ["topics"]
|
||||||
~docv:"comma-separated topics" ~doc:"texts with topics") in
|
~docv:"comma-separated topics" ~doc:"texts with topics") in
|
||||||
Term.(const listing $ recurse $ time $ reverse $ number $ authed $ topics),
|
Term.(const listing $ recurse $ time $ reverse $ number $ paths $ authed $ topics),
|
||||||
Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION";
|
Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION";
|
||||||
`P "List header information for current directory. If -R is used, list header
|
`P "List header information for current directory. If -R is used, list header
|
||||||
information for texts found in subdirectories too, along with their filepaths" ]
|
information for texts found in subdirectories too, along with their filepaths" ]
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
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 =
|
||||||
|
let id = Arg.(value & pos 0 string "" & info [] ~docv:"text ID") in
|
||||||
|
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 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
|
||||||
|
Term.(const print $ recurse $ time $ reverse $ number $ authed $ topics $ id),
|
||||||
|
Term.info "read" ~doc:"list texts" ~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" ]
|
|
@ -16,5 +16,6 @@ let () = match Term.eval_choice default_cmd [
|
||||||
New.term;
|
New.term;
|
||||||
Publish.term;
|
Publish.term;
|
||||||
Pull.term;
|
Pull.term;
|
||||||
|
Read.term;
|
||||||
Topics.term;
|
Topics.term;
|
||||||
] with `Error _ -> exit 1 | _ -> exit 0
|
] with `Error _ -> exit 1 | _ -> exit 0
|
||||||
|
|
|
@ -4,6 +4,9 @@ let authored query_string =
|
||||||
let q = Person.Set.of_query @@ String_set.query query_string in
|
let q = Person.Set.of_query @@ String_set.query query_string in
|
||||||
fun n -> Person.Set.predicate q n.Text.authors
|
fun n -> Person.Set.predicate q n.Text.authors
|
||||||
|
|
||||||
|
let ided query_string =
|
||||||
|
fun n -> n.Text.id = query_string
|
||||||
|
|
||||||
let keyworded query_string =
|
let keyworded query_string =
|
||||||
let q = String_set.query query_string in
|
let q = String_set.query query_string in
|
||||||
fun n -> String_set.(predicate q (Text.set "Keywords" n))
|
fun n -> String_set.(predicate q (Text.set "Keywords" n))
|
||||||
|
|
Loading…
Reference in New Issue