Add description for commands disabled in slave mode

Running the `gerrit` ssh command without arguments to a server that
is running in slave mode results in a list of available commands
being shown.

In this list, the commands that are disabled in slave mode do not
have any description.

Add a description mentioning that the command is disabled due to
the server running in slave mode.

Bug: Issue 2424
Change-Id: Iffc43a921e70a9ed9008a62dcec12b80683b71b3
This commit is contained in:
David Pursehouse
2014-01-24 13:50:36 +09:00
parent 6ef51f6615
commit 84bcead690
2 changed files with 8 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.CapabilityUtils; import com.google.gerrit.server.account.CapabilityUtils;
import com.google.gerrit.server.args4j.SubcommandHandler; import com.google.gerrit.server.args4j.SubcommandHandler;
import com.google.gerrit.sshd.commands.ErrorSlaveMode;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
@@ -154,9 +155,13 @@ final class DispatchCommand extends BaseCommand {
String format = "%-" + maxLength + "s %s"; String format = "%-" + maxLength + "s %s";
for (String name : Sets.newTreeSet(commands.keySet())) { for (String name : Sets.newTreeSet(commands.keySet())) {
final CommandProvider p = commands.get(name); final CommandProvider p = commands.get(name);
Command c = p.getProvider().get();
String description = c instanceof ErrorSlaveMode
? "Command disabled: server is running in slave mode"
: Strings.nullToEmpty(p.getDescription());
usage.append(" "); usage.append(" ");
usage.append(String.format(format, name, usage.append(String.format(format, name, description));
Strings.nullToEmpty(p.getDescription())));
usage.append("\n"); usage.append("\n");
} }
usage.append("\n"); usage.append("\n");

View File

@@ -25,7 +25,7 @@ import java.io.IOException;
* server. This is used when a user tries to run a command on a server in Slave * server. This is used when a user tries to run a command on a server in Slave
* Mode, but the command only applies to the Master server. * Mode, but the command only applies to the Master server.
*/ */
final class ErrorSlaveMode extends BaseCommand { public final class ErrorSlaveMode extends BaseCommand {
@Override @Override
public void start(final Environment env) { public void start(final Environment env) {
String msg = String msg =