When prompting for arguments in the cli there is no way to tell what is
optional and what is required. This sticks brackets around optional
arguments.
Ticket 832
rob
>From 493040768759d1d215c26456198e0af5354333fe Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcrit...@redhat.com>
Date: Mon, 24 Jan 2011 16:59:52 -0500
Subject: [PATCH] Add brackets around optional parameters when prompting.
ticket 832
---
ipalib/cli.py | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 2cd3a97..493ddba 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -505,15 +505,19 @@ class textui(backend.Backend):
def print_error(self, text):
print ' ** %s **' % unicode(text)
- def prompt(self, label, default=None, get_values=None):
+ def prompt(self, label, default=None, get_values=None, optional=False):
"""
Prompt user for input.
"""
# TODO: Add tab completion using readline
+ if optional:
+ prompt = u'[%s]' % label
+ else:
+ prompt = u'%s' % label
if default is None:
- prompt = u'%s: ' % label
+ prompt = u'%s: ' % prompt
else:
- prompt = u'%s [%s]: ' % (label, default)
+ prompt = u'%s [%s]: ' % (prompt, default)
try:
data = raw_input(self.encode(prompt))
except EOFError:
@@ -1001,7 +1005,7 @@ class cli(backend.Executioner):
while True:
if error is not None:
print '>>> %s: %s' % (unicode(param.label), unicode(error))
- raw = self.Backend.textui.prompt(param.label, default)
+ 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:
--
1.7.3.4
_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel