summaryrefslogtreecommitdiffstats
path: root/ipalib/cli.py
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2011-05-26 09:55:53 +0200
committerMartin Kosek <mkosek@redhat.com>2011-06-02 09:00:35 +0200
commit585083c1d7a0069579d45b17adb39ad8f522c3f6 (patch)
tree0695c93b80c3d304e2e748cf9d24b4b02263491d /ipalib/cli.py
parentc0f155bbfe5c5448af1b38b9da9bb75e9cdac9b4 (diff)
downloadfreeipa-585083c1d7a0069579d45b17adb39ad8f522c3f6.tar.gz
freeipa-585083c1d7a0069579d45b17adb39ad8f522c3f6.tar.xz
freeipa-585083c1d7a0069579d45b17adb39ad8f522c3f6.zip
Improve interactive mode for DNS plugin
Interactive mode for commands manipulating with DNS records (dnsrecord-add, dnsrecord-del) is not usable. This patch enhances the server framework with new callback for interactive mode, which can be used by commands to inject their own interactive handling. The callback is then used to improve aforementioned commands' interactive mode. https://fedorahosted.org/freeipa/ticket/1018
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r--ipalib/cli.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 99f236bb4..5e1365dc3 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -527,6 +527,47 @@ class textui(backend.Backend):
return None
return self.decode(data)
+ def prompt_yesno(self, label, default=None):
+ """
+ Prompt user for yes/no input. This method returns True/False according
+ to user response.
+
+ Parameter "default" should be True, False or None
+
+ If Default parameter is not None, user can enter an empty input instead
+ of Yes/No answer. Value passed to Default is returned in that case.
+
+ If Default parameter is None, user is asked for Yes/No answer until
+ a correct answer is provided. Answer is then returned.
+
+ In case of an error, a None value may returned
+ """
+
+ default_prompt = None
+ if default is not None:
+ if default:
+ default_prompt = "Yes"
+ else:
+ default_prompt = "No"
+
+ if default_prompt:
+ prompt = u'%s Yes/No (default %s): ' % (label, default_prompt)
+ else:
+ prompt = u'%s Yes/No: ' % label
+
+ while True:
+ try:
+ data = raw_input(self.encode(prompt)).lower()
+ except EOFError:
+ return None
+
+ if data in (u'yes', u'y'):
+ return True
+ elif data in ( u'n', u'no'):
+ return False
+ elif default is not None and data == u'':
+ return default
+
def prompt_password(self, label):
"""
Prompt user for a password or read it in via stdin depending
@@ -1032,6 +1073,9 @@ class cli(backend.Executioner):
param.label
)
+ for callback in getattr(cmd, 'INTERACTIVE_PROMPT_CALLBACKS', []):
+ callback(kw)
+
def load_files(self, cmd, kw):
"""
Load files from File parameters.