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:
@@ -48,7 +48,7 @@ public abstract class CommandModule extends AbstractModule {
|
||||
/**
|
||||
* Configure a command to be invoked by name.
|
||||
*
|
||||
*@param parent context of the parent command, that this command is a
|
||||
* @param parent context of the parent command, that this command is a
|
||||
* subcommand of.
|
||||
* @param name the name of the command the client will provide in order to
|
||||
* call the command.
|
||||
@@ -60,6 +60,42 @@ public abstract class CommandModule extends AbstractModule {
|
||||
return bind(Commands.key(parent, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a command to be invoked by name. The command is bound to the passed class.
|
||||
*
|
||||
* @param parent context of the parent command, that this command is a
|
||||
* subcommand of.
|
||||
* @param clazz class of the command with {@link CommandMetaData} annotation
|
||||
* to retrieve the name and the description from
|
||||
*/
|
||||
protected void command(final CommandName parent,
|
||||
final Class<? extends BaseCommand> clazz) {
|
||||
CommandMetaData meta = (CommandMetaData)clazz.getAnnotation(CommandMetaData.class);
|
||||
if (meta == null) {
|
||||
throw new IllegalStateException("no CommandMetaData annotation found");
|
||||
}
|
||||
bind(Commands.key(parent, meta.name(), meta.descr())).to(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias one command to another. The alias is bound to the passed class.
|
||||
*
|
||||
* @param parent context of the parent command, that this command is a
|
||||
* subcommand of.
|
||||
* @param name the name of the command the client will provide in order to
|
||||
* call the command.
|
||||
* @param clazz class of the command with {@link CommandMetaData} annotation
|
||||
* to retrieve the description from
|
||||
*/
|
||||
protected void alias(final CommandName parent, final String name,
|
||||
final Class<? extends BaseCommand> clazz) {
|
||||
CommandMetaData meta = (CommandMetaData)clazz.getAnnotation(CommandMetaData.class);
|
||||
if (meta == null) {
|
||||
throw new IllegalStateException("no CommandMetaData annotation found");
|
||||
}
|
||||
bind(Commands.key(parent, name, meta.descr())).to(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias one command to another.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user