Improved argument parsing.

Made launch arguments override the config's values. Added a --normal
switch for overriding both debug and verbose parameters if present.
This commit is contained in:
Vgr E.Barry 2015-01-03 19:49:58 -05:00
parent 11b35c79ff
commit 932d9f45f4

View File

@ -8,17 +8,13 @@ from settings import wolfgame as var
# Argument --debug means start in debug mode # Argument --debug means start in debug mode
# --verbose means to print a lot of stuff (when not in debug mode) # --verbose means to print a lot of stuff (when not in debug mode)
# --normal means to override the above and use nothing
# Settings can be defined in the config, but launch argumentss override it
parser = argparse.ArgumentParser() debug_mode = False
parser.add_argument('--debug', action='store_true') verbose = False
parser.add_argument('--sabotage', action='store_true') sabotage = False
parser.add_argument('--verbose', action='store_true') normal = False
args = parser.parse_args()
debug_mode = args.debug
verbose = args.verbose
sabotage = args.sabotage
# Carry over settings from botconfig into settings/wolfgame.py # Carry over settings from botconfig into settings/wolfgame.py
@ -31,14 +27,29 @@ for setting, value in botconfig.__dict__.items():
verbose = value verbose = value
if setting == "DEFAULT_MODULE": if setting == "DEFAULT_MODULE":
sabotage = value sabotage = value
if setting == "NORMAL_MODE":
normal = value
if not setting in var.__dict__.keys(): if not setting in var.__dict__.keys():
continue # Don't carry over config-only settings continue # Don't carry over config-only settings
# If we got that far, it's valid # If we got that far, it's valid
setattr(var, setting, value) setattr(var, setting, value)
botconfig.DEBUG_MODE = debug_mode if not botconfig.DISABLE_DEBUG_MODE else False parser = argparse.ArgumentParser()
botconfig.VERBOSE_MODE = verbose parser.add_argument('--debug', action='store_true')
parser.add_argument('--sabotage', action='store_true')
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--normal', action='store_true')
args = parser.parse_args()
if args.debug: debug_mode = True
if args.verbose: verbose = True
if args.sabotage: sabotage = True
if args.normal: normal = True
botconfig.DEBUG_MODE = debug_mode if not botconfig.DISABLE_DEBUG_MODE and not normal else False
botconfig.VERBOSE_MODE = verbose if not normal else False
botconfig.DEFAULT_MODULE = "sabotage" if args.sabotage else "wolfgame" botconfig.DEFAULT_MODULE = "sabotage" if args.sabotage else "wolfgame"