Add ssh command to list groups.

Change-Id: Iaae73ec644e4f1ca631e8be1d90f7334ae5bd8c7
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2011-09-01 15:55:15 +02:00
parent 8e7a35be30
commit cf6c35942d
9 changed files with 163 additions and 14 deletions

View File

@@ -37,6 +37,7 @@ public class DefaultCommandModule extends CommandModule {
command(gerrit).toProvider(new DispatchCommandProvider(gerrit));
command(gerrit, "flush-caches").to(FlushCaches.class);
command(gerrit, "ls-projects").to(ListProjects.class);
command(gerrit, "ls-groups").to(ListGroupsCommand.class);
command(gerrit, "query").to(Query.class);
command(gerrit, "show-caches").to(ShowCaches.class);
command(gerrit, "show-connections").to(ShowConnections.class);

View File

@@ -0,0 +1,62 @@
// Copyright (C) 2011 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.sshd.commands;
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.sshd.BaseCommand;
import com.google.gwtorm.client.OrmException;
import com.google.inject.Inject;
import org.apache.sshd.server.Environment;
import java.io.IOException;
import java.io.PrintWriter;
public class ListGroupsCommand extends BaseCommand {
@Inject
private VisibleGroups.Factory visibleGroupsFactory;
@Override
public void start(final Environment env) throws IOException {
startThread(new CommandRunnable() {
@Override
public void run() throws Exception {
parseCommandLine();
ListGroupsCommand.this.display();
}
});
}
private void display() throws Failure {
final PrintWriter stdout = toPrintWriter(out);
try {
final GroupList visibleGroups =
visibleGroupsFactory.create().get();
for (final GroupDetail groupDetail : visibleGroups.getGroups()) {
stdout.print(groupDetail.group.getName() + "\n");
}
} catch (OrmException e) {
throw die(e);
} catch (NoSuchGroupException e) {
throw die(e);
} finally {
stdout.flush();
}
}
}