From c3bf83e9fb08de0084e8004517354d53d7003a14 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Thu, 3 Oct 2013 16:48:08 -0400
Subject: [PATCH] Fixed user and group commands.

The commands for user certificates, user memberships, and group members
have been renamed to be more consistent such that they can be parsed
correctly.
---
 .../src/com/netscape/cmstools/group/GroupCLI.java  | 15 +---
 ...oupAddMemberCLI.java => GroupMemberAddCLI.java} | 14 ++--
 ...{GroupAddMemberCLI.java => GroupMemberCLI.java} | 44 ++++++------
 ...pFindMemberCLI.java => GroupMemberFindCLI.java} | 14 ++--
 ...oveMemberCLI.java => GroupMemberRemoveCLI.java} | 12 ++--
 ...pShowMemberCLI.java => GroupMemberShowCLI.java} | 14 ++--
 .../src/com/netscape/cmstools/user/UserCLI.java    | 49 +-------------
 .../{UserAddCertCLI.java => UserCertAddCLI.java}   | 14 ++--
 .../com/netscape/cmstools/user/UserCertCLI.java    | 79 ++++++++++++++++++++++
 .../{UserFindCertCLI.java => UserCertFindCLI.java} | 14 ++--
 ...erRemoveCertCLI.java => UserCertRemoveCLI.java} | 12 ++--
 .../{UserShowCertCLI.java => UserCertShowCLI.java} | 14 ++--
 ...embershipCLI.java => UserMembershipAddCLI.java} | 14 ++--
 ...ddMembershipCLI.java => UserMembershipCLI.java} | 45 ++++++------
 ...mbershipCLI.java => UserMembershipFindCLI.java} | 14 ++--
 ...ershipCLI.java => UserMembershipRemoveCLI.java} | 12 ++--
 16 files changed, 202 insertions(+), 178 deletions(-)
 copy base/java-tools/src/com/netscape/cmstools/group/{GroupAddMemberCLI.java => GroupMemberAddCLI.java} (77%)
 rename base/java-tools/src/com/netscape/cmstools/group/{GroupAddMemberCLI.java => GroupMemberCLI.java} (53%)
 rename base/java-tools/src/com/netscape/cmstools/group/{GroupFindMemberCLI.java => GroupMemberFindCLI.java} (86%)
 rename base/java-tools/src/com/netscape/cmstools/group/{GroupRemoveMemberCLI.java => GroupMemberRemoveCLI.java} (80%)
 rename base/java-tools/src/com/netscape/cmstools/group/{GroupShowMemberCLI.java => GroupMemberShowCLI.java} (77%)
 rename base/java-tools/src/com/netscape/cmstools/user/{UserAddCertCLI.java => UserCertAddCLI.java} (87%)
 create mode 100644 base/java-tools/src/com/netscape/cmstools/user/UserCertCLI.java
 rename base/java-tools/src/com/netscape/cmstools/user/{UserFindCertCLI.java => UserCertFindCLI.java} (87%)
 rename base/java-tools/src/com/netscape/cmstools/user/{UserRemoveCertCLI.java => UserCertRemoveCLI.java} (81%)
 rename base/java-tools/src/com/netscape/cmstools/user/{UserShowCertCLI.java => UserCertShowCLI.java} (86%)
 copy base/java-tools/src/com/netscape/cmstools/user/{UserAddMembershipCLI.java => UserMembershipAddCLI.java} (75%)
 rename base/java-tools/src/com/netscape/cmstools/user/{UserAddMembershipCLI.java => UserMembershipCLI.java} (52%)
 rename base/java-tools/src/com/netscape/cmstools/user/{UserFindMembershipCLI.java => UserMembershipFindCLI.java} (85%)
 rename base/java-tools/src/com/netscape/cmstools/user/{UserRemoveMembershipCLI.java => UserMembershipRemoveCLI.java} (78%)

diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java
index dba9d9ab3c6ec693c090dd188a8d6fd863ec1e4f..973e0bae6d0652923c1f9f3b5ced78682e534730 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java
@@ -23,7 +23,6 @@ import org.jboss.resteasy.plugins.providers.atom.Link;
 
 import com.netscape.certsrv.group.GroupClient;
 import com.netscape.certsrv.group.GroupData;
-import com.netscape.certsrv.group.GroupMemberData;
 import com.netscape.cmstools.cli.CLI;
 import com.netscape.cmstools.cli.MainCLI;
 
@@ -43,10 +42,7 @@ public class GroupCLI extends CLI {
         addModule(new GroupModifyCLI(this));
         addModule(new GroupRemoveCLI(this));
 
-        addModule(new GroupFindMemberCLI(this));
-        addModule(new GroupShowMemberCLI(this));
-        addModule(new GroupAddMemberCLI(this));
-        addModule(new GroupRemoveMemberCLI(this));
+        addModule(new GroupMemberCLI(this));
     }
 
     public String getFullName() {
@@ -87,13 +83,4 @@ public class GroupCLI extends CLI {
             System.out.println("  Link: " + link.getHref());
         }
     }
-
-    public static void printGroupMember(GroupMemberData groupMemberData) {
-        System.out.println("  User: "+groupMemberData.getID());
-
-        Link link = groupMemberData.getLink();
-        if (verbose && link != null) {
-            System.out.println("  Link: " + link.getHref());
-        }
-    }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupAddMemberCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberAddCLI.java
similarity index 77%
copy from base/java-tools/src/com/netscape/cmstools/group/GroupAddMemberCLI.java
copy to base/java-tools/src/com/netscape/cmstools/group/GroupMemberAddCLI.java
index eb2f9bedefe29ed5f57a143ce91b36b1b01a16a2..94d1a1161766b3cc896ddf1a5ae3764a45f5f360 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupAddMemberCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberAddCLI.java
@@ -25,13 +25,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class GroupAddMemberCLI extends CLI {
+public class GroupMemberAddCLI extends CLI {
 
-    public GroupCLI groupCLI;
+    public GroupMemberCLI groupMemberCLI;
 
-    public GroupAddMemberCLI(GroupCLI groupCLI) {
-        super("add-member", "Add group member", groupCLI);
-        this.groupCLI = groupCLI;
+    public GroupMemberAddCLI(GroupMemberCLI groupMemberCLI) {
+        super("add", "Add group member", groupMemberCLI);
+        this.groupMemberCLI = groupMemberCLI;
     }
 
     public void printHelp() {
@@ -48,10 +48,10 @@ public class GroupAddMemberCLI extends CLI {
         String groupID = args[0];
         String memberID = args[1];
 
-        GroupMemberData groupMemberData = groupCLI.groupClient.addGroupMember(groupID, memberID);
+        GroupMemberData groupMemberData = groupMemberCLI.groupClient.addGroupMember(groupID, memberID);
 
         MainCLI.printMessage("Added group member \""+memberID+"\"");
 
-        GroupCLI.printGroupMember(groupMemberData);
+        GroupMemberCLI.printGroupMember(groupMemberData);
     }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupAddMemberCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberCLI.java
similarity index 53%
rename from base/java-tools/src/com/netscape/cmstools/group/GroupAddMemberCLI.java
rename to base/java-tools/src/com/netscape/cmstools/group/GroupMemberCLI.java
index eb2f9bedefe29ed5f57a143ce91b36b1b01a16a2..22fd2354e7c68db635038e4cc629f00329c6b291 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupAddMemberCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberCLI.java
@@ -18,40 +18,42 @@
 
 package com.netscape.cmstools.group;
 
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.group.GroupClient;
 import com.netscape.certsrv.group.GroupMemberData;
 import com.netscape.cmstools.cli.CLI;
-import com.netscape.cmstools.cli.MainCLI;
 
 /**
  * @author Endi S. Dewata
  */
-public class GroupAddMemberCLI extends CLI {
+public class GroupMemberCLI extends CLI {
 
-    public GroupCLI groupCLI;
+    public GroupClient groupClient;
 
-    public GroupAddMemberCLI(GroupCLI groupCLI) {
-        super("add-member", "Add group member", groupCLI);
-        this.groupCLI = groupCLI;
-    }
+    public GroupMemberCLI(CLI parent) {
+        super("member", "Group member management commands", parent);
 
-    public void printHelp() {
-        formatter.printHelp(getFullName() + " <Group ID> <Member ID>", options);
+        addModule(new GroupMemberFindCLI(this));
+        addModule(new GroupMemberShowCLI(this));
+        addModule(new GroupMemberAddCLI(this));
+        addModule(new GroupMemberRemoveCLI(this));
     }
 
     public void execute(String[] args) throws Exception {
 
-        if (args.length != 2) {
-            printHelp();
-            System.exit(1);
+        client = parent.getClient();
+        groupClient = (GroupClient)parent.getClient("group");
+
+        super.execute(args);
+    }
+
+    public static void printGroupMember(GroupMemberData groupMemberData) {
+        System.out.println("  User: "+groupMemberData.getID());
+
+        Link link = groupMemberData.getLink();
+        if (verbose && link != null) {
+            System.out.println("  Link: " + link.getHref());
         }
-
-        String groupID = args[0];
-        String memberID = args[1];
-
-        GroupMemberData groupMemberData = groupCLI.groupClient.addGroupMember(groupID, memberID);
-
-        MainCLI.printMessage("Added group member \""+memberID+"\"");
-
-        GroupCLI.printGroupMember(groupMemberData);
     }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupFindMemberCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberFindCLI.java
similarity index 86%
rename from base/java-tools/src/com/netscape/cmstools/group/GroupFindMemberCLI.java
rename to base/java-tools/src/com/netscape/cmstools/group/GroupMemberFindCLI.java
index 383e547f31a6656f071d88edbc471b4ab501ee9b..b9c9ac76d30df29001ff44f4c2503da0876abd91 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupFindMemberCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberFindCLI.java
@@ -31,13 +31,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class GroupFindMemberCLI extends CLI {
+public class GroupMemberFindCLI extends CLI {
 
-    public GroupCLI groupCLI;
+    public GroupMemberCLI groupMemberCLI;
 
-    public GroupFindMemberCLI(GroupCLI groupCLI) {
-        super("find-member", "Find group members", groupCLI);
-        this.groupCLI = groupCLI;
+    public GroupMemberFindCLI(GroupMemberCLI groupMemberCLI) {
+        super("find", "Find group members", groupMemberCLI);
+        this.groupMemberCLI = groupMemberCLI;
     }
 
     public void printHelp() {
@@ -80,7 +80,7 @@ public class GroupFindMemberCLI extends CLI {
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        GroupMemberCollection response = groupCLI.groupClient.findGroupMembers(groupID, start, size);
+        GroupMemberCollection response = groupMemberCLI.groupClient.findGroupMembers(groupID, start, size);
 
         Collection<GroupMemberData> entries = response.getMembers();
 
@@ -96,7 +96,7 @@ public class GroupFindMemberCLI extends CLI {
                 System.out.println();
             }
 
-            GroupCLI.printGroupMember(groupMemberData);
+            GroupMemberCLI.printGroupMember(groupMemberData);
         }
 
         MainCLI.printMessage("Number of entries returned "+entries.size());
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupRemoveMemberCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberRemoveCLI.java
similarity index 80%
rename from base/java-tools/src/com/netscape/cmstools/group/GroupRemoveMemberCLI.java
rename to base/java-tools/src/com/netscape/cmstools/group/GroupMemberRemoveCLI.java
index ef348404586997cc9f4b9d52e3afc22bd7852699..f340e7f649d4db13d27be47dc6836d6229400505 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupRemoveMemberCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberRemoveCLI.java
@@ -24,13 +24,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class GroupRemoveMemberCLI extends CLI {
+public class GroupMemberRemoveCLI extends CLI {
 
-    public GroupCLI groupCLI;
+    public GroupMemberCLI groupMemberCLI;
 
-    public GroupRemoveMemberCLI(GroupCLI groupCLI) {
-        super("remove-member", "Remove group member", groupCLI);
-        this.groupCLI = groupCLI;
+    public GroupMemberRemoveCLI(GroupMemberCLI groupMemberCLI) {
+        super("remove", "Remove group member", groupMemberCLI);
+        this.groupMemberCLI = groupMemberCLI;
     }
 
     public void printHelp() {
@@ -47,7 +47,7 @@ public class GroupRemoveMemberCLI extends CLI {
         String groupID = args[0];
         String memberID = args[1];
 
-        groupCLI.groupClient.removeGroupMember(groupID, memberID);
+        groupMemberCLI.groupClient.removeGroupMember(groupID, memberID);
 
         MainCLI.printMessage("Deleted group member \""+memberID+"\"");
     }
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupShowMemberCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberShowCLI.java
similarity index 77%
rename from base/java-tools/src/com/netscape/cmstools/group/GroupShowMemberCLI.java
rename to base/java-tools/src/com/netscape/cmstools/group/GroupMemberShowCLI.java
index 2f50a6a080bd8a22b485316779ac05a02447e220..26a096f72d5aff1188080f48a8a6d348a3a8f882 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupShowMemberCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupMemberShowCLI.java
@@ -25,13 +25,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class GroupShowMemberCLI extends CLI {
+public class GroupMemberShowCLI extends CLI {
 
-    public GroupCLI groupCLI;
+    public GroupMemberCLI groupMemberCLI;
 
-    public GroupShowMemberCLI(GroupCLI groupCLI) {
-        super("show-member", "Show group member", groupCLI);
-        this.groupCLI = groupCLI;
+    public GroupMemberShowCLI(GroupMemberCLI groupMemberCLI) {
+        super("show", "Show group member", groupMemberCLI);
+        this.groupMemberCLI = groupMemberCLI;
     }
 
     public void printHelp() {
@@ -48,10 +48,10 @@ public class GroupShowMemberCLI extends CLI {
         String groupID = args[0];
         String memberID = args[1];
 
-        GroupMemberData groupMemberData = groupCLI.groupClient.getGroupMember(groupID, memberID);
+        GroupMemberData groupMemberData = groupMemberCLI.groupClient.getGroupMember(groupID, memberID);
 
         MainCLI.printMessage("Group member \""+memberID+"\"");
 
-        GroupCLI.printGroupMember(groupMemberData);
+        GroupMemberCLI.printGroupMember(groupMemberData);
     }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java
index edbb62cabddb0d4b113044c4eb4ac8002bfc641f..7a03d3384fbe3cc47276442461b8b959702afcf9 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java
@@ -21,10 +21,8 @@ package com.netscape.cmstools.user;
 import org.apache.commons.lang.StringUtils;
 import org.jboss.resteasy.plugins.providers.atom.Link;
 
-import com.netscape.certsrv.user.UserCertData;
 import com.netscape.certsrv.user.UserClient;
 import com.netscape.certsrv.user.UserData;
-import com.netscape.certsrv.user.UserMembershipData;
 import com.netscape.certsrv.user.UserResource;
 import com.netscape.cmstools.cli.CLI;
 import com.netscape.cmstools.cli.MainCLI;
@@ -45,14 +43,9 @@ public class UserCLI extends CLI {
         addModule(new UserModifyCLI(this));
         addModule(new UserRemoveCLI(this));
 
-        addModule(new UserFindCertCLI(this));
-        addModule(new UserShowCertCLI(this));
-        addModule(new UserAddCertCLI(this));
-        addModule(new UserRemoveCertCLI(this));
+        addModule(new UserCertCLI(this));
 
-        addModule(new UserFindMembershipCLI(this));
-        addModule(new UserAddMembershipCLI(this));
-        addModule(new UserRemoveMembershipCLI(this));
+        addModule(new UserMembershipCLI(this));
     }
 
     public String getFullName() {
@@ -118,42 +111,4 @@ public class UserCLI extends CLI {
             }
         }
     }
-
-    public static void printCert(
-            UserCertData userCertData,
-            boolean showPrettyPrint,
-            boolean showEncoded) {
-
-        System.out.println("  Cert ID: " + userCertData.getID());
-        System.out.println("  Version: " + userCertData.getVersion());
-        System.out.println("  Serial Number: " + userCertData.getSerialNumber().toHexString());
-        System.out.println("  Issuer: " + userCertData.getIssuerDN());
-        System.out.println("  Subject: " + userCertData.getSubjectDN());
-
-        Link link = userCertData.getLink();
-        if (verbose && link != null) {
-            System.out.println("  Link: " + link.getHref());
-        }
-
-        String prettyPrint = userCertData.getPrettyPrint();
-        if (showPrettyPrint && prettyPrint != null) {
-            System.out.println();
-            System.out.println(prettyPrint);
-        }
-
-        String encoded = userCertData.getEncoded();
-        if (showEncoded && encoded != null) {
-            System.out.println();
-            System.out.println(encoded);
-        }
-    }
-
-    public static void printUserMembership(UserMembershipData userMembershipData) {
-        System.out.println("  Group: "+userMembershipData.getID());
-
-        Link link = userMembershipData.getLink();
-        if (verbose && link != null) {
-            System.out.println("  Link: " + link.getHref());
-        }
-    }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserAddCertCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCertAddCLI.java
similarity index 87%
rename from base/java-tools/src/com/netscape/cmstools/user/UserAddCertCLI.java
rename to base/java-tools/src/com/netscape/cmstools/user/UserCertAddCLI.java
index e3271c022a355a4002601d8af953ea52c7970d7a..1a1ce5ee00def8d330ff903936871987ea7674de 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserAddCertCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCertAddCLI.java
@@ -31,13 +31,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class UserAddCertCLI extends CLI {
+public class UserCertAddCLI extends CLI {
 
-    public UserCLI userCLI;
+    public UserCertCLI userCertCLI;
 
-    public UserAddCertCLI(UserCLI userCLI) {
-        super("add-cert", "Add user cert", userCLI);
-        this.userCLI = userCLI;
+    public UserCertAddCLI(UserCertCLI userCertCLI) {
+        super("add", "Add user certificate", userCertCLI);
+        this.userCertCLI = userCertCLI;
     }
 
     public void printHelp() {
@@ -88,10 +88,10 @@ public class UserAddCertCLI extends CLI {
             System.out.println(userCertData);
         }
 
-        userCertData = userCLI.userClient.addUserCert(userId, userCertData);
+        userCertData = userCertCLI.userClient.addUserCert(userId, userCertData);
 
         MainCLI.printMessage("Added certificate \"" + userCertData.getID() + "\"");
 
-        UserCLI.printCert(userCertData, false, false);
+        UserCertCLI.printCert(userCertData, false, false);
     }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserCertCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCertCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..163c55f25c843844ed51b3f9acfe247ee802f3b8
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCertCLI.java
@@ -0,0 +1,79 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.user.UserCertData;
+import com.netscape.certsrv.user.UserClient;
+import com.netscape.cmstools.cli.CLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserCertCLI extends CLI {
+
+    public UserClient userClient;
+
+    public UserCertCLI(UserCLI parent) {
+        super("cert", "User certificate management commands", parent);
+
+        addModule(new UserCertFindCLI(this));
+        addModule(new UserCertShowCLI(this));
+        addModule(new UserCertAddCLI(this));
+        addModule(new UserCertRemoveCLI(this));
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        client = parent.getClient();
+        userClient = (UserClient)parent.getClient("user");
+
+        super.execute(args);
+    }
+
+    public static void printCert(
+            UserCertData userCertData,
+            boolean showPrettyPrint,
+            boolean showEncoded) {
+
+        System.out.println("  Cert ID: " + userCertData.getID());
+        System.out.println("  Version: " + userCertData.getVersion());
+        System.out.println("  Serial Number: " + userCertData.getSerialNumber().toHexString());
+        System.out.println("  Issuer: " + userCertData.getIssuerDN());
+        System.out.println("  Subject: " + userCertData.getSubjectDN());
+
+        Link link = userCertData.getLink();
+        if (verbose && link != null) {
+            System.out.println("  Link: " + link.getHref());
+        }
+
+        String prettyPrint = userCertData.getPrettyPrint();
+        if (showPrettyPrint && prettyPrint != null) {
+            System.out.println();
+            System.out.println(prettyPrint);
+        }
+
+        String encoded = userCertData.getEncoded();
+        if (showEncoded && encoded != null) {
+            System.out.println();
+            System.out.println(encoded);
+        }
+    }
+}
\ No newline at end of file
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserFindCertCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCertFindCLI.java
similarity index 87%
rename from base/java-tools/src/com/netscape/cmstools/user/UserFindCertCLI.java
rename to base/java-tools/src/com/netscape/cmstools/user/UserCertFindCLI.java
index 15bc4f753f9bf9b98905e074b545af8959aba201..680b6b362a0266078699a54508cf4c5d7b7d838f 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserFindCertCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCertFindCLI.java
@@ -31,13 +31,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class UserFindCertCLI extends CLI {
+public class UserCertFindCLI extends CLI {
 
-    public UserCLI userCLI;
+    public UserCertCLI userCertCLI;
 
-    public UserFindCertCLI(UserCLI userCLI) {
-        super("find-cert", "Find user certs", userCLI);
-        this.userCLI = userCLI;
+    public UserCertFindCLI(UserCertCLI userCertCLI) {
+        super("find", "Find user certificates", userCertCLI);
+        this.userCertCLI = userCertCLI;
     }
 
     public void printHelp() {
@@ -80,7 +80,7 @@ public class UserFindCertCLI extends CLI {
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        UserCertCollection response = userCLI.userClient.findUserCerts(userID, start, size);
+        UserCertCollection response = userCertCLI.userClient.findUserCerts(userID, start, size);
 
         Collection<UserCertData> entries = response.getCerts();
 
@@ -96,7 +96,7 @@ public class UserFindCertCLI extends CLI {
                 System.out.println();
             }
 
-            UserCLI.printCert(userCertData, false, false);
+            UserCertCLI.printCert(userCertData, false, false);
         }
 
         MainCLI.printMessage("Number of entries returned " + entries.size());
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCertCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCertRemoveCLI.java
similarity index 81%
rename from base/java-tools/src/com/netscape/cmstools/user/UserRemoveCertCLI.java
rename to base/java-tools/src/com/netscape/cmstools/user/UserCertRemoveCLI.java
index 5758c4ccd593226f0f5639f3f121d57939c6735e..c68988fee878394a61da69c881bb43dad6d175ec 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCertCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCertRemoveCLI.java
@@ -27,13 +27,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class UserRemoveCertCLI extends CLI {
+public class UserCertRemoveCLI extends CLI {
 
-    public UserCLI userCLI;
+    public UserCertCLI userCertCLI;
 
-    public UserRemoveCertCLI(UserCLI userCLI) {
-        super("remove-cert", "Remove user cert", userCLI);
-        this.userCLI = userCLI;
+    public UserCertRemoveCLI(UserCertCLI userCertCLI) {
+        super("remove", "Remove user certificate", userCertCLI);
+        this.userCertCLI = userCertCLI;
     }
 
     public void printHelp() {
@@ -54,7 +54,7 @@ public class UserRemoveCertCLI extends CLI {
             System.out.println("Removing cert "+certID+" from user "+userID+".");
         }
 
-        userCLI.userClient.removeUserCert(userID, URLEncoder.encode(certID, "UTF-8"));
+        userCertCLI.userClient.removeUserCert(userID, URLEncoder.encode(certID, "UTF-8"));
 
         MainCLI.printMessage("Deleted certificate \"" + certID + "\"");
     }
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserShowCertCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCertShowCLI.java
similarity index 86%
rename from base/java-tools/src/com/netscape/cmstools/user/UserShowCertCLI.java
rename to base/java-tools/src/com/netscape/cmstools/user/UserCertShowCLI.java
index 87e535f6a93f143d1c1bcf2a4c25bfcf0d09d1ea..e07de6d3e8b19d37061e660753056f0db6b7359d 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserShowCertCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCertShowCLI.java
@@ -32,13 +32,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class UserShowCertCLI extends CLI {
+public class UserCertShowCLI extends CLI {
 
-    public UserCLI userCLI;
+    public UserCertCLI userCertCLI;
 
-    public UserShowCertCLI(UserCLI userCLI) {
-        super("show-cert", "Show user cert", userCLI);
-        this.userCLI = userCLI;
+    public UserCertShowCLI(UserCertCLI userCertCLI) {
+        super("show", "Show user certificate", userCertCLI);
+        this.userCertCLI = userCertCLI;
     }
 
     public void printHelp() {
@@ -79,7 +79,7 @@ public class UserShowCertCLI extends CLI {
         String certID = cmdArgs[1];
         String file = cmd.getOptionValue("output");
 
-        UserCertData userCertData = userCLI.userClient.getUserCert(userID, URLEncoder.encode(certID, "UTF-8"));
+        UserCertData userCertData = userCertCLI.userClient.getUserCert(userID, URLEncoder.encode(certID, "UTF-8"));
 
         String encoded = userCertData.getEncoded();
         if (encoded != null && file != null) {
@@ -91,6 +91,6 @@ public class UserShowCertCLI extends CLI {
 
         MainCLI.printMessage("Certificate \"" + userCertData.getID() + "\"");
 
-        UserCLI.printCert(userCertData, showPrettyPrint, showEncoded);
+        UserCertCLI.printCert(userCertData, showPrettyPrint, showEncoded);
     }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserAddMembershipCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipAddCLI.java
similarity index 75%
copy from base/java-tools/src/com/netscape/cmstools/user/UserAddMembershipCLI.java
copy to base/java-tools/src/com/netscape/cmstools/user/UserMembershipAddCLI.java
index ab8e61fe185397db7fb2e8546c58d0e21fe1130d..1b9925c3bf919014a1c1ea0ecdb70e030ca102fc 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserAddMembershipCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipAddCLI.java
@@ -25,13 +25,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class UserAddMembershipCLI extends CLI {
+public class UserMembershipAddCLI extends CLI {
 
-    public UserCLI userCLI;
+    public UserMembershipCLI userMembershipCLI;
 
-    public UserAddMembershipCLI(UserCLI userCLI) {
-        super("add-membership", "Add user membership", userCLI);
-        this.userCLI = userCLI;
+    public UserMembershipAddCLI(UserMembershipCLI userMembershipCLI) {
+        super("add", "Add user membership", userMembershipCLI);
+        this.userMembershipCLI = userMembershipCLI;
     }
 
     public void printHelp() {
@@ -48,10 +48,10 @@ public class UserAddMembershipCLI extends CLI {
         String userID = args[0];
         String groupID = args[1];
 
-        UserMembershipData userMembershipData = userCLI.userClient.addUserMembership(userID, groupID);
+        UserMembershipData userMembershipData = userMembershipCLI.userClient.addUserMembership(userID, groupID);
 
         MainCLI.printMessage("Added membership in \""+groupID+"\"");
 
-        UserCLI.printUserMembership(userMembershipData);
+        UserMembershipCLI.printUserMembership(userMembershipData);
     }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserAddMembershipCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipCLI.java
similarity index 52%
rename from base/java-tools/src/com/netscape/cmstools/user/UserAddMembershipCLI.java
rename to base/java-tools/src/com/netscape/cmstools/user/UserMembershipCLI.java
index ab8e61fe185397db7fb2e8546c58d0e21fe1130d..430aef5ad6616322a6a758bd80d75464ce6412a3 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserAddMembershipCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipCLI.java
@@ -12,46 +12,47 @@
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 //
-// (C) 2013 Red Hat, Inc.
+// (C) 2012 Red Hat, Inc.
 // All rights reserved.
 // --- END COPYRIGHT BLOCK ---
 
 package com.netscape.cmstools.user;
 
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.user.UserClient;
 import com.netscape.certsrv.user.UserMembershipData;
 import com.netscape.cmstools.cli.CLI;
-import com.netscape.cmstools.cli.MainCLI;
 
 /**
  * @author Endi S. Dewata
  */
-public class UserAddMembershipCLI extends CLI {
+public class UserMembershipCLI extends CLI {
 
-    public UserCLI userCLI;
+    public UserClient userClient;
 
-    public UserAddMembershipCLI(UserCLI userCLI) {
-        super("add-membership", "Add user membership", userCLI);
-        this.userCLI = userCLI;
-    }
+    public UserMembershipCLI(CLI parent) {
+        super("membership", "User membership management commands", parent);
 
-    public void printHelp() {
-        formatter.printHelp(getFullName() + " <User ID> <Group ID>", options);
+        addModule(new UserMembershipFindCLI(this));
+        addModule(new UserMembershipAddCLI(this));
+        addModule(new UserMembershipRemoveCLI(this));
     }
 
     public void execute(String[] args) throws Exception {
 
-        if (args.length != 2) {
-            printHelp();
-            System.exit(1);
+        client = parent.getClient();
+        userClient = (UserClient)parent.getClient("user");
+
+        super.execute(args);
+    }
+
+    public static void printUserMembership(UserMembershipData userMembershipData) {
+        System.out.println("  Group: "+userMembershipData.getID());
+
+        Link link = userMembershipData.getLink();
+        if (verbose && link != null) {
+            System.out.println("  Link: " + link.getHref());
         }
-
-        String userID = args[0];
-        String groupID = args[1];
-
-        UserMembershipData userMembershipData = userCLI.userClient.addUserMembership(userID, groupID);
-
-        MainCLI.printMessage("Added membership in \""+groupID+"\"");
-
-        UserCLI.printUserMembership(userMembershipData);
     }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserFindMembershipCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipFindCLI.java
similarity index 85%
rename from base/java-tools/src/com/netscape/cmstools/user/UserFindMembershipCLI.java
rename to base/java-tools/src/com/netscape/cmstools/user/UserMembershipFindCLI.java
index 0c41635dd1624e8982eea45d26ee2bedde121b95..129aa6dc829a135e89e1f2dc44604f2c1418ace9 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserFindMembershipCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipFindCLI.java
@@ -31,13 +31,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class UserFindMembershipCLI extends CLI {
+public class UserMembershipFindCLI extends CLI {
 
-    public UserCLI userCLI;
+    public UserMembershipCLI userMembershipCLI;
 
-    public UserFindMembershipCLI(UserCLI userCLI) {
-        super("find-membership", "Find user memberships", userCLI);
-        this.userCLI = userCLI;
+    public UserMembershipFindCLI(UserMembershipCLI userMembershipCLI) {
+        super("find", "Find user memberships", userMembershipCLI);
+        this.userMembershipCLI = userMembershipCLI;
     }
 
     public void printHelp() {
@@ -80,7 +80,7 @@ public class UserFindMembershipCLI extends CLI {
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        UserMembershipCollection response = userCLI.userClient.findUserMemberships(userID, start, size);
+        UserMembershipCollection response = userMembershipCLI.userClient.findUserMemberships(userID, start, size);
 
         Collection<UserMembershipData> entries = response.getMemberships();
 
@@ -96,7 +96,7 @@ public class UserFindMembershipCLI extends CLI {
                 System.out.println();
             }
 
-            UserCLI.printUserMembership(userMembershipData);
+            UserMembershipCLI.printUserMembership(userMembershipData);
         }
 
         MainCLI.printMessage("Number of entries returned "+entries.size());
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserRemoveMembershipCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipRemoveCLI.java
similarity index 78%
rename from base/java-tools/src/com/netscape/cmstools/user/UserRemoveMembershipCLI.java
rename to base/java-tools/src/com/netscape/cmstools/user/UserMembershipRemoveCLI.java
index 62091efb00b32c7178a8cca9da67bb85a8f00d43..bb0ca714bb947853300eb6c1d59f7dd984764b77 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserRemoveMembershipCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserMembershipRemoveCLI.java
@@ -24,13 +24,13 @@ import com.netscape.cmstools.cli.MainCLI;
 /**
  * @author Endi S. Dewata
  */
-public class UserRemoveMembershipCLI extends CLI {
+public class UserMembershipRemoveCLI extends CLI {
 
-    public UserCLI userCLI;
+    public UserMembershipCLI userMembershipCLI;
 
-    public UserRemoveMembershipCLI(UserCLI userCLI) {
-        super("remove-membership", "Remove user membership", userCLI);
-        this.userCLI = userCLI;
+    public UserMembershipRemoveCLI(UserMembershipCLI userMembershipCLI) {
+        super("remove", "Remove user membership", userMembershipCLI);
+        this.userMembershipCLI = userMembershipCLI;
     }
 
     public void printHelp() {
@@ -47,7 +47,7 @@ public class UserRemoveMembershipCLI extends CLI {
         String userID = args[0];
         String groupID = args[1];
 
-        userCLI.userClient.removeUserMembership(userID, groupID);
+        userMembershipCLI.userClient.removeUserMembership(userID, groupID);
 
         MainCLI.printMessage("Deleted membership in group \""+groupID+"\"");
     }
-- 
1.8.1.4

