ls-groups: add option to list groups for a project
Add an option to the ls-groups SSH command that allows to list only those groups for which any permission is assigned to a project. Change-Id: Ied7274d433a38eae82b4970154004eb9cc4216c2 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -18,20 +18,29 @@ import com.google.gerrit.common.data.GroupDetail;
|
||||
import com.google.gerrit.common.data.GroupList;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.server.account.VisibleGroups;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.sshd.BaseCommand;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListGroupsCommand extends BaseCommand {
|
||||
|
||||
@Inject
|
||||
private VisibleGroups.Factory visibleGroupsFactory;
|
||||
|
||||
|
||||
@Option(name = "--project", aliases = {"-p"},
|
||||
usage = "projects for which the groups should be listed")
|
||||
private final List<ProjectControl> projects = new ArrayList<ProjectControl>();
|
||||
|
||||
@Override
|
||||
public void start(final Environment env) throws IOException {
|
||||
startThread(new CommandRunnable() {
|
||||
@@ -46,9 +55,10 @@ public class ListGroupsCommand extends BaseCommand {
|
||||
private void display() throws Failure {
|
||||
final PrintWriter stdout = toPrintWriter(out);
|
||||
try {
|
||||
final GroupList visibleGroups =
|
||||
visibleGroupsFactory.create().get();
|
||||
for (final GroupDetail groupDetail : visibleGroups.getGroups()) {
|
||||
final VisibleGroups visibleGroups = visibleGroupsFactory.create();
|
||||
visibleGroups.setProjects(projects);
|
||||
final GroupList groupList = visibleGroups.get();
|
||||
for (final GroupDetail groupDetail : groupList.getGroups()) {
|
||||
stdout.print(groupDetail.group.getName() + "\n");
|
||||
}
|
||||
} catch (OrmException e) {
|
||||
|
Reference in New Issue
Block a user