Migrate the codebase to the latest revision of Cmdliner

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

git-svn-id: file:///srv/svn/repo/kosuzu/trunk@66 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
yakumo.izuru
2024-08-21 01:37:05 +00:00
parent 3f090772ce
commit d310d041ce
17 changed files with 271 additions and 233 deletions

View File

@@ -6,12 +6,17 @@ let authors r topics_opt =
let s = File_store.fold ~r ~predicate author_union Person.Set.empty in let s = File_store.fold ~r ~predicate author_union Person.Set.empty in
Person.Set.iter (fun x -> print_endline (Person.to_string x)) s Person.Set.iter (fun x -> print_endline (Person.to_string x)) s
open Ocmd open Cmdliner
let term = let recurse = Arg.(value & flag & info ["R"] ~doc: "Include texts in subdirectories too")
let recurse = Arg.(value & flag & info ["R"] let topics = Arg.(value & opt (some string) None & info ["topics"] ~docv:"topics" ~doc: "Display authors who have written on topics")
~doc:"include texts in subdirectories too") in
let topics = Arg.(value & opt (some string) None & info ["topics"] let authors_t = Term.(const authors $ recurse $ topics)
~docv:"TOPICS" ~doc:"display authors who have written on topics") in
Term.(const authors $ recurse $ topics), let cmd =
Term.info "authors" ~doc:"list authors" let doc = "List authors" in
~man:[ `S "DESCRIPTION"; `P "List author names" ] let man = [
`S Manpage.s_description;
`P "List author names" ]
in
let info = Cmd.info "authors" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info authors_t

View File

@@ -76,15 +76,21 @@ let at_path types noindex path = match path with
) )
| path -> Printf.eprintf "Path doesn't exist: %s" path | path -> Printf.eprintf "Path doesn't exist: %s" path
open Ocmd open Cmdliner
let term =
let path = Arg.(value & pos 0 string "" & info [] ~docv:"path" let path = Arg.(value & pos 0 string "" & info [] ~docv:"path" ~doc:"Text file or directory to convert. If directory is provided, it must contain an index.pck (see: txt index)")
~doc:"Text file or directory to convert. If directory is provided, it must contain an index.pck (see: txt index)") in let types = Arg.(value & opt string "all" & info ["t"; "type"] ~docv:"output type" ~doc:"Convert to file type")
let types = Arg.(value & opt string "all" & info ["t"; "type"] ~docv:"output type" let noindex = Arg.(value & flag & info ["noindex"] ~doc:"Don't create indices in target format")
~doc:"Convert to file type") in
let noindex = Arg.(value & flag & info ["noindex"] let convert_t = Term.(const at_path $ types $ noindex $ path)
~doc:"Don't create indices in target format") in
Term.(const at_path $ types $ noindex $ path), let cmd =
Term.info "convert" ~doc:"convert texts" let doc = "Convert texts" in
~man:[ `S "DESCRIPTION"; `P "Convert text or indexed texts within a directory to another format. let man = [
If path is a directory must contain an index.pck. Run `txt index` first." ] `S Manpage.s_description;
`P "Convert text or indexed texts within a directory to another format.";
`P "If path is a directory must contain an index.pck.";
`P "Run `txt index` first." ]
in
let info = Cmd.info "convert" ~version: "%%VERSION%%" ~doc ~man in
Cmd.v info convert_t

View File

@@ -2,5 +2,5 @@
(name txt) (name txt)
(public_name txt) (public_name txt)
(modules txt authors convert conversion edit file index last listing (modules txt authors convert conversion edit file index last listing
new topics html atom gemini peers pull read recent) new topics html atom gemini peers pull read recent unfile)
(libraries text_parse.converter text_parse.parsers logarion msgpck curl str cmdliner)) (libraries text_parse.converter text_parse.parsers logarion msgpck curl str cmdliner ocmd))

View File

@@ -1,16 +1,20 @@
open Ocmd open Cmdliner
let term = let id = Arg.(value & pos 0 string "" & info [] ~docv: "text ID")
let id = Arg.(value & pos 0 string "" & info [] ~docv:"text ID") in let recurse = Arg.(value & flag & info ["R"] ~doc: "Recurse into subdirectories")
let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs") in let reverse = Arg.(value & flag & info ["r"] ~doc: "Reverse order")
let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in let time = Arg.(value & flag & info ["t"] ~doc: "Sort by time, newest first")
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")
let number = Arg.(value & opt (some int) None & info ["n"] let authed = Arg.(value & opt (some string) None & info ["authored"] ~docv: "Comma-separated names" ~doc: "Texts by authors")
~docv:"number" ~doc:"number of entries to list") in let topics = Arg.(value & opt (some string) None & info ["topics"] ~docv: "Comma-separated topics" ~doc: "Texts by topics")
let authed = Arg.(value & opt (some string) None & info ["authored"]
~docv:"comma-separated names" ~doc:"texts by authors") in let edit_t = Term.(const (Logarion.Archive.apply_sys_util "EDITOR" "nano") $ recurse $ time $ reverse $ number $ authed $ topics $ id)
let topics = Arg.(value & opt (some string) None & info ["topics"]
~docv:"comma-separated topics" ~doc:"texts with topics") in let cmd =
Term.(const (Logarion.Archive.apply_sys_util "EDITOR" "nano") $ recurse $ time $ reverse $ number $ authed $ topics $ id), let doc = "Edit a text" in
Term.info "edit" ~doc: "edit a text" ~man:[ `S "DESCRIPTION"; let man = [
`P "Launches EDITOR (nano if environment variable is unset) with text path as parameter. `S Manpage.s_description;
If -R is used, the ID search space includes texts found in subdirectories too" ] `P "Launches EDITOR (nano if environment variable is unset) with text path as parameter.";
`P "If -R is used, the ID search space includes texts found in subdirectories, too." ]
in
let info = Cmd.info "edit" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info edit_t

View File

@@ -8,27 +8,16 @@ let file files =
let link = link_with_id in let link = link_with_id in
List.iter (fun d -> List.iter (link d) files) dirs List.iter (fun d -> List.iter (link d) files) dirs
let unfile files = open Cmdliner
let dirs, files = File_store.split_filetypes files in let files = Arg.(value & pos_all string [] & info [] ~docv: "Text filenames and subdirectories")
let unlink dir file = try Unix.unlink (Filename.concat dir file) let file_t = Term.(const file $ files)
with Unix.(Unix_error(ENOENT,_,_))-> () in
List.iter (fun d -> List.iter (unlink d) files) dirs
open Ocmd let cmd =
let term = let doc = "File texts in subdirectories" in
let files = Arg.(value & pos_all string [] & info [] let man = [
~docv:"text filenames and subdirectories") in `S Manpage.s_description;
Term.(const file $ files), Term.info "file" `P "Files all texts in parameter in every directory in parameter, using hardlinks";
~doc:"file texts in subdirectories" `P "Use it to create sub-repositories for sharing or converting" ]
~man:[ `S "DESCRIPTION"; `P "Files all texts in parameter in every in
directory in parameter, using hardlinks. let info = Cmd.info "file" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info file_t
Use it to create sub-repositories for sharing or converting" ]
let unfile_term =
let files = Arg.(value & pos_all string [] & info []
~docv:"text filenames and subdirectories") in
Term.(const unfile $ files), Term.info "unfile"
~doc:"unfile texts from subdirectories"
~man:[ `S "DESCRIPTION"; `P "unfile texts in parameter from
directories in parameter, by removing hardlinks" ]

View File

@@ -67,25 +67,25 @@ let load dir =
let index_path = Filename.concat dir "index.pck" in let index_path = Filename.concat dir "index.pck" in
index { dir; index_path; pck = Header_pack.of_kv kv } index { dir; index_path; pck = Header_pack.of_kv kv }
open Ocmd open Cmdliner
let term = let print = Arg.(value & flag & info ["print"] ~doc: "Print info")
let print= Arg.(value & flag & info ["print"] ~doc:"print info") in let title = Arg.(value & opt ~vopt:(Some "") (some string) None & info ["t"; "title"] ~docv: "string" ~doc: "Title for index")
let title= Arg.(value & opt ~vopt:(Some "") (some string) None & info ["t"; "title"] let auth = Arg.(value & opt ~vopt:(Some "") (some string) None & info ["a"; "authors"] ~docv: "Comma-separated names" ~doc: "Index authors")
~docv:"string" ~doc:"Title for index") in let locs = Arg.(value & opt ~vopt:(Some "") (some string) None & info ["l"; "location"] ~docv: "Comma-separated URLs" ~doc: "Repository URLs")
let auth = Arg.(value & opt ~vopt:(Some "") (some string) None & info ["a"; "authors"] let peers = Arg.(value & opt ~vopt:(Some "") (some string) None & info ["p"; "peers"] ~docv: "Comma-separated URLs" ~doc: "URLs to other known text repositories")
~docv:"comma-separated names" ~doc:"Index authors") in let dir = Arg.(value & pos 0 string "." & info [] ~docv: "Directory to index")
let locs = Arg.(value & opt ~vopt:(Some "") (some string) None & info ["l"; "locations"]
~docv:"comma-separated URLs" ~doc:"repository URLs") in
let peers= Arg.(value & opt ~vopt:(Some "") (some string) None & info ["p"; "peers"]
~docv:"comma-separated URLs" ~doc:"URLs to other known text repositories") in
let dir = Arg.(value & pos 0 string "." & info []
~docv:"directory to index") in
let doc = "Generate an index.pck for texts in a directory" in
Term.(const load $ dir $ print $ title $ auth $ locs $ peers),
Term.info "index" ~doc
~man:[ `S "DESCRIPTION"; `Pre "An index contains:\n
* an info section with: title for the index, the authors, locations (URLs) the texts can be access\n
* listing of texts with: ID, date, title, authors, topics\n
* list of other text repositories (peers)\n\n
MessagePack format. <msgpack.org>" ]
let index_t = Term.(const load $ dir $ print $ title $ auth $ locs $ peers)
let cmd =
let doc = "Generate an index.pck for texts in a directory" in
let man = [
`S Manpage.s_description;
`P "An index contains:\n";
`P "* n info section with: title for the index, the authors, locations (URLs) the texts can be accessed.";
`P "* listing of texts with: ID, date, title, authors, topics.";
`P "* list of other text repositories (peers)";
`S Manpage.s_see_also;
`P "MessagePack format. https://msgpack.org" ] in
let info = Cmd.info "index" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info index_t

View File

@@ -20,9 +20,16 @@ let last search_mine =
| None -> () | None -> ()
| Some (_, f) -> List.iter print_endline f | Some (_, f) -> List.iter print_endline f
open Ocmd open Cmdliner
let term =
let mine = Arg.(value & flag & info ["mine"] ~doc:"last text authored by me") in let mine = Arg.(value & flag & info ["mine"] ~doc: "Last text authored by me")
Term.(const last $ mine), let last_t = Term.(const last $ mine)
Term.info "last" ~doc:"most recent text"
~man:[ `S "DESCRIPTION"; `P "Print the filename of most recent text" ] let cmd =
let doc = "Most recent text" in
let man = [
`S Manpage.s_description;
`P "Print the filename of most recent text" ]
in
let info = Cmd.info "last" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info last_t

View File

@@ -19,22 +19,26 @@ let listing r order_opt reverse_opt number_opt paths_opt authors_opt topics_opt
| Some number -> FS.iter ~r ~dir ~predicate ~order ~number list_text | Some number -> FS.iter ~r ~dir ~predicate ~order ~number list_text
| None -> FS.iter ~r ~dir ~predicate ~order list_text | None -> FS.iter ~r ~dir ~predicate ~order list_text
open Ocmd open Cmdliner
let term =
let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs") in let recurse = Arg.(value & flag & info ["R"] ~doc: "Recurse into subdirectories")
let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in let reverse = Arg.(value & flag & info ["r"] ~doc: "Reverse order")
let time = Arg.(value & flag & info ["t"] ~doc:"sort by time, newest first") in let time = Arg.(value & flag & info ["t"] ~doc: "Sort by time, newest first")
let paths = Arg.(value & flag & info ["p"] ~doc:"show file paths") in let paths = Arg.(value & flag & info ["p"] ~doc: "Show file paths")
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")
~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")
let authed = Arg.(value & opt (some string) None & info ["authored"] let topics = Arg.(value & opt (some string) None & info ["topics"] ~docv: "comma-separated topics" ~doc: "Texts by topics")
~docv:"comma-separated names" ~doc:"texts by authors") in let dir = Arg.(value & pos 0 string "" & info [] ~docv: "directory to index")
let topics = Arg.(value & opt (some string) None & info ["topics"]
~docv:"comma-separated topics" ~doc:"texts with topics") in let listing_t = Term.(const listing $ recurse $ time $ reverse $ number $ paths $ authed $ topics $ dir)
let dir = Arg.(value & pos 0 string "" & info []
~docv:"directory to index") in let cmd =
Term.(const listing $ recurse $ time $ reverse $ number $ paths $ authed $ topics $ dir), let doc = "List texts" in
Term.info "list" ~doc:"list texts" ~man:[ `S "DESCRIPTION"; let man = [
`P "Diplays text id, date, author, title for a directory. `S Manpage.s_description;
If directory argument is ommitted, TXTDIR is used, where empty value defaults to ~/.local/share/texts. `P "Displays text id, date, author, title for a directory.";
If -R is used, list header information for texts found in subdirectories too." ] `P "If directory argument is omitted, TXTDIR is used, where empty value defaults to ~/.local/share/texts.";
`P "If -R is used, list header information for texts found in subdirectories, too." ]
in
let info = Cmd.info "list" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info listing_t

View File

@@ -1,5 +1,5 @@
open Logarion open Logarion
open Ocmd open Cmdliner
let new_txt title topics_opt interactive = let new_txt title topics_opt interactive =
let kv = Logarion.File_store.of_kv_file () in let kv = Logarion.File_store.of_kv_file () in
@@ -13,13 +13,17 @@ let new_txt title topics_opt interactive =
if interactive then (Sys.command ("$EDITOR " ^ filepath) |> ignore); if interactive then (Sys.command ("$EDITOR " ^ filepath) |> ignore);
print_endline filepath print_endline filepath
let term = let title = Arg.(value & pos 0 string "" & info [] ~docv: "title" ~doc: "Title for new article")
let title = Arg.(value & pos 0 string "" & info [] let topics = Arg.(value & opt (some string) None & info ["t"; "topics"] ~docv: "Comma-separated topics" ~doc: "Topics for new article")
~docv:"title" ~doc:"Title for new article") in let inter = Arg.(value & flag & info ["i"; "interactive"] ~doc: "Prompt through the steps of creation")
let topics= Arg.(value & opt (some string) None & info ["t"; "topics"]
~docv:"comma-separated topics" ~doc:"Topics for new article") in let new_t = Term.(const new_txt $ title $ topics $ inter)
let inter = Arg.(value & flag & info ["i"; "interactive"]
~doc:"Prompts through the steps of creation") in let cmd =
Term.(const new_txt $ title $ topics $ inter), Term.info "new" let doc = "Create a new article" in
~doc:"create a new article" ~man:[ `S "DESCRIPTION"; let man = [
`S Manpage.s_description;
`P "Create a new article, with title 'Draft' when none provided" ] `P "Create a new article, with title 'Draft' when none provided" ]
in
let info = Cmd.info "new" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info new_t

View File

@@ -28,10 +28,15 @@ let peers = function
Printf.printf "Peers in %s\n" Logarion.Peers.text_dir; Printf.printf "Peers in %s\n" Logarion.Peers.text_dir;
Logarion.Peers.fold print_peer () Logarion.Peers.fold print_peer ()
open Ocmd open Cmdliner
let term = let remove = Arg.(value & opt (some string) None & info ["remove"] ~docv:"Repository ID" ~doc:"Remove repository texts and from future pulling")
let remove = Arg.(value & opt (some string) None & info ["remove"] let peers_t = Term.(const peers $ remove)
~docv:"repository ID" ~doc:"remove repository texts & from future pulling") in
Term.(const peers $ remove), let cmd =
Term.info "peers" ~doc:"list current peers" ~man:[ `S "DESCRIPTION"; let doc = "List current peers" in
`P "Lists current peers and associated information"] let man = [
`S Manpage.s_description;
`P "List current peers and associated information" ]
in
let info = Cmd.info "peers" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info peers_t

View File

@@ -138,47 +138,18 @@ let pull_list auths topics =
let pull url auths topics = match url with let pull url auths topics = match url with
| "" -> pull_list auths topics | x -> ignore (pull_index x auths topics) | "" -> pull_list auths topics | x -> ignore (pull_index x auths topics)
open Ocmd open Cmdliner
let term = let authors = Arg.(value & opt (some string) None & info ["a"; "authors"] ~docv:"Comma-separated names" ~doc:"Filter by authors")
let authors = Arg.(value & opt (some string) None & info ["a"; "authors"] let topics = Arg.(value & opt (some string) None & info ["t"; "topics"] ~docv:"Comma-separated topics" ~doc:"Filter by topics")
~docv:"comma-separated names" ~doc:"filter by authors") in let url = Arg.(value & pos 0 string "" & info [] ~docv:"URL" ~doc:"Repository location")
let topics = Arg.(value & opt (some string) None & info ["t"; "topics"]
~docv:"comma-separated topics" ~doc:"filter by topics") in
let url = Arg.(value & pos 0 string "" & info [] ~docv:"URL"
~doc:"Repository location") in
Term.(const pull $ url $ authors $ topics),
Term.info "pull" ~doc:"pull listed texts" ~man:[ `S "DESCRIPTION";
`P "Pull texts from known repositories. To add a new repository use:";
`P "txt pull [url]";
`P ("This creates a directory in " ^ Logarion.Peers.text_dir
^ " and downloads the text index.pck file in it")]
(*module Msg = struct*) let pull_t = Term.(const pull $ url $ authors $ topics)
(* type t = string * string*)
(* let compare (x0,y0) (x1,y1) =*) let cmd =
(* match compare x1 x0 with 0 -> String.compare y0 y1 | c -> c*) let doc = "Pull listed texts" in
(*end*) let man = [
(*module MsgSet = Set.Make(Msg)*) `S Manpage.s_description;
(*let pull_msgs url _authors _topics =*) `P "Pull texts from known repositories." ]
(* match http_apply response url with*) in
(* | Error msg ->*) let info = Cmd.info "pull" ~version:"%%VERSION%%" ~doc ~man in
(* Printf.eprintf "Failed index request for %s %s" url msg*) Cmd.v info pull_t
(* | Ok body ->*)
(* let rec fold_msgs s a fn =*)
(* let t, msg = Scanf.bscanf s "%s %s@\n" (fun t m -> t, m) in*)
(* if t <> "" then fold_msgs s (fn a t msg) fn else a*)
(* in*)
(* let s = Scanf.Scanning.from_string body in*)
(* let msgs = MsgSet.empty in*)
(* let date_string t = Ptime.to_date t |>*)
(* fun (y, m, d) -> Printf.sprintf "%04d-%02d-%02d" y m d in*)
(* let msgs = fold_msgs s msgs*)
(* (fun msgs t m -> match Ptime.of_rfc3339 t with*)
(* | Ok (v,_,_) -> let open MsgSet in*)
(* let msgs = if cardinal msgs > 1 then remove (max_elt msgs) msgs else msgs in*)
(* add (v,m) msgs*)
(* | _ -> msgs) in*)
(* let msg_string = MsgSet.fold*)
(* (fun (t,m) a -> a ^ Printf.sprintf " %s 𐄁 %s\n" (date_string t) m)*)
(* msgs "" in*)
(* Printf.printf "┌───{ %s }───┐\n%s" url msg_string*)

View File

@@ -1,18 +1,24 @@
open Logarion open Logarion
open Ocmd 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 id = Arg.(value & pos 0 string "" & info [] ~docv:"text ID")
let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs")
let time = Arg.(value & flag & info ["t"] ~doc:"sort by time, newest first") in let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order")
let number = Arg.(value & opt (some int) None & info ["n"] let time = Arg.(value & flag & info ["t"] ~doc:"sort by time, newest first")
~docv:"number" ~doc:"number of entries to list") in let number = Arg.(value & opt (some int) None & info ["n"] ~docv:"number" ~doc:"number of entries to list")
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")
~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")
let topics = Arg.(value & opt (some string) None & info ["topics"]
~docv:"comma-separated topics" ~doc:"texts with topics") in let read_t = Term.(const (Archive.apply_sys_util "PAGER" "less") $ 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"; let cmd =
`P "List header information for current directory. If -R is used, list header let doc = "Read a text" in
information for texts found in subdirectories too, along with their filepaths" ] let man = [
`S Manpage.s_description;
`P "Deprecated. This subcommand will be removed in a future release of Logarion";
`P "This invokes the PAGER utility ('less' if unset) on an article of the archive" ]
in
let info = Cmd.info "read" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info read_t

View File

@@ -2,20 +2,22 @@ open Logarion
module FS = File_store module FS = File_store
module A = Archive module A = Archive
open Ocmd open Cmdliner
let term = let recurse = Arg.(value & flag & info ["R"] ~doc: "Recurse into subdirectories")
let recurse = Arg.(value & flag & info ["R"] ~doc:"recurse, include subdirs") in let reverse = Arg.(value & flag & info ["r"] ~doc: "Reverse order")
let reverse = Arg.(value & flag & info ["r"] ~doc:"reverse order") in let paths = Arg.(value & flag & info ["p"] ~doc: "Show file paths")
let paths = Arg.(value & flag & info ["p"] ~doc:"show file paths") in let number = Arg.(value & opt (some int) (Some 10) & info ["n"] ~docv: "number" ~doc: "Number of entries to list")
let number = Arg.(value & opt (some int) (Some 10) & info ["n"] let authed = Arg.(value & opt (some string) None & info ["authored"] ~docv: "Comma-separated names" ~doc: "Texts by authors")
~docv:"number" ~doc:"number of entries to list") in let topics = Arg.(value & opt (some string) None & info ["topics"] ~docv: "Comma-separated topics" ~doc: "Texts with topics")
let authed = Arg.(value & opt (some string) None & info ["authored"] let dir = Arg.(value & pos 0 string "" & info [] ~docv: "Directory to index")
~docv:"comma-separated names" ~doc:"texts by authors") in
let topics = Arg.(value & opt (some string) None & info ["topics"] let recent_t = Term.(const Listing.listing $ recurse $ (const true) $ reverse $ number $ paths $ authed $ topics $ dir)
~docv:"comma-separated topics" ~doc:"texts with topics") in let cmd =
let dir = Arg.(value & pos 0 string "" & info [] let doc = "List recent texts" in
~docv:"directory to index") in let man = [
Term.(const Listing.listing $ recurse $ (const true) $ reverse $ number $ paths $ authed $ topics $ dir), `S Manpage.s_description;
Term.info "recent" ~doc:"list recent texts" ~man:[ `S "DESCRIPTION"; `P "List header information of most recent texts.";
`P "List header information of most recent texts. If -R is used, list header `P "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" ] in
let info = Cmd.info "recent" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info recent_t

View File

@@ -6,12 +6,16 @@ let topics r authors_opt =
let s = File_store.fold ~r ~predicate topic_union String_set.empty in let s = File_store.fold ~r ~predicate topic_union String_set.empty in
print_endline @@ String_set.to_string s print_endline @@ String_set.to_string s
open Ocmd open Cmdliner
let term = let recurse = Arg.(value & flag & info ["R"] ~doc: "Include texts in subdirectories")
let recurse = Arg.(value & flag & info ["R"] let authed = Arg.(value & opt (some string) None & info ["authored"] ~docv: "Comma-separated authors" ~doc: "Topics by authors")
~doc:"include texts in subdirectories") in let topics_t = Term.(const topics $ recurse $ authed)
let authed = Arg.(value & opt (some string) None & info ["authored"]
~docv:"comma-separated authors" ~doc:"topics by authors") in let cmd =
Term.(const topics $ recurse $ authed), let doc = "List topics" in
Term.info "topics" ~doc:"list topics" ~man:[ `S "DESCRIPTION"; let man = [
`S Manpage.s_description;
`P "List of topics" ] `P "List of topics" ]
in
let info = Cmd.info "topics" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info topics_t

View File

@@ -1,21 +1,31 @@
open Ocmd open Cmdliner
let default_cmd =
let doc = "Discover, collect & exchange texts" in
let man = [ `S "CONTACT"; `P "<mailto:logarion-dev@chaotic.ninja>" ] in
Term.(ret (const (`Help (`Pager, None)))), Term.info "txt" ~version:"%%VERSION%%" ~doc ~man
let () = match Term.eval_choice default_cmd [ let subs = [
Authors.term; Authors.cmd; (* Done *)
Convert.term; Convert.cmd; (* Done *)
Edit.term; Edit.cmd; (* Done *)
File.term; File.unfile_term; File.cmd; (* Done *)
Index.term; Index.cmd; (* Done *)
Last.term; Last.cmd; (* Done *)
Listing.term; Listing.cmd; (* Done *)
New.term; New.cmd; (* Done *)
Peers.term; Peers.cmd; (* Done *)
Pull.term; Pull.cmd; (* Done *)
Read.term; Read.cmd; (* Done *)
Recent.term; Recent.cmd; (* Done *)
Topics.term; Topics.cmd; (* Done *)
] with `Error _ -> exit 1 | _ -> exit 0 Unfile.cmd; (* Done *)
]
let default_cmd = Term.(ret (const (`Help (`Pager, None))))
let txt =
let doc = "Discover, collect and exchange texts" in
let man = [
`S "CONTACT";
`P "<mailto:logarion-dev@chaotic.ninja>"; ]
in
Cmd.group (Cmd.info "txt" ~version:"%%VERSION%%" ~doc ~man) ~default:default_cmd subs
let main () = exit (Cmd.eval txt)
let () = main ()

21
cli/unfile.ml Normal file
View File

@@ -0,0 +1,21 @@
open Logarion
let unfile files =
let dirs, files = File_store.split_filetypes files in
let unlink dir file = try Unix.unlink (Filename.concat dir file) with
Unix.(Unix_error(ENOENT,_,_))-> () in
List.iter (fun d -> List.iter (unlink d) files) dirs
open Cmdliner
let files = Arg.(value & pos_all string [] & info [] ~docv: "Text filenames and subdirectories")
let unfile_t = Term.(const unfile $ files)
let cmd =
let doc = "Unfile texts from subdirectories" in
let man = [
`S Manpage.s_description;
`P "Unfile texts in parameter from directories in parameter, by removing hardlinks" ]
in
let info = Cmd.info "unfile" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info unfile_t

View File

@@ -1,13 +1,13 @@
# This file is generated by dune, edit dune-project instead # This file is generated by dune, edit dune-project instead
opam-version: "2.0" opam-version: "2.0"
version: "1.3.2" version: "1.4.0"
synopsis: "Texts archival and exchange" synopsis: "Texts archival and exchange"
maintainer: ["Izuru Yakumo <yakumo.izuru@chaotic.ninja>"] maintainer: ["Izuru Yakumo <yakumo.izuru@chaotic.ninja>"]
authors: ["orbifx <fox@orbitalfox.eu>"] authors: ["orbifx <fox@orbitalfox.eu>"]
license: "EUPL-1.2" license: "EUPL-1.2"
homepage: "https://suzunaan.chaotic.ninja/logarion/" homepage: "https://suzunaan.chaotic.ninja/logarion/"
bug-reports: "mailto:logarion-dev@chaotic.ninja" bug-reports: "mailto:logarion-dev@chaotic.ninja"
depends: ["ocaml" "dune" "ocurl" "msgpck" "ocmd"] depends: ["ocaml" "dune" "ocurl" "msgpck" "cmdliner"]
build: [ build: [
["dune" "subst"] {pinned} ["dune" "subst"] {pinned}
[ [