diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-01-08 13:36:21 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-01-08 15:23:16 +0100 |
commit | 79ed2e0f088d0b374f5dbed12051770236268238 (patch) | |
tree | 96b8cb9e94425115759aaa97f324c2ac0c5c4a2b /gbp/config.py | |
parent | fc1d47d222e76e1c89b8c022f7f285bddbc17f96 (diff) |
Use tristate option for --color=value
this allows true and false as alias for on and off.
Diffstat (limited to 'gbp/config.py')
-rw-r--r-- | gbp/config.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/gbp/config.py b/gbp/config.py index c989afe..e623c3b 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -3,7 +3,7 @@ # (C) 2006,2007,2010 Guido Guenther <agx@sigxcpu.org> """handles command line and config file option parsing for the gbp commands""" -from optparse import OptionParser, OptionGroup, Option +from optparse import OptionParser, OptionGroup, Option, OptionValueError from ConfigParser import SafeConfigParser from copy import copy import os.path @@ -11,15 +11,26 @@ try: from gbp.gbp_version import gbp_version except ImportError: gbp_version = "[Unknown version]" +import gbp.tristate def expand_path(option, opt, value): value = os.path.expandvars(value) return os.path.expanduser(value) +def check_tristate(option, opt, value): + try: + val = gbp.tristate.Tristate(value) + except TypeError: + raise OptionValueError( + "option %s: invalid value: %r" % (opt, value)) + else: + return val + class GbpOption(Option): - TYPES = Option.TYPES + ('path',) + TYPES = Option.TYPES + ('path', 'tristate') TYPE_CHECKER = copy(Option.TYPE_CHECKER) TYPE_CHECKER['path'] = expand_path + TYPE_CHECKER['tristate'] = check_tristate class GbpOptionParser(OptionParser): """ |