annotate pytouhou/options.py @ 567:b2269b9c6119

Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 01 Jul 2014 23:17:40 +0200
parents 5f7f859a72f9
children e7a4731a278b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 ##
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 ## Copyright (C) 2014 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 ##
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 ##
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 ## GNU General Public License for more details.
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ##
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14
567
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
15 import os
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
16 from ConfigParser import RawConfigParser, NoOptionError
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
17
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
18 from pytouhou.utils.xdg import load_config_paths
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
19
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
20
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
21 class Options(object):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
22 def __init__(self, name, defaults):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
23 load_paths = list(reversed([os.path.join(directory, '%s.cfg' % name)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
24 for directory
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
25 in load_config_paths(name)]))
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
26
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
27 self.config = RawConfigParser(defaults)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
28 self.paths = self.config.read(load_paths)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
29 self.section = name if self.config.has_section(name) else 'DEFAULT'
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
30
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
31 def get(self, option):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
32 try:
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
33 return self.config.get(self.section, option)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
34 except NoOptionError:
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
35 return None
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
36
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
37
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
38 def patch_argument_parser():
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
39 from argparse import ArgumentParser, _ActionsContainer
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
40
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
41 original_method = _ActionsContainer.add_argument
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
42
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
43 def add_argument(self, *args, **kwargs):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
44 if 'default' not in kwargs:
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
45 dest = kwargs.get('dest')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
46 if dest is None:
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
47 for dest in args:
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
48 dest = dest.lstrip('-')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
49 value = self.default.get(dest)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
50 if value is not None:
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
51 break
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
52 else:
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
53 dest = dest.replace('_', '-')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
54 value = self.default.get(dest)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
55 if value is not None:
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
56 argument_type = kwargs.get('type')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
57 if argument_type is not None:
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
58 value = argument_type(value)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
59 action = kwargs.get('action')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
60 if action == 'store_true':
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
61 value = value.lower() == 'true'
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
62 elif action == 'store_false':
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
63 value = value.lower() != 'true'
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
64 if kwargs.get('nargs') == '*' and isinstance(value, str):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
65 value = value.split()
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
66 kwargs['default'] = value
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
67 elif dest == 'double-buffer':
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
68 kwargs['default'] = None
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
69 return original_method(self, *args, **kwargs)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
70 _ActionsContainer.add_argument = add_argument
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
71
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
72 class Parser(ArgumentParser):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
73 def __init__(self, *args, **kwargs):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
74 self.default = kwargs.pop('default')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
75 ArgumentParser.__init__(self, *args, **kwargs)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
76
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
77 def add_argument_group(self, *args, **kwargs):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
78 group = ArgumentParser.add_argument_group(self, *args, **kwargs)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
79 group.default = self.default
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
80 group.add_argument_group = self.add_argument_group
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
81 group.add_mutually_exclusive_group = self.add_mutually_exclusive_group
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
82 return group
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
83
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
84 def add_mutually_exclusive_group(self, *args, **kwargs):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
85 group = ArgumentParser.add_mutually_exclusive_group(self, *args, **kwargs)
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
86 group.default = self.default
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
87 group.add_argument_group = self.add_argument_group
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
88 group.add_mutually_exclusive_group = self.add_mutually_exclusive_group
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
89 return group
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
90
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
91 return Parser
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
92
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
93
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
94 ArgumentParser = patch_argument_parser()
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
95
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
96
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
97 def parse_config(section, defaults):
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
98 return Options(section, defaults)
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 def parse_arguments(defaults):
567
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
102 parser = ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.', default=defaults)
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103
567
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
104 parser.add_argument('data', metavar='DAT', nargs='*', help='Game’s data files')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
105 parser.add_argument('-p', '--path', metavar='DIRECTORY', help='Game directory path.')
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 parser.add_argument('--debug', action='store_true', help='Set unlimited continues, and perhaps other debug features.')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 parser.add_argument('--verbosity', metavar='VERBOSITY', choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Select the wanted logging level.')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 game_group = parser.add_argument_group('Game options')
567
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
110 game_group.add_argument('-s', '--stage', metavar='STAGE', type=int, help='Stage, 1 to 7 (Extra), nothing means story mode.')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
111 game_group.add_argument('-r', '--rank', metavar='RANK', type=int, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
112 game_group.add_argument('-c', '--character', metavar='CHARACTER', type=int, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 game_group.add_argument('-b', '--boss-rush', action='store_true', help='Fight only bosses.')
567
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
114 game_group.add_argument('--game', metavar='GAME', choices=['EoSD'], help='Select the game engine to use.')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
115 game_group.add_argument('--interface', metavar='INTERFACE', choices=['EoSD', 'Sample'], help='Select the interface to use.')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
116 game_group.add_argument('--hints', metavar='HINTS', help='Hints file, to display text while playing.')
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 replay_group = parser.add_argument_group('Replay options')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 replay_group.add_argument('--replay', metavar='REPLAY', help='Select a file to replay.')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120 replay_group.add_argument('--save-replay', metavar='REPLAY', help='Save the upcoming game into a replay file.')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 replay_group.add_argument('--skip-replay', action='store_true', help='Skip the replay and start to play when it’s finished.')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 netplay_group = parser.add_argument_group('Netplay options')
567
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
124 netplay_group.add_argument('--port', metavar='PORT', type=int, help='Local port to use.')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
125 netplay_group.add_argument('--remote', metavar='REMOTE', help='Remote address.')
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 netplay_group.add_argument('--friendly-fire', action='store_true', help='Allow friendly-fire during netplay.')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 graphics_group = parser.add_argument_group('Graphics options')
567
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
129 graphics_group.add_argument('--backend', metavar='BACKEND', choices=['opengl', 'sdl'], nargs='*', help='Which backend to use (opengl or sdl).')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
130 graphics_group.add_argument('--fps-limit', metavar='FPS', type=int, help='Set fps limit. A value of 0 disables fps limiting, while a negative value limits to 60 fps if and only if vsync doesn’t work.')
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 graphics_group.add_argument('--no-background', action='store_false', help='Disable background display (huge performance boost on slow systems).')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 graphics_group.add_argument('--no-particles', action='store_false', help='Disable particles handling (huge performance boost on slow systems).')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 graphics_group.add_argument('--no-sound', action='store_false', help='Disable music and sound effects.')
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 opengl_group = parser.add_argument_group('OpenGL backend options')
567
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
136 opengl_group.add_argument('--gl-flavor', choices=['core', 'es', 'compatibility', 'legacy'], help='OpenGL profile to use.')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
137 opengl_group.add_argument('--gl-version', type=float, help='OpenGL version to use.')
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 double_buffer = opengl_group.add_mutually_exclusive_group()
567
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
140 double_buffer.add_argument('--double-buffer', dest='double_buffer', action='store_true', help='Enable double buffering.')
b2269b9c6119 Add a configuration parser, and pass those options to argparse as defaults. Also include an xdg helper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 565
diff changeset
141 double_buffer.add_argument('--single-buffer', dest='double_buffer', action='store_false', help='Disable double buffering.')
565
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142
5f7f859a72f9 Move CLI options to their own module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143 return parser.parse_args()