make argsfiles use double dash

This commit is contained in:
Jonathan Shook
2020-10-26 12:08:05 -05:00
parent a9b0dc9dd0
commit b9607d07e6
4 changed files with 37 additions and 35 deletions

View File

@@ -19,19 +19,19 @@ import java.util.stream.Collectors;
*
* <H1>ArgsFile Selection</H1>
*
* During processing, any occurence of '-argsfile' selects the active argsfile and loads
* it into the command line in place of the '-argsfile' argument. By default the args file
* During processing, any occurence of '--argsfile' selects the active argsfile and loads
* it into the command line in place of the '--argsfile' argument. By default the args file
* will be loaded if it exists, and a warning will be given if it does not.
*
* The '-argsfile-required &lt;somepath&gt;' version will throw an error if the args file
* The '--argsfile-required &lt;somepath&gt;' version will throw an error if the args file
* is not present, but it will not report any warnings or details otherwise.
*
* The `-argsfile-optional &lt;somepath&gt; version will not throw an error if the args
* The `--argsfile-optional &lt;somepath&gt; version will not throw an error if the args
* file is not present, and it will not report any warnings or details otherwise.
*
* A prefix command line can be given to ArgsFile to pre-load any settings. In this way
* it is possible to easily provide a default args file which will be loaded. For example,
* A prefix command of '-argsfile-optional &lt;somepath&gt;' will load options if they are
* A prefix command of '--argsfile-optional &lt;somepath&gt;' will load options if they are
* available in the specified file, but will otherwise provide no feedback to the user.
*
* <H1>ArgsFile Injection</H1>
@@ -92,29 +92,29 @@ public class ArgsFile {
while (commandline.peekFirst() != null) {
String arg = commandline.peekFirst();
switch (arg) {
case "-argsfile":
case "--argsfile":
commandline.removeFirst();
String argspath = readWordOrThrow(commandline, "path to an args file");
setArgsFile(argspath, Selection.WarnIfMissing);
commandline = loadArgs(this.argsPath, Selection.WarnIfMissing, commandline);
break;
case "-argsfile-required":
case "--argsfile-required":
commandline.removeFirst();
String argspathRequired = readWordOrThrow(commandline, "path to an args file");
setArgsFile(argspathRequired, Selection.ErrorIfMissing);
commandline = loadArgs(this.argsPath, Selection.ErrorIfMissing, commandline);
break;
case "-argsfile-optional":
case "--argsfile-optional":
commandline.removeFirst();
String argspathOptional = readWordOrThrow(commandline, "path to an args file");
setArgsFile(argspathOptional, Selection.IgnoreIfMissing);
commandline = loadArgs(this.argsPath, Selection.IgnoreIfMissing, commandline);
break;
case "-pin":
case "--pin":
commandline.removeFirst();
commandline = pinArg(commandline);
break;
case "-unpin":
case "--unpin":
commandline.removeFirst();
commandline = unpinArg(commandline);
break;

View File

@@ -26,10 +26,10 @@ public class NBCLIOptions {
// Options which may contextualize other CLI options or commands.
// These must be parsed first
private static final String ARGS_FILE = "-argsfile";
private static final String ARGS_FILE = "--argsfile";
private static final String ARGS_FILE_DEFAULT = "$HOME/.nosqlbench/argsfile";
private static final String ARGS_PIN = "-pin";
private static final String ARGS_UNPIN = "-unpin";
private static final String ARGS_PIN = "--pin";
private static final String ARGS_UNPIN = "--unpin";
private static final String INCLUDE = "--include";
private static final String METRICS_PREFIX = "--metrics-prefix";
@@ -164,7 +164,7 @@ public class NBCLIOptions {
private LinkedList<String> parseGlobalOptions(String[] args) {
ArgsFile argsfile = new ArgsFile();
argsfile.preload("-argsfile-optional", ARGS_FILE_DEFAULT);
argsfile.preload("--argsfile-optional", ARGS_FILE_DEFAULT);
LinkedList<String> arglist = new LinkedList<>() {{
addAll(Arrays.asList(args));

View File

@@ -13,9 +13,9 @@ public class ArgsFileTest {
public void testLoadingArgs() {
LinkedList<String> result;
ArgsFile argsFile = new ArgsFile();
result = argsFile.process("-argsfile", "src/test/resources/argsfiles/nonextant.cli");
result = argsFile.process("--argsfile", "src/test/resources/argsfiles/nonextant.cli");
assertThat(result).containsExactly();
result = argsFile.process("-argsfile", "src/test/resources/argsfiles/alphagamma.cli");
result = argsFile.process("--argsfile", "src/test/resources/argsfiles/alphagamma.cli");
assertThat(result).containsExactly("alpha", "gamma");
}
@@ -23,17 +23,18 @@ public class ArgsFileTest {
public void testLoadingMissingRequiredFails() {
LinkedList<String> result;
ArgsFile argsFile = new ArgsFile();
result = argsFile.process("-argsfile-required", "src/test/resources/argsfiles/nonextant.cli");
result = argsFile.process("--argsfile-required", "src/test/resources/argsfiles/nonextant.cli");
}
@Test
public void testLoadingInPlace() {
LinkedList<String> result;
LinkedList<String> commands = new LinkedList<>(List.of("--abc", "--def", "-argsfile", "src/test/resources/argsfiles/alphagamma.cli"));
ArgsFile argsFile = new ArgsFile().preload("-argsfile-optional", "src/test/resources/argsfiles/alphagamma.cli");
LinkedList<String> commands = new LinkedList<>(List.of("--abc", "--def", "--argsfile", "src/test/resources" +
"/argsfiles/alphagamma.cli"));
ArgsFile argsFile = new ArgsFile().preload("--argsfile-optional", "src/test/resources/argsfiles/alphagamma" +
".cli");
result = argsFile.process(commands);
assertThat(result).containsExactly("alpha", "gamma", "--abc", "--def", "alpha", "gamma");
}
}