generate database from command line arguments
This commit is contained in:
parent
d56e771887
commit
547e5824e9
19
elements.ml
19
elements.ml
|
@ -4,7 +4,7 @@ module Opts = struct
|
||||||
type lasttype = NAME | SYMB
|
type lasttype = NAME | SYMB
|
||||||
|
|
||||||
let ltype = ref NAME
|
let ltype = ref NAME
|
||||||
let gendb = ref ""
|
let jsonf = ref ""
|
||||||
let maxmatch = ref 3
|
let maxmatch = ref 3
|
||||||
let match_name : string list ref = ref []
|
let match_name : string list ref = ref []
|
||||||
let match_symb : string list ref = ref []
|
let match_symb : string list ref = ref []
|
||||||
|
@ -25,10 +25,15 @@ module Opts = struct
|
||||||
elements [-maxmatch n] [-dbfile search] [-name ...] [-symb ...]\n\
|
elements [-maxmatch n] [-dbfile search] [-name ...] [-symb ...]\n\
|
||||||
"
|
"
|
||||||
|
|
||||||
|
let setfile name v f =
|
||||||
|
if f = "" then raise
|
||||||
|
(Bad (Printf.sprintf "%s requires a filename" name))
|
||||||
|
else v := f
|
||||||
|
|
||||||
let spec = [
|
let spec = [
|
||||||
"-gendb", Set_string gendb, "Generate DB file";
|
"-gendb", String (setfile "-gendb" jsonf), "Generate DB file";
|
||||||
"-maxmatch", Set_int maxmatch, "Limit the amount of matches (def. 3)";
|
"-maxmatch", Set_int maxmatch, "Limit the amount of matches (def. 3)";
|
||||||
"-dbfile", Set_string dbfile, "Set the DB filename";
|
"-dbfile", String (setfile "-dbfile" dbfile), "Set the DB filename";
|
||||||
"-name", String add_name, "Search by name (default)";
|
"-name", String add_name, "Search by name (default)";
|
||||||
"-symb", String add_symb, "Search by symbol"
|
"-symb", String add_symb, "Search by symbol"
|
||||||
]
|
]
|
||||||
|
@ -37,3 +42,11 @@ module Opts = struct
|
||||||
end
|
end
|
||||||
|
|
||||||
let () = Opts.exec()
|
let () = Opts.exec()
|
||||||
|
|
||||||
|
let db = Sqlite3.db_open !Opts.dbfile
|
||||||
|
if !Opts.jsonf <> "" then
|
||||||
|
Makedb.makedb db (if !Opts.jsonf = "-" then
|
||||||
|
Yojson.Basic.from_channel stdin
|
||||||
|
else
|
||||||
|
Yojson.Basic.from_file !Opts.jsonf
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue