aboutsummaryrefslogtreecommitdiffstats
path: root/elements.ml
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2021-08-10 09:21:23 -0400
committerGravatar Peter McGoron 2021-08-10 09:21:23 -0400
commitd56e7718878595c9ce44040338cde72d76d1f9f6 (patch)
tree8a71fc012f331fb901b14b6dfeac044270f12577 /elements.ml
parentmakedb: properly add cache (diff)
add command line arguments parser
Diffstat (limited to '')
-rw-r--r--elements.ml41
1 files changed, 39 insertions, 2 deletions
diff --git a/elements.ml b/elements.ml
index 518a705..ad99740 100644
--- a/elements.ml
+++ b/elements.ml
@@ -1,2 +1,39 @@
-let () = Makedb.makedb (Sqlite3.db_open "elements.sqlite3")
- (Yojson.Basic.from_channel stdin)
+module Opts = struct
+ open Arg
+
+ type lasttype = NAME | SYMB
+
+ let ltype = ref NAME
+ let gendb = ref ""
+ let maxmatch = ref 3
+ let match_name : string list ref = ref []
+ let match_symb : string list ref = ref []
+ let dbfile = ref "elements.sqlite3"
+
+ let add_name s =
+ match_name := s::!match_name;
+ ltype := NAME
+ let add_symb s =
+ match_symb := s::!match_symb;
+ ltype := SYMB
+ let add_def s = match !ltype with
+ | NAME -> add_name s
+ | SYMB -> add_symb s
+
+ let msg = "Periodic table search\n\
+ elements -gendb file [-dbfile outfile]\n\
+ elements [-maxmatch n] [-dbfile search] [-name ...] [-symb ...]\n\
+ "
+
+ let spec = [
+ "-gendb", Set_string gendb, "Generate DB file";
+ "-maxmatch", Set_int maxmatch, "Limit the amount of matches (def. 3)";
+ "-dbfile", Set_string dbfile, "Set the DB filename";
+ "-name", String add_name, "Search by name (default)";
+ "-symb", String add_symb, "Search by symbol"
+ ]
+
+ let exec() = parse spec add_def msg
+end
+
+let () = Opts.exec()