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:
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.apache.sshd.server.Command;
|
||||
|
||||
final class CommandProvider {
|
||||
|
||||
private final Provider<Command> provider;
|
||||
private final String description;
|
||||
|
||||
CommandProvider(final Provider<Command> p, final String d) {
|
||||
this.provider = p;
|
||||
this.description = d;
|
||||
}
|
||||
|
||||
public Provider<Command> getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user