SSH: Inherit some commands from SshCommand
Some SSH command classes were unnecessary inherited from BaseCommand and were doing stdout/stderr initialization on their own. That's what SshCommand class is for. Change-Id: Ia31f1dedbc46b0e19019c905d6b3fad1d87ba7a0
This commit is contained in:
@@ -28,43 +28,36 @@ import com.google.gerrit.server.group.GroupJson;
|
||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||
import com.google.gerrit.server.group.ListGroups;
|
||||
import com.google.gerrit.server.ioutil.ColumnFormatter;
|
||||
import com.google.gerrit.sshd.BaseCommand;
|
||||
import com.google.gerrit.sshd.CommandMetaData;
|
||||
import com.google.gerrit.sshd.SshCommand;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@CommandMetaData(name = "ls-groups", description = "List groups visible to the caller",
|
||||
runsAt = MASTER_OR_SLAVE)
|
||||
public class ListGroupsCommand extends BaseCommand {
|
||||
public class ListGroupsCommand extends SshCommand {
|
||||
@Inject
|
||||
private MyListGroups impl;
|
||||
|
||||
@Override
|
||||
public void start(final Environment env) {
|
||||
startThread(new CommandRunnable() {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
parseCommandLine(impl);
|
||||
if (impl.getUser() != null && !impl.getProjects().isEmpty()) {
|
||||
throw new UnloggedFailure(1, "fatal: --user and --project options are not compatible.");
|
||||
}
|
||||
final PrintWriter stdout = toPrintWriter(out);
|
||||
try {
|
||||
impl.display(stdout);
|
||||
} finally {
|
||||
stdout.flush();
|
||||
}
|
||||
}
|
||||
});
|
||||
public void run() throws Exception {
|
||||
if (impl.getUser() != null && !impl.getProjects().isEmpty()) {
|
||||
throw new UnloggedFailure(1, "fatal: --user and --project options are not compatible.");
|
||||
}
|
||||
impl.display(stdout);
|
||||
}
|
||||
|
||||
private static class MyListGroups extends ListGroups {
|
||||
@Override
|
||||
protected void parseCommandLine() throws UnloggedFailure {
|
||||
parseCommandLine(impl);
|
||||
}
|
||||
|
||||
private static class MyListGroups extends ListGroups {
|
||||
@Option(name = "--verbose", aliases = {"-v"},
|
||||
usage = "verbose output format with tab-separated columns for the " +
|
||||
"group name, UUID, description, owner group name, " +
|
||||
|
Reference in New Issue
Block a user