source: code/trunk/cli/peers.ml@ 68

Last change on this file since 68 was 66, checked in by Izuru Yakumo, 8 months ago

Migrate the codebase to the latest revision of Cmdliner

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

File size: 1.5 KB
Line 
1let print_peers_of_peer p =
2 let open Logarion.Header_pack in
3 match Msgpck.to_list p.peers with [] -> ()
4 | ps -> print_endline @@
5 List.fold_left (fun a x -> Printf.sprintf "%s %s" a (Msgpck.to_string x)) "peers: " ps
6
7type filter_t = { authors: Logarion.Person.Set.t; topics: Logarion.String_set.t }
8
9let print_peer () peer =
10 let open Logarion.Peers in
11 Printf.printf "%s" peer.path;
12 List.iter (Printf.printf "\t%s\n") peer.pack.info.locations
13
14let remove_repo id =
15 let repopath = Filename.concat Logarion.Peers.text_dir id in
16 match Sys.is_directory repopath with
17 | false -> Printf.eprintf "No repository %s in %s" id Logarion.Peers.text_dir
18 | true ->
19 let cmd = Printf.sprintf "rm -r %s" repopath in
20 Printf.printf "Run: %s ? (y/N) %!" cmd;
21 match input_char stdin with
22 |'y'-> if Sys.command cmd = 0 then print_endline "Removed" else prerr_endline "Failed"
23 | _ -> ()
24
25let peers = function
26 | Some id -> remove_repo id
27 | None ->
28 Printf.printf "Peers in %s\n" Logarion.Peers.text_dir;
29 Logarion.Peers.fold print_peer ()
30
31open Cmdliner
32let remove = Arg.(value & opt (some string) None & info ["remove"] ~docv:"Repository ID" ~doc:"Remove repository texts and from future pulling")
33let peers_t = Term.(const peers $ remove)
34
35let cmd =
36 let doc = "List current peers" in
37 let man = [
38 `S Manpage.s_description;
39 `P "List current peers and associated information" ]
40 in
41 let info = Cmd.info "peers" ~version:"%%VERSION%%" ~doc ~man in
42 Cmd.v info peers_t
Note: See TracBrowser for help on using the repository browser.