Mercurial > nagslang
view nagslang/options.py @ 341:63d0c70a4e15
Enemies can hurt things again. (Oops.)
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Fri, 06 Sep 2013 12:55:48 +0200 |
parents | 004e3dd38336 |
children | 044b53eb22df |
line wrap: on
line source
import optparse import os from nagslang.constants import DEFAULTS class AttrDict(dict): '''A dict with attribute access''' def __getattr__(self, attr): return self[attr] options = AttrDict() def parse_args(args): ''' Parse arguments and store them in the options dictionary. Note: If you add arguments, you need to add an appropriate default to the DEFAULTS dict. ''' options.update(DEFAULTS) options.debug = 'DEBUG' in os.environ parser = optparse.OptionParser() parser.add_option('--no-sound', dest='sound', action='store_false', default=True, help='Disable all sound, including music') parser.add_option('--no-music', dest='music', action='store_false', default=True, help='Disable music (but not sound)') if options.debug: parser.add_option('--area', help='Initial area') opts, _ = parser.parse_args(args) for k in DEFAULTS: if getattr(opts, k, None) is not None: options[k] = getattr(opts, k)