Changeset 9 in code for trunk


Ignore:
Timestamp:
Jun 19, 2022, 9:01:11 PM (3 years ago)
Author:
fox
Message:

Txt read & optional path printing for txt list

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/dune

    r6 r9  
    22 (name txt)
    33 (public_name txt)
    4  (modules txt authors convert conversion file index last listing new topics html atom gemini publish pull)
     4 (modules txt authors convert conversion file index last listing new topics html atom gemini publish pull read)
    55 (libraries text_parse.converter text_parse.parsers logarion msgpck curl str cmdliner))
  • trunk/cli/listing.ml

    r3 r9  
    22module FS = File_store
    33module A = Archive
    4 let listing r order_opt reverse_opt number_opt authors_opt topics_opt =
    5         let predicates = A.predicate A.authored authors_opt
    6                 @ A.predicate A.topics topics_opt in
     4
     5let listing r order_opt reverse_opt number_opt paths_opt authors_opt topics_opt =
     6        let predicates = A.predicate A.authored authors_opt @ A.predicate A.topics topics_opt in
    77        let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
    8         let list_text a (t, fnames) = a ^ Printf.sprintf "%s %s %s 𐄁 %s [%s]\n"
     8        let list_text (t, fnames) = Printf.printf "%s %s %s 𐄁 %s%s\n"
    99                (Text.short_id t) Date.(pretty_date @@ listing t.Text.date)
    1010                (Person.Set.to_string ~names_only:true t.Text.authors)
    11                 t.Text.title (List.hd fnames)
     11                t.Text.title (if paths_opt then (List.fold_left (Printf.sprintf "%s\n@ %s") "" fnames) else "")
    1212        in
    13         print_string @@ match order_opt with
    14         | false -> FS.fold ~r ~predicate list_text ""
     13        match order_opt with
     14        | false -> FS.iter ~r ~predicate list_text
    1515        | true ->
    1616                let order = match reverse_opt with true -> FS.newest | false -> FS.oldest in
    1717                match number_opt with
    18                 | Some number -> FS.fold ~r ~predicate ~order ~number list_text ""
    19                 | None -> FS.fold ~r ~predicate ~order list_text ""
     18                | Some number -> FS.iter ~r ~predicate ~order ~number list_text
     19                | None -> FS.iter ~r ~predicate ~order list_text
    2020
    2121open Cmdliner
    2222let term =
    23         let recurse = Arg.(value & flag & info ["R"]
    24                 ~doc:"recursive, include texts in subdirectories too") in
    25         let reverse = Arg.(value & flag & info ["r"]
    26                 ~doc:"reverse order") in
    27         let time   = Arg.(value & flag & info ["t"]
    28                 ~doc:"Sort by time, newest first") in
     23        let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs") in
     24        let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in
     25        let time   = Arg.(value & flag & info ["t"] ~doc:"sort by time, newest first") in
     26        let paths = Arg.(value & flag & info ["p"] ~doc:"show file paths") in
    2927        let number = Arg.(value & opt (some int) None & info ["n"]
    3028                ~docv:"number" ~doc:"number of entries to list") in
     
    3331        let topics = Arg.(value & opt (some string) None & info ["topics"]
    3432                ~docv:"comma-separated topics" ~doc:"texts with topics") in
    35         Term.(const listing $ recurse $ time $ reverse $ number $ authed $ topics),
     33        Term.(const listing $ recurse $ time $ reverse $ number $ paths $ authed $ topics),
    3634        Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION";
    37         `P "List header information for current directory. If -R is used, list header
    38         information for texts found in subdirectories too, along with their filepaths" ]
     35                `P "List header information for current directory. If -R is used, list header
     36                information for texts found in subdirectories too, along with their filepaths" ]
  • trunk/cli/txt.ml

    r6 r9  
    1717        Publish.term;
    1818        Pull.term;
     19        Read.term;
    1920        Topics.term;
    2021        ] with `Error _ -> exit 1 | _ -> exit 0
  • trunk/lib/archive.ml

    r3 r9  
    44  let q = Person.Set.of_query @@ String_set.query query_string in
    55  fun n -> Person.Set.predicate q n.Text.authors
     6
     7let ided query_string =
     8        fun n -> n.Text.id = query_string
    69
    710let keyworded query_string =
Note: See TracChangeset for help on using the changeset viewer.