diff --git a/setup.cfg b/setup.cfg index 60fd44e..e8eda2f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = ProcruSQL -version = 0.0.2 +version = 0.0.3 author = Peter J. Holzer author_email = hjp@hjp.at description = Make a database fit its description diff --git a/src/procrusql/__init__.py b/src/procrusql/__init__.py index 0d5c736..52c6625 100644 --- a/src/procrusql/__init__.py +++ b/src/procrusql/__init__.py @@ -1,3 +1,4 @@ +import argparse import logging import sys @@ -247,16 +248,26 @@ def dump_dot(): def main(): logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s %(lineno)d | %(message)s", level=logging.DEBUG) - with open(sys.argv[1]) as rf: - text = rf.read() - ps = parser.ParseState(text) + ap = argparse.ArgumentParser() + ap.add_argument("--dbname") + ap.add_argument("--dbuser") + ap.add_argument("files", nargs="+") + args = ap.parse_args() - ps2 = parser.parse_ruleset(ps) + db = psycopg2.connect(dbname=args.dbname, user=args.dbuser) - if not ps2: - ps.printerror() - sys.exit(1) + rules = [] + for f in args.files: + with open(f) as rf: + text = rf.read() + ps = parser.ParseState(text) - db = psycopg2.connect(sys.argv[2]) - fit(db, ps2.ast) + ps2 = parser.parse_ruleset(ps) + + if not ps2: + ps.printerror() + sys.exit(1) + rules.extend(ps2.ast) + + fit(db, rules)