summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>2008-11-14 13:09:20 +0100
committerNicolas Chauvat <nicolas.chauvat@logilab.fr>2008-11-14 13:09:20 +0100
commit871009629bdc1c55709470a4d5bb36a7a38c41e1 (patch)
treef9fb8e2e858d8b19e28c803f6022eebb16078533
parentadf3c9846945356098aaa05f893308f5e691a879 (diff)
downloadlogilab-common-871009629bdc1c55709470a4d5bb36a7a38c41e1.tar.gz
Backed out changeset 8c66ea05839d see #6509
-rw-r--r--configuration.py7
-rw-r--r--optik_ext.py6
-rw-r--r--test/unittest_configuration.py8
3 files changed, 7 insertions, 14 deletions
diff --git a/configuration.py b/configuration.py
index 6f9d9af..ac27166 100644
--- a/configuration.py
+++ b/configuration.py
@@ -395,13 +395,6 @@ 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 ffaf1ba..123a2a6 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
- if value in (True, False):
- return value
- msg = "option %s: invalid yn value %r, should be True or False"
+ msg = "option %s: invalid yn value %r, should be in (y, yes, n, no)"
raise OptionValueError(msg % (opt, value))
def check_named(option, opt, value):
diff --git a/test/unittest_configuration.py b/test/unittest_configuration.py
index a6b9037..a60d6e7 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',
+ '--multiple=1,2,3', '--dothis=n',
'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
+ --dothis=<y or n>
-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
+ --dothis=<y or n>
-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
+ --dothis=<y or n>
-v<string>, --value=<string>
--multiple=<comma separated values>
you can also document the option