comparison eclviewer.py @ 186:84da28ae7ee4

Parse command line with argparse.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 26 Oct 2011 15:03:50 -0700
parents 959c8b312918
children 46793ccfedca
comparison
equal deleted inserted replaced
185:68e6d3faeee6 186:84da28ae7ee4
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details. 13 ## GNU General Public License for more details.
14 ## 14 ##
15 15
16 import sys 16 import argparse
17 import os 17 import os
18 18
19 import pyximport 19 import pyximport
20 pyximport.install() 20 pyximport.install()
21 21
44 # Main loop 44 # Main loop
45 runner = GameRunner(resource_loader, game, background) 45 runner = GameRunner(resource_loader, game, background)
46 runner.start() 46 runner.start()
47 47
48 48
49 try: 49 parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.')
50 file_path, stage_num, rank, character = sys.argv[1:]
51 stage_num = int(stage_num)
52 rank = int(rank)
53 character = int(character)
54 except ValueError:
55 print('Usage: %s game_dir_path stage_num rank character' % sys.argv[0])
56 else:
57 main(file_path, stage_num, rank, character)
58 50
51 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
52 parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).')
53 parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
54 parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
55
56 args = parser.parse_args()
57
58 main(args.path, args.stage, args.rank, args.character)