@ -25,7 +25,7 @@ let converters types kv =
Conversion . { ext = Gemini . ext ; page = Gemini . page ; indices = Gemini . indices } :: t else t in
t
let convert_all converters noindex dir id kv =
let directory converters noindex dir id kv =
let empty = Topic_set . Map . empty in
let repo = Conversion . { id ; dir ; kv ; topic_roots = [] ; topics = empty ; texts = [] } in
let fn ( ts , ls , acc ) ( ( elt , _ ) as r ) =
@ -38,11 +38,11 @@ let convert_all converters noindex dir id kv =
if not noindex then List . iter ( fun c -> c . Conversion . indices repo ) converters ;
Printf . printf " Converted: %d Indexed: %d \n " count ( List . length texts )
let convert_dir types noindex dir =
match dir with " " -> prerr_endline " unspecified dir"
| dir ->
let at_path types noindex path =
match path with " " -> prerr_endline " unspecified text file or directory "
| dir when Sys . file_exists dir && Sys . is_directory dir ->
let fname = Filename . concat dir " index.pck " in
match Header_pack . of_string @@ File_store . to_string fname with
( match Header_pack . of_string @@ File_store . to_string fname with
| Error s -> prerr_endline s
| Ok { info ; _ } ->
let kv = let f = Filename . concat dir " .convert.conf " in (* TODO: better place to store convert conf? *)
@ -51,17 +51,26 @@ let convert_dir types noindex dir =
else Store . KV . add " Title " info . Header_pack . title kv in
let kv = Store . KV . add " Locations " ( String . concat " ; \n " info . Header_pack . locations ) kv in
let cs = converters types kv in
convert_all cs noindex dir info . Header_pack . id kv
directory cs noindex dir info . Header_pack . id kv )
| path when Sys . file_exists path ->
let repo = Conversion . {
id = " " ; dir = " " ; kv = Store . KV . empty ; topic_roots = [] ;
topics = Topic_set . Map . empty ; texts = [] } in
let cs = converters types repo . kv in
( match File_store . to_text path with
| Ok text -> ignore @@ convert cs repo ( text , [ path ] )
| Error s -> prerr_endline s )
| path -> Printf . eprintf " Path doesn't exist: %s " path
open Cmdliner
let term =
let directory = Arg . ( value & pos 0 string " " & info [] ~ docv : " target directory "
~ doc : " Directory to convert " ) in
let types = Arg . ( value & opt string " all " & info [ " t " ; " type " ] ~ docv : " TYPES "
~ doc : " Convert to type " ) in
let path = Arg . ( value & pos 0 string " " & info [] ~ docv : " path "
~ doc : " Text file or directory to convert. Ff 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" ) in
let noindex = Arg . ( value & flag & info [ " noindex " ]
~ doc : " don't create indices in target format " ) in
Term . ( const convert_dir $ types $ noindex $ directory ) ,
~ doc : " D on't create indices in target format" ) in
Term . ( const at_path $ types $ noindex $ path ) ,
Term . info " convert " ~ doc : " convert texts "
~ man : [ ` S " DESCRIPTION " ; ` P " Convert text s within a directory to another format.
D irectory must contain an index . pck . Run ` txt index ` first . " ]
~ man : [ ` S " DESCRIPTION " ; ` P " Convert text or indexed text s within a directory to another format.
If path is a d irectory must contain an index . pck . Run ` txt index ` first . " ]