Extensibility, Cleanup For Client Helper
Change-Id: Ifa24e952c1b49d7d3a5b971906915ae1560086c8
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1133
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/AsterixHelperExecution.java b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/AsterixHelperExecution.java
index 82e8386..419e660 100644
--- a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/AsterixHelperExecution.java
+++ b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/AsterixHelperExecution.java
@@ -33,6 +33,7 @@
public class AsterixHelperExecution {
public static final String ASTERIX_HELPER = "asterixhelper";
+ public static final int COMMAND_USAGE_ALIGNMENT = 20;
protected AsterixHelperExecution() {
}
@@ -41,7 +42,7 @@
"squid:S106", // use of System.err
"squid:S1166" // rethrow or log exception
})
- protected int execute(String [] argArray) throws IOException {
+ public int execute(String [] argArray) throws IOException {
Args args = createArgs();
CmdLineParser parser = createParser(args);
try {
@@ -59,7 +60,7 @@
System.err.println("ERROR: " + e.getMessage() + "\n\n"
+ "Usage: " + getHelperCommandName() + " [options] <command>\n\n"
+ "Commands:");
- printCommandUsage(System.err);
+ printCommandsUsage(System.err);
System.err.println("Options:");
parser.printUsage(System.err);
System.err.flush();
@@ -71,12 +72,20 @@
return ASTERIX_HELPER;
}
- protected void printCommandUsage(PrintStream out) {
+ protected void printCommandsUsage(PrintStream out) {
for (Command command : Command.values()) {
- out.println(" " + command.name().toLowerCase() + " " + command.usage());
+ printCommandUsage(out, command.name(), command.usage());
}
}
+ protected void printCommandUsage(PrintStream out, String name, String usage) {
+ StringBuilder padding = new StringBuilder();
+ for (int i = name.length(); i < COMMAND_USAGE_ALIGNMENT; i++) {
+ padding.append(' ');
+ }
+ out.println(" " + name.toLowerCase() + padding.toString() + " : " + usage);
+ }
+
protected CmdLineParser createParser(Args args) {
return new CmdLineParser(args, ParserProperties.defaults().withUsageWidth(120));
}
diff --git a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/ClientCommand.java b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/ClientCommand.java
index 734d87b..8f0cac0 100644
--- a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/ClientCommand.java
+++ b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/ClientCommand.java
@@ -28,9 +28,9 @@
public abstract class ClientCommand {
public enum Command {
- GET_CLUSTER_STATE("- Get state of cluster (errorcode 0 = UP, non-zero = DOWN)"),
- WAIT_FOR_CLUSTER(" - Wait for cluster to be ready (errorcode 0 = UP, non-zero = UNKNOWN)\")"),
- SHUTDOWN_CLUSTER(" - Instructs the cluster to shut down"),;
+ GET_CLUSTER_STATE("Get state of cluster (errorcode 0 = UP, non-zero = DOWN)"),
+ WAIT_FOR_CLUSTER("Wait for cluster to be ready (errorcode 0 = UP, non-zero = UNKNOWN)"),
+ SHUTDOWN_CLUSTER("Instructs the cluster to shut down"),;
private final String usage;
private static final Map<String, Command> nameMap = new HashMap<>();
diff --git a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/RemoteCommand.java b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/RemoteCommand.java
index 1440b70..77ccbb4 100644
--- a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/RemoteCommand.java
+++ b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/RemoteCommand.java
@@ -26,7 +26,7 @@
import org.apache.asterix.clienthelper.Args;
public abstract class RemoteCommand extends ClientCommand {
- enum Method {
+ protected enum Method {
GET,
POST
}