Use ArgumentParser instead of OptionParser.
Chris Pressey
5 years ago
12 | 12 | # ----------------------------------------------------------------- # |
13 | 13 | |
14 | 14 | import codecs |
15 | from optparse import OptionParser | |
15 | from argparse import ArgumentParser | |
16 | 16 | from pprint import pprint |
17 | 17 | import sys |
18 | 18 | import traceback |
24 | 24 | |
25 | 25 | |
26 | 26 | if __name__ == '__main__': |
27 | optparser = OptionParser(__doc__.strip()) | |
27 | argparser = ArgumentParser(__doc__.strip()) | |
28 | 28 | |
29 | optparser.add_option("--analyze-only", | |
30 | action="store_true", | |
31 | help="Only parse and analyze the program; do not compile it.") | |
32 | optparser.add_option("--basic-prelude", | |
33 | action="store_true", | |
34 | help="Insert a Commodore BASIC 2.0 snippet before the program " | |
35 | "so that it can be LOADed and RUN on Commodore platforms.") | |
36 | optparser.add_option("--debug", | |
37 | action="store_true", | |
38 | help="Display debugging information when analyzing and compiling.") | |
39 | optparser.add_option("--parse-only", | |
40 | action="store_true", | |
41 | help="Only parse the program; do not analyze or compile it.") | |
42 | optparser.add_option("--traceback", | |
43 | action="store_true", | |
44 | help="When an error occurs, display a full Python traceback.") | |
29 | argparser.add_argument( | |
30 | 'filenames', metavar='FILENAME', type=str, nargs='+', | |
31 | help="The SixtyPical source files to compile." | |
32 | ) | |
33 | argparser.add_argument( | |
34 | "--analyze-only", | |
35 | action="store_true", | |
36 | help="Only parse and analyze the program; do not compile it." | |
37 | ) | |
38 | argparser.add_argument( | |
39 | "--basic-prelude", | |
40 | action="store_true", | |
41 | help="Insert a Commodore BASIC 2.0 snippet before the program " | |
42 | "so that it can be LOADed and RUN on Commodore platforms." | |
43 | ) | |
44 | argparser.add_argument( | |
45 | "--debug", | |
46 | action="store_true", | |
47 | help="Display debugging information when analyzing and compiling." | |
48 | ) | |
49 | argparser.add_argument( | |
50 | "--parse-only", | |
51 | action="store_true", | |
52 | help="Only parse the program; do not analyze or compile it." | |
53 | ) | |
54 | argparser.add_argument( | |
55 | "--traceback", | |
56 | action="store_true", | |
57 | help="When an error occurs, display a full Python traceback." | |
58 | ) | |
45 | 59 | |
46 | (options, args) = optparser.parse_args(sys.argv[1:]) | |
60 | options, unknown = argparser.parse_known_args(sys.argv[1:]) | |
61 | remainder = ' '.join(unknown) | |
47 | 62 | |
48 | for filename in args: | |
63 | for filename in options.filenames: | |
49 | 64 | text = open(filename).read() |
50 | 65 | |
51 | 66 | try: |