Merge "Expose some BaseCommand's methods to support generic SSH commands"

This commit is contained in:
Shawn Pearce
2013-10-16 19:34:41 +00:00
committed by Gerrit Code Review
2 changed files with 41 additions and 3 deletions

View File

@@ -403,6 +403,44 @@ by PrintHello class will be available to users as:
$ ssh -p 29418 review.example.com helloworld print $ 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]]
Configuration Configuration
------------- -------------

View File

@@ -128,11 +128,11 @@ public abstract class BaseCommand implements Command {
} }
@Nullable @Nullable
String getPluginName() { protected String getPluginName() {
return pluginName; return pluginName;
} }
String getName() { protected String getName() {
return commandName; return commandName;
} }
@@ -140,7 +140,7 @@ public abstract class BaseCommand implements Command {
this.commandName = prefix; this.commandName = prefix;
} }
String[] getArguments() { public String[] getArguments() {
return argv; return argv;
} }