diff options
| author | 2021-08-10 10:06:31 -0400 | |
|---|---|---|
| committer | 2021-08-10 10:06:31 -0400 | |
| commit | 547e5824e995c65d016c4aa5f562ffb36a9f154c (patch) | |
| tree | e0e142c32fa9f56e45c45ef3da4290efaf3e1476 | |
| parent | add command line arguments parser (diff) | |
generate database from command line arguments
| -rw-r--r-- | elements.ml | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/elements.ml b/elements.ml index ad99740..a2877fb 100644 --- a/elements.ml +++ b/elements.ml @@ -4,7 +4,7 @@ module Opts = struct type lasttype = NAME | SYMB let ltype = ref NAME - let gendb = ref "" + let jsonf = ref "" let maxmatch = ref 3 let match_name : 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\ " + let setfile name v f = + if f = "" then raise + (Bad (Printf.sprintf "%s requires a filename" name)) + else v := f + 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)"; - "-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)"; "-symb", String add_symb, "Search by symbol" ] @@ -37,3 +42,11 @@ module Opts = struct end 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 + ) |
