Use better description for group names in help and always prompt for members

When running <foo>-[add|remove]-member completely interactively it didn't prompt for managing membership, it just reported that 0 members were handled which was rather confusing.

This will work via a shell if you want to echo too:

$ echo "" | ipa group-add-member g1

This returns 0 members because nothing is read for users or group members.

$ echo -e "g1\nadmin\n" | ipa group-add-member

This adds the user admin to the group g1. It adds it as a user because user membership is prompted for first.

ticket 415

rob
>From 90d7d3addc5c7850db00cf7564d9fd58432d5cd3 Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcrit...@redhat.com>
Date: Tue, 23 Nov 2010 15:08:07 -0500
Subject: [PATCH] Use better description for group names in help and always prompt for members

When running <foo>-[add|remove]-member completely interactively it didn't
prompt for managing membership, it just reported that 0 members were
handled which was rather confusing.

This will work via a shell if you want to echo too:

$ echo "" | ipa group-add-member g1

This returns 0 members because nothing is read for users or group members.

$ echo -e "g1\nadmin\n" | ipa group-add-member

This adds the user admin to the group g1. It adds it as a user because
user membership is prompted for first.

ticket 415
---
 ipalib/cli.py                  |   10 ++++++----
 ipalib/parameters.py           |    1 +
 ipalib/plugins/baseldap.py     |    2 +-
 ipalib/plugins/group.py        |    2 +-
 ipalib/plugins/hostgroup.py    |    2 +-
 ipalib/plugins/sudocmdgroup.py |    2 +-
 ipalib/plugins/sudorule.py     |    2 +-
 7 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/ipalib/cli.py b/ipalib/cli.py
index 41bee7a..05145e0 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -503,9 +503,11 @@ class textui(backend.Backend):
             prompt = u'%s: ' % label
         else:
             prompt = u'%s [%s]: ' % (label, default)
-        return self.decode(
-            raw_input(self.encode(prompt))
-        )
+        try:
+            data = raw_input(self.encode(prompt))
+        except EOFError:
+            return None
+        return self.decode(data)
 
     def prompt_password(self, label):
         """
@@ -896,7 +898,7 @@ class cli(backend.Executioner):
             elif param.name not in kw:
                 if param.autofill:
                     kw[param.name] = param.get_default(**kw)
-                elif param.required or self.env.prompt_all:
+                elif param.required or param.alwaysask or self.env.prompt_all:
                     default = param.get_default(**kw)
                     error = None
                     while True:
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 7543e15..cf4f3ba 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -315,6 +315,7 @@ class Param(ReadOnly):
         ('exclude', frozenset, None),
         ('flags', frozenset, frozenset()),
         ('hint', (str, Gettext), None),
+        ('alwaysask', bool, False),
 
         # The 'default' kwarg gets appended in Param.__init__():
         # ('default', self.type, None),
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 315deb0..8ef8f01 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -846,7 +846,7 @@ class LDAPModMember(LDAPQuery):
                 name = to_cli(ldap_obj_name)
                 doc = self.member_param_doc % ldap_obj.object_name_plural
                 yield List('%s?' % name, cli_name='%ss' % name, doc=doc,
-                           label=ldap_obj.object_name)
+                           label=ldap_obj.object_name, alwaysask=True)
 
     def get_member_dns(self, **options):
         dns = {}
diff --git a/ipalib/plugins/group.py b/ipalib/plugins/group.py
index 5ecc72a..a8c4af6 100644
--- a/ipalib/plugins/group.py
+++ b/ipalib/plugins/group.py
@@ -101,7 +101,7 @@ class group(LDAPObject):
             pattern='^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,252}[a-zA-Z0-9_.$-]?$',
             pattern_errmsg='may only include letters, numbers, _, -, . and $',
             maxlength=255,
-            cli_name='name',
+            cli_name='group_name',
             label=_('Group name'),
             primary_key=True,
             normalizer=lambda value: value.lower(),
diff --git a/ipalib/plugins/hostgroup.py b/ipalib/plugins/hostgroup.py
index 51d0583..1c4cc28 100644
--- a/ipalib/plugins/hostgroup.py
+++ b/ipalib/plugins/hostgroup.py
@@ -73,7 +73,7 @@ class hostgroup(LDAPObject):
 
     takes_params = (
         Str('cn',
-            cli_name='name',
+            cli_name='hostgroup_name',
             label=_('Host-group'),
             doc=_('Name of host-group'),
             primary_key=True,
diff --git a/ipalib/plugins/sudocmdgroup.py b/ipalib/plugins/sudocmdgroup.py
index 5476f99..98e4843 100644
--- a/ipalib/plugins/sudocmdgroup.py
+++ b/ipalib/plugins/sudocmdgroup.py
@@ -68,7 +68,7 @@ class sudocmdgroup(LDAPObject):
 
     takes_params = (
         Str('cn',
-            cli_name='name',
+            cli_name='sudocmdgroup_name',
             label=_('Sudo Command Group name'),
             primary_key=True,
             normalizer=lambda value: value.lower(),
diff --git a/ipalib/plugins/sudorule.py b/ipalib/plugins/sudorule.py
index df0ae5c..2e32d86 100644
--- a/ipalib/plugins/sudorule.py
+++ b/ipalib/plugins/sudorule.py
@@ -50,7 +50,7 @@ class sudorule(LDAPObject):
 
     takes_params = (
         Str('cn',
-            cli_name='name',
+            cli_name='sudorule_name',
             label=_('Rule name'),
             primary_key=True,
         ),
-- 
1.7.2.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to