Changeset 25 in code for trunk


Ignore:
Timestamp:
Nov 13, 2022, 1:15:27 PM (2 years ago)
Author:
fox
Message:

New edit <ID> command and updated readme

Location:
trunk
Files:
2 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/dune

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

    r10 r25  
    11open Logarion
    2 module FS = File_store
    3 module A = Archive
    4 
    5 let print r order_opt reverse_opt number_opt authors_opt topics_opt id_opt =
    6         let predicates = if id_opt <> "" then [ A.ided id_opt ] else []
    7                 @ A.predicate A.authored authors_opt
    8                 @ A.predicate A.topics topics_opt in
    9         let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
    10         let pager = try Sys.getenv "PAGER" with Not_found -> "less" in
    11         let print_text acc (_t, fnames) = Printf.sprintf "%s %s" acc (List.hd fnames) in
    12         let paths = match order_opt with
    13         | false -> FS.fold ~r ~predicate print_text ""
    14         | true ->
    15                 let order = match reverse_opt with true -> FS.newest | false -> FS.oldest in
    16                 match number_opt with
    17                 | Some number -> FS.fold ~r ~predicate ~order ~number print_text ""
    18                 | None -> FS.fold ~r ~predicate ~order print_text ""
    19         in if paths = "" then ()
    20         else (ignore @@ Sys.command @@ Printf.sprintf "%s %s" pager paths)
    21        
    222
    233open Cmdliner
     
    3313        let topics = Arg.(value & opt (some string) None & info ["topics"]
    3414                ~docv:"comma-separated topics" ~doc:"texts with topics") in
    35         Term.(const print $ recurse $ time $ reverse $ number $ authed $ topics $ id),
     15        Term.(const (Archive.apply_sys_util "PAGER" "less") $ recurse $ time $ reverse $ number $ authed $ topics $ id),
    3616        Term.info "read" ~doc: "read a text" ~man:[ `S "DESCRIPTION";
    3717                `P "List header information for current directory. If -R is used, list header
  • trunk/cli/txt.ml

    r17 r25  
    44let default_cmd =
    55        let doc = "Discover, collect & exchange texts" in
    6         let man = [ `S "Contact"; `P "<mailto:fox@orbitalfox.eu?subject=Logarion>" ] in
     6        let man = [ `S "Contact"; `P "<mailto:logarion@lists.tildeverse.org?subject=Logarion>" ] in
    77        Term.(ret (const (`Help (`Pager, None)))), Term.info "txt" ~version ~doc ~man
    88
     
    1010        Authors.term;
    1111        Convert.term;
     12        Edit.term;
    1213        File.term; File.unfile_term;
    1314        Index.term;
  • trunk/lib/archive.ml

    r9 r25  
    1515  let q = String_set.query query_string in
    1616  fun n -> String_set.(predicate q (Text.set "Topics" n))
     17
     18let apply_sys_util env def_env r order_opt reverse_opt number_opt authors_opt topics_opt id_opt =
     19        let predicates = if id_opt <> "" then [ ided id_opt ] else []
     20                @ predicate authored authors_opt
     21                @ predicate topics topics_opt in
     22        let predicate text = List.fold_left (fun a e -> a && e text) true predicates in
     23        let util = try Sys.getenv env with Not_found -> def_env in
     24        let print_text acc (_t, fnames) = Printf.sprintf "%s %s" acc (List.hd fnames) in
     25        let paths = match order_opt with
     26        | false -> File_store.fold ~r ~predicate print_text ""
     27        | true ->
     28                let order = match reverse_opt with true -> File_store.newest | false -> File_store.oldest in
     29                match number_opt with
     30                | Some number -> File_store.fold ~r ~predicate ~order ~number print_text ""
     31                | None -> File_store.fold ~r ~predicate ~order print_text ""
     32        in if paths = "" then ()
     33        else (ignore @@ Sys.command @@ Printf.sprintf "%s %s" util paths)
Note: See TracChangeset for help on using the changeset viewer.