Add an argument and option
Gives some more examples to plugin authors on how to accept arguments
and options with their custom SSH commands.
Change-Id: Ib784a79aebd01aa9567251012769f94c6603bde5
Signed-off-by: Brad Larson <bklarson@gmail.com>
diff --git a/src/main/java/com/google/gerrit/plugins/PrintHelloWorldCommand.java b/src/main/java/com/google/gerrit/plugins/PrintHelloWorldCommand.java
index 408a2c9..d5412ed 100644
--- a/src/main/java/com/google/gerrit/plugins/PrintHelloWorldCommand.java
+++ b/src/main/java/com/google/gerrit/plugins/PrintHelloWorldCommand.java
@@ -16,11 +16,22 @@
import com.google.gerrit.sshd.SshCommand;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
+
public final class PrintHelloWorldCommand extends SshCommand {
+
+ @Argument(usage = "name of user")
+ private String name = "world";
+
+ @Option(name = "--french", usage = "output in French?")
+ private boolean french = false;
+
@Override
public void run() throws UnloggedFailure, Failure, Exception {
+ final String greeting = (french ? "Bonjour " : "Hello ");
// Note the use of '\n' instead of println to keep platform-agnostic line
// terminator.
- stdout.print("Hello world!\n");
+ stdout.print(greeting + name + "!\n");
}
}