summaryrefslogtreecommitdiffstats
path: root/ipalib/cli.py
diff options
context:
space:
mode:
authorTomas Babej <tbabej@redhat.com>2013-05-09 15:36:41 +0200
committerMartin Kosek <mkosek@redhat.com>2013-06-05 12:50:29 +0200
commit89ffaf411d4cfbf7cc7861439b8cde7ea8ba3ff7 (patch)
tree8d132728b2f16a750c6d6c0f89dfa2a2e7f640bd /ipalib/cli.py
parent8984e3e10582c3802edeb03d22d8b2c78381a31c (diff)
downloadfreeipa-89ffaf411d4cfbf7cc7861439b8cde7ea8ba3ff7.tar.gz
freeipa-89ffaf411d4cfbf7cc7861439b8cde7ea8ba3ff7.tar.xz
freeipa-89ffaf411d4cfbf7cc7861439b8cde7ea8ba3ff7.zip
Add prompt_param method to avoid code duplication
Extracted common code from ipalib/plugins/cli.py and ipalib/plugins/dns.py that provided way to prompt user for the value of specific attribute. Added prompt_param method to Command class in ipalib/frontend.py Done as part of https://fedorahosted.org/freeipa/ticket/3602
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r--ipalib/cli.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index c4b4492a5..5f02e929f 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -1178,11 +1178,13 @@ class cli(backend.Executioner):
``self.env.prompt_all`` is ``True``, this method will prompt for any
params that have a missing values, even if the param is optional.
"""
+
honor_alwaysask = True
for param in cmd.params():
if param.alwaysask and param.name in kw:
honor_alwaysask = False
break
+
for param in cmd.params():
if (param.required and param.name not in kw) or \
(param.alwaysask and honor_alwaysask) or self.env.prompt_all:
@@ -1196,19 +1198,16 @@ class cli(backend.Executioner):
)
else:
default = cmd.get_default_of(param.name, **kw)
- error = None
- while True:
- if error is not None:
- self.Backend.textui.print_prompt_attribute_error(unicode(param.label),
- unicode(error))
- raw = self.Backend.textui.prompt(param.label, default, optional=param.alwaysask or not param.required)
- try:
- value = param(raw, **kw)
- if value is not None:
- kw[param.name] = value
- break
- except (ValidationError, ConversionError), e:
- error = e.error
+ optional = param.alwaysask or not param.required
+
+ value = cmd.prompt_param(param,
+ default=default,
+ optional=optional,
+ kw=kw)
+
+ if value is not None:
+ kw[param.name] = value
+
elif param.password and kw.get(param.name, False) is True:
kw[param.name] = self.Backend.textui.prompt_password(
param.label, param.confirm