diff options
-rw-r--r-- | configuration.py | 7 | ||||
-rw-r--r-- | optik_ext.py | 6 | ||||
-rw-r--r-- | test/unittest_configuration.py | 8 |
3 files changed, 14 insertions, 7 deletions
diff --git a/configuration.py b/configuration.py index ac27166..6f9d9af 100644 --- a/configuration.py +++ b/configuration.py @@ -395,6 +395,13 @@ class OptionsManagerMixIn(object): use with optik/optparse """ opt_dict = copy(opt_dict) + # if yn option then create right action depending of default value + if "type" in opt_dict and opt_dict['type'] == "yn": + if "default" in opt_dict and opt_dict['default']: + opt_dict['action'] = "store_false" + else: + opt_dict['action'] = "store_true" + del opt_dict['type'] if 'action' in opt_dict: self._nocallback_options[provider] = opt_name else: diff --git a/optik_ext.py b/optik_ext.py index 123a2a6..ffaf1ba 100644 --- a/optik_ext.py +++ b/optik_ext.py @@ -78,13 +78,13 @@ def check_yn(option, opt, value): """check a yn value return true for yes and false for no """ - if isinstance(value, int): - return bool(value) if value in ('y', 'yes'): return True if value in ('n', 'no'): return False - msg = "option %s: invalid yn value %r, should be in (y, yes, n, no)" + if value in (True, False): + return value + msg = "option %s: invalid yn value %r, should be True or False" raise OptionValueError(msg % (opt, value)) def check_named(option, opt, value): diff --git a/test/unittest_configuration.py b/test/unittest_configuration.py index a60d6e7..a6b9037 100644 --- a/test/unittest_configuration.py +++ b/test/unittest_configuration.py @@ -57,7 +57,7 @@ class ConfigurationTC(TestCase): def test_load_command_line_configuration(self): cfg = self.cfg args = cfg.load_command_line_configuration(['--choice', 'ye', '--number', '4', - '--multiple=1,2,3', '--dothis=n', + '--multiple=1,2,3', '--dothis', 'other', 'arguments']) self.assertEquals(args, ['other', 'arguments']) self.assertEquals(cfg['dothis'], False) @@ -198,7 +198,7 @@ named=key:val Options: -h, --help show this help message and exit - --dothis=<y or n> + --dothis -v<string>, --value=<string> --multiple=<comma separated values> you can also document the option [current: yop,yep] @@ -215,7 +215,7 @@ Options: options: -h, --help show this help message and exit - --dothis=<y or n> + --dothis -v<string>, --value=<string> --multiple=<comma separated values> you can also document the option [current: yop,yep] @@ -232,7 +232,7 @@ options: options: -h, --help show this help message and exit - --dothis=<y or n> + --dothis -v<string>, --value=<string> --multiple=<comma separated values> you can also document the option |