X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=lightcards%2Frunner.py;h=40b5b15f25673e0f2c4599ebb950249a35f98977;hb=HEAD;hp=15a622983235a671fd6b330b7efe75a6bd42dc55;hpb=79afb3261a260272d0c3975eac67872a1c0b25df;p=lightcards.git diff --git a/lightcards/runner.py b/lightcards/runner.py index 15a6229..40b5b15 100644 --- a/lightcards/runner.py +++ b/lightcards/runner.py @@ -8,7 +8,7 @@ from random import shuffle import sys from . import parse, progress, config -from .display import Display, CursesError +from .display import Display from .deck import Status @@ -20,19 +20,33 @@ def parse_args(): parser.add_argument( "-c", "--config", + metavar="config_file", type=str, + default="/dev/null", help="specify custom config file", ) parser.add_argument( "-V", "--view", - metavar="view", + metavar="1-3", type=int, choices=range(1, 4), - default=1, - help="specify which view to start in (default = 1)", + help="specify which view to start in", + ) + parser.add_argument("inp", metavar="input_files", type=str, nargs="+") + parser.add_argument( + "-l", + "--lenient", + action="store_true", + help="don't raise exception if tables are malformed", + ) + parser.add_argument( + "-t", + "--table", + metavar="num_table", + type=int, + help="specify which table to use if multiple are given", ) - parser.add_argument("inp", metavar="input file", type=str, nargs=1) parser.add_argument( "-a", "--alphabetize", @@ -43,7 +57,7 @@ def parse_args(): "-p", "--purge", action="store_true", - help="don't check cached info before starting", + help="delete cache before starting", ) parser.add_argument( "-r", "--reverse", action="store_true", help="reverse card order" @@ -72,23 +86,29 @@ def show(args, stack, headers, conf): # Check for caches idx = Status() cache = progress.dive(get_orig()[1]) - if cache: + if cache and conf["cache"]: (stack) = cache # Manipulate deck - if args.shuffle: + if args.shuffle or conf["shuffle"]: shuffle(stack) - if args.alphabetize: + if args.alphabetize or conf["alphabetize"]: stack.sort(key=lambda x: x.front) - if args.reverse: + if args.reverse or conf["reverse"]: stack.reverse() + # Set view + if args.view: + view = args.view + else: + view = conf["default_view"] + # Send to display - win = Display(stack, headers, idx, args.view, args, conf) + win = Display(stack, headers, idx, view, args, conf) try: curses.wrapper(win.run) except curses.error as e: - raise CursesError() from e + raise e def get_orig(): @@ -98,13 +118,14 @@ def get_orig(): def main(args=sys.argv): args = parse_args() - global headers, stack - (headers, stack) = parse.parse_html(parse.md2html(args.inp[0])) conf = config.read_file(args.config) if not conf["debug"]: sys.tracebacklimit = 0 + global headers, stack + (headers, stack) = parse.parse_html(parse.md2html(args.inp), args, conf) + show(args, stack, headers, conf)