mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
reformat file
This commit is contained in:
parent
e673197161
commit
2091c5ad5a
@ -8,10 +8,9 @@ import java.util.*;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulate Command parsing and structure for the NoSQLBench command line.
|
* Encapsulate Command parsing and structure for the NoSQLBench command line. Commands always have a name, sometimes
|
||||||
* Commands always have a name, sometimes have a list of positional arguments,
|
* have a list of positional arguments, and sometimes have a map of named parameters. An example of a command tha thas
|
||||||
* and sometimes have a map of named parameters.
|
* both would look like {@code script test.js p1=v1}
|
||||||
* An example of a command tha thas both would look like {@code script test.js p1=v1}
|
|
||||||
*/
|
*/
|
||||||
public class Cmd {
|
public class Cmd {
|
||||||
|
|
||||||
@ -72,8 +71,9 @@ public class Cmd {
|
|||||||
public static Arg<String> of(String name) {
|
public static Arg<String> of(String name) {
|
||||||
return new Arg<>(name, s -> s, false);
|
return new Arg<>(name, s -> s, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Arg<String> ofFreeform(String name) {
|
public static Arg<String> ofFreeform(String name) {
|
||||||
return new Arg<>(name, s->s, true);
|
return new Arg<>(name, s -> s, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ public class Cmd {
|
|||||||
for (String value : getParams().values()) {
|
for (String value : getParams().values()) {
|
||||||
String trimmed = ((value.startsWith("'") && value.endsWith("'"))
|
String trimmed = ((value.startsWith("'") && value.endsWith("'"))
|
||||||
|| (value.startsWith("\"")) && value.endsWith("\"")) ?
|
|| (value.startsWith("\"")) && value.endsWith("\"")) ?
|
||||||
value.substring(1,value.length()-1) : value;
|
value.substring(1, value.length() - 1) : value;
|
||||||
sb.append("'").append(trimmed).append("'").append(",");
|
sb.append("'").append(trimmed).append("'").append(",");
|
||||||
}
|
}
|
||||||
sb.setLength(sb.length() - 1);
|
sb.setLength(sb.length() - 1);
|
||||||
@ -131,18 +131,18 @@ public class Cmd {
|
|||||||
|
|
||||||
if (nextarg == null) {
|
if (nextarg == null) {
|
||||||
throw new InvalidParameterException(
|
throw new InvalidParameterException(
|
||||||
"command '" + cmdName + " requires a value for " + arg.name
|
"command '" + cmdName + " requires a value for " + arg.name
|
||||||
+ ", but there were no remaining arguments after it.");
|
+ ", but there were no remaining arguments after it.");
|
||||||
} else if (arg.freeform) {
|
} else if (arg.freeform) {
|
||||||
logger.debug("freeform parameter:" + nextarg);
|
logger.debug("freeform parameter:" + nextarg);
|
||||||
} else if (nextarg.contains("=")) {
|
} else if (nextarg.contains("=")) {
|
||||||
throw new InvalidParameterException(
|
throw new InvalidParameterException(
|
||||||
"command '" + cmdName + "' requires a value for " + arg.name + "" +
|
"command '" + cmdName + "' requires a value for " + arg.name + "" +
|
||||||
", but a named parameter was found instead: " + nextarg);
|
", but a named parameter was found instead: " + nextarg);
|
||||||
} else if (NBCLIOptions.RESERVED_WORDS.contains(nextarg)) {
|
} else if (NBCLIOptions.RESERVED_WORDS.contains(nextarg)) {
|
||||||
throw new InvalidParameterException(
|
throw new InvalidParameterException(
|
||||||
"command '" + cmdName + "' requires a value for " + arg.name
|
"command '" + cmdName + "' requires a value for " + arg.name
|
||||||
+ ", but a reserved word was found instead: " + nextarg);
|
+ ", but a reserved word was found instead: " + nextarg);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("cmd name:" + cmdName + ", positional " + arg.name + ": " + nextarg);
|
logger.debug("cmd name:" + cmdName + ", positional " + arg.name + ": " + nextarg);
|
||||||
@ -150,8 +150,8 @@ public class Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (arglist.size() > 0 &&
|
while (arglist.size() > 0 &&
|
||||||
!NBCLIOptions.RESERVED_WORDS.contains(arglist.peekFirst())
|
!NBCLIOptions.RESERVED_WORDS.contains(arglist.peekFirst())
|
||||||
&& arglist.peekFirst().contains("=")) {
|
&& arglist.peekFirst().contains("=")) {
|
||||||
String arg = arglist.removeFirst();
|
String arg = arglist.removeFirst();
|
||||||
String[] assigned = arg.split("=", 2);
|
String[] assigned = arg.split("=", 2);
|
||||||
String pname = assigned[0];
|
String pname = assigned[0];
|
||||||
@ -179,9 +179,9 @@ public class Cmd {
|
|||||||
String key = entries.getKey();
|
String key = entries.getKey();
|
||||||
String value = sanitizeQuotes(entries.getValue());
|
String value = sanitizeQuotes(entries.getValue());
|
||||||
if (oneline) {
|
if (oneline) {
|
||||||
l.add("'" + key + "':'"+value+"'");
|
l.add("'" + key + "':'" + value + "'");
|
||||||
} else {
|
} else {
|
||||||
l.add(" '"+key+"': " + " ".repeat(klen - key.length()) + "'" + value + "'");
|
l.add(" '" + key + "': " + " ".repeat(klen - key.length()) + "'" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "{" + (oneline ? "" : "\n") + String.join(",\n", l) + (oneline ? "}" : "\n}");
|
return "{" + (oneline ? "" : "\n") + String.join(",\n", l) + (oneline ? "}" : "\n}");
|
||||||
@ -189,10 +189,10 @@ public class Cmd {
|
|||||||
|
|
||||||
private static String sanitizeQuotes(String value) {
|
private static String sanitizeQuotes(String value) {
|
||||||
if (value.startsWith("'") && value.endsWith("'")) {
|
if (value.startsWith("'") && value.endsWith("'")) {
|
||||||
return value.substring(1,value.length()-1);
|
return value.substring(1, value.length() - 1);
|
||||||
}
|
}
|
||||||
if (value.startsWith("\"") && value.endsWith("\"")) {
|
if (value.startsWith("\"") && value.endsWith("\"")) {
|
||||||
return value.substring(1,value.length()-1);
|
return value.substring(1, value.length() - 1);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user