From dbba7cc7b9ce9cac276a035f3e530b728ffc20bf Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Tue, 6 Mar 2018 16:28:34 +0000 Subject: [PATCH] Use ArgumentParser instead of OptionParser. --- bin/sixtypical | 55 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/bin/sixtypical b/bin/sixtypical index 62b3c6a..e084d13 100755 --- a/bin/sixtypical +++ b/bin/sixtypical @@ -13,7 +13,7 @@ sys.path.insert(0, join(dirname(realpath(sys.argv[0])), '..', 'src')) # ----------------------------------------------------------------- # import codecs -from optparse import OptionParser +from argparse import ArgumentParser from pprint import pprint import sys import traceback @@ -25,28 +25,43 @@ from sixtypical.compiler import Compiler if __name__ == '__main__': - optparser = OptionParser(__doc__.strip()) + argparser = ArgumentParser(__doc__.strip()) - optparser.add_option("--analyze-only", - action="store_true", - help="Only parse and analyze the program; do not compile it.") - optparser.add_option("--basic-prelude", - action="store_true", - help="Insert a Commodore BASIC 2.0 snippet before the program " - "so that it can be LOADed and RUN on Commodore platforms.") - optparser.add_option("--debug", - action="store_true", - help="Display debugging information when analyzing and compiling.") - optparser.add_option("--parse-only", - action="store_true", - help="Only parse the program; do not analyze or compile it.") - optparser.add_option("--traceback", - action="store_true", - help="When an error occurs, display a full Python traceback.") + argparser.add_argument( + 'filenames', metavar='FILENAME', type=str, nargs='+', + help="The SixtyPical source files to compile." + ) + argparser.add_argument( + "--analyze-only", + action="store_true", + help="Only parse and analyze the program; do not compile it." + ) + argparser.add_argument( + "--basic-prelude", + action="store_true", + help="Insert a Commodore BASIC 2.0 snippet before the program " + "so that it can be LOADed and RUN on Commodore platforms." + ) + argparser.add_argument( + "--debug", + action="store_true", + help="Display debugging information when analyzing and compiling." + ) + argparser.add_argument( + "--parse-only", + action="store_true", + help="Only parse the program; do not analyze or compile it." + ) + argparser.add_argument( + "--traceback", + action="store_true", + help="When an error occurs, display a full Python traceback." + ) - (options, args) = optparser.parse_args(sys.argv[1:]) + options, unknown = argparser.parse_known_args(sys.argv[1:]) + remainder = ' '.join(unknown) - for filename in args: + for filename in options.filenames: text = open(filename).read() try: