import argparse
from meak.interpreter import MeakInterpreter

def main():
    parser = argparse.ArgumentParser(prog="meak", description="meak: rigorous math DSL (exact rationals)")
    parser.add_argument("file", nargs="?", help="Run a .meak script file")
    parser.add_argument("-c", "--code", help="Run a single line of meak code")
    parser.add_argument("--version", action="store_true", help="Show version and exit")
    args = parser.parse_args()

    if args.version:
        print("meak 0.1.0")
        return 0

    itp = MeakInterpreter()

    if args.code is not None:
        outs = itp.run_line(args.code)
        for o in outs:
            print(o)
        return 0

    if args.file:
        outs = itp.run_file(args.file)
        for o in outs:
            print(o)
        return 0

    # default: REPL
    itp.repl()
    return 0

if __name__ == "__main__":
    raise SystemExit(main())