diff --git a/Documentation/dev-plugins.txt b/Documentation/dev-plugins.txt index dcf176e34c..2e74b7c281 100644 --- a/Documentation/dev-plugins.txt +++ b/Documentation/dev-plugins.txt @@ -403,6 +403,44 @@ by PrintHello class will be available to users as: $ ssh -p 29418 review.example.com helloworld print ---- +Multiple SSH commands can be bound to the same implementation class. For +example a Gerrit Shell plugin can bind different shell commands to the same +implementation class: + +[source,java] +---- +public class SshShellModule extends PluginCommandModule { + @Override + protected void configureCommands() { + command("ls").to(ShellCommand.class); + command("ps").to(ShellCommand.class); + [...] + } +} +---- + +With the possible implementation: + +[source,java] +---- +public class ShellCommand extends SshCommand { + @Override + protected void run() throws UnloggedFailure { + String cmd = getName().substring(getPluginName().length() + 1); + ProcessBuilder proc = new ProcessBuilder(cmd); + Process cmd = proc.start(); + [...] + } +} +---- + +And the call: + +---- +$ ssh -p 29418 review.example.com shell ls +$ ssh -p 29418 review.example.com shell ps +---- + [[configuration]] Configuration ------------- diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java index c8b24f727e..4ac8f64a1e 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java @@ -128,11 +128,11 @@ public abstract class BaseCommand implements Command { } @Nullable - String getPluginName() { + protected String getPluginName() { return pluginName; } - String getName() { + protected String getName() { return commandName; } @@ -140,7 +140,7 @@ public abstract class BaseCommand implements Command { this.commandName = prefix; } - String[] getArguments() { + public String[] getArguments() { return argv; }