source: code/trunk/cli/publish.ml@ 27

Last change on this file since 27 was 27, checked in by fox, 2 years ago

Improve pubdir parameter reporting

File size: 1.6 KB
Line 
1let targets pubdir = List.fold_left
2 (fun a x ->
3 let path = Filename.concat pubdir (snd x) in
4 try if Sys.is_directory path then (fst x, path)::a else a with Sys_error _ -> a)
5 []
6 ["htm,atom", "public_html/"; "gmi,gmi-atom", "public_gemini/"; "", "public_gopher/"]
7
8open Logarion
9let publish pubdir ids =
10 let kv = Logarion.File_store.of_kv_file () in
11 let predicate t = List.mem t.Text.id ids in
12 let pubdir_source, pubdir = match pubdir with Some d -> "--pubdir ", d | None ->
13 try "txt.conf:Pubdir", Logarion.Store.KV.find "Pubdir" kv with Not_found ->
14 try "$txtpubdir", Sys.getenv "txtpubdir" with Not_found -> "$txtpubdir", ""
15 in
16 let targets = targets pubdir in
17 if targets = [] then
18 Printf.eprintf "No target directories in %s='%s'\n" pubdir_source pubdir
19 else begin
20 let pub_dirs = List.map (fun x -> snd x) targets in
21 File_store.iter ~predicate (fun (_t, p) ->
22 try File.file ((List.hd p)::pub_dirs)
23 with Unix.Unix_error (Unix.EEXIST, _, _) -> ());
24 List.iter (fun t -> Printf.eprintf "%s %s\n" (fst t) (snd t);
25 Index.((load (snd t)) false None None None None);
26 Convert.at_path (fst t) false (snd t))
27 targets
28 end
29
30open Cmdliner
31let term =
32 let ids = Arg.(value & pos_all string [] & info [] ~docv:"text ids") in
33 let pubdir = Arg.(value & opt (some string) None & info ["p"; "pubdir"] ~docv:"directory path"
34 ~doc:"set top directory for publishing files") in
35 let doc = "convert texts into standard public dirs pubdir/public_{html,gemini,gopher} if they exist" in
36 Term.(const publish $ pubdir $ ids), Term.info "publish" ~doc ~man:[ `S "DESCRIPTION"; `P doc ]
Note: See TracBrowser for help on using the repository browser.