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

@@ -29,6 +29,7 @@ import com.google.gerrit.server.account.AuthRequest;
import com.google.gerrit.server.account.Realm;
import com.google.gerrit.server.ssh.SshKeyCache;
import com.google.gerrit.sshd.BaseCommand;
import com.google.gerrit.sshd.CommandMetaData;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.ResultSet;
import com.google.inject.Inject;
@@ -46,6 +47,7 @@ import java.util.Collections;
import java.util.List;
/** Set a user's account settings. **/
@CommandMetaData(name = "set-account", descr = "Change an account's settings")
final class SetAccountCommand extends BaseCommand {
@Argument(index = 0, required = true, metaVar = "USER", usage = "full name, email-address, ssh username or account id")