incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1491150 - /incubator/public/trunk/tools/src/asf/cli.py
Date Sun, 09 Jun 2013 06:49:33 GMT
Author: adc
Date: Sun Jun  9 06:49:32 2013
New Revision: 1491150

URL: http://svn.apache.org/r1491150
Log:
Handy prompt commands.

Modified:
    incubator/public/trunk/tools/src/asf/cli.py

Modified: incubator/public/trunk/tools/src/asf/cli.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/src/asf/cli.py?rev=1491150&r1=1491149&r2=1491150&view=diff
==============================================================================
--- incubator/public/trunk/tools/src/asf/cli.py (original)
+++ incubator/public/trunk/tools/src/asf/cli.py Sun Jun  9 06:49:32 2013
@@ -384,3 +384,34 @@ class CLI(object):
 class ExitedCleanly(StandardError):
     """ Use instead of sys.exit() to throw an exception but not log an error. """
     pass
+
+
+def prompt_options(text, options):
+    for idx, value in enumerate(options):
+        print '%s: %s' % (idx + 1, value)
+    text += ' [1 to %s, enter to skip] ' % len(options)
+    while True:
+        answer = raw_input(text)
+        if not answer:
+            return None
+        if answer.isdigit():
+            answer = int(answer)
+            if 1 <= answer <= len(options):
+                return answer - 1
+
+
+def prompt_yes_no(text, default=None):
+    if default is None:
+        text += ' (y/n) '
+    elif default:
+        text += ' (Y/n) '
+    else:
+        text += ' (y/N) '
+    while True:
+        answer = raw_input(text)
+        if not answer and default is not None:
+            return default
+        if answer.lower() == 'y':
+            return True
+        if answer.lower() == 'n':
+            return False



---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message