Display command description in ssh gerrit --help

Show one line description for each ssh command. Make COMMAND
argument optional, so that --help argument is not needed.

This approach is working for core gerrit commands, aliases, nested
commands and plugin's own ssh commands.

To provide a description ssh command must be annotated with
CommandMetaData annotation, i. e.:

@CommandMetaData(name="print", descr="Print greeting in different languages")
public final class PrintHelloWorldCommand extends SshCommand { ...

Syntactic sugar for command registration is provided to reflect the fact,
that both name and description are included in CommandMetaData annotation.

To register command and alias in plugin:
protected void configureCommands() {
  command(PrintHelloWorldCommand.class);
  alias("say-hello", PrintHelloWorldCommand.class);
[...]

With the outcome:
$ ssh gerrit helloworld
Available commands of helloworld are:

   print       Print greeting in different languages
   say-hello   Print greeting in different languages

Change-Id: I2e5440378023ecc5425092d8131f121da2f20a30
This commit is contained in:
David Ostrovsky
2013-01-13 16:00:45 +01:00
parent 1756441516
commit e51c428fe5
39 changed files with 281 additions and 62 deletions

View File

@@ -18,6 +18,7 @@ import com.google.common.collect.Sets;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.server.plugins.PluginLoader;
import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand;
import com.google.inject.Inject;
@@ -26,6 +27,7 @@ import org.kohsuke.args4j.Argument;
import java.util.List;
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
@CommandMetaData(name = "remove", descr = "Disable plugins")
final class PluginRemoveCommand extends SshCommand {
@Argument(index = 0, metaVar = "NAME", required = true, usage = "plugin to remove")
List<String> names;