mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
make argsfiles use double dash
This commit is contained in:
parent
a9b0dc9dd0
commit
b9607d07e6
@ -5,7 +5,7 @@ An argsfile (Command Line Arguments File) is a simple text file which
|
||||
file to contain a set of global defaults that you want to use by
|
||||
default and automatically.
|
||||
|
||||
A command, `-argsfile <path>` is used to specify an args file. You can
|
||||
A command, `--argsfile <path>` is used to specify an args file. You can
|
||||
use it like an instant import statement in the middle of a command
|
||||
line. Notice that this option uses only a single dash. This
|
||||
distinguishes the argsfile options from the others in general. These are meta
|
||||
@ -17,8 +17,8 @@ A command, `-argsfile <path>` is used to specify an args file. You can
|
||||
The default args file location is `$HOME/.nosqlbench/argsfile`. If this
|
||||
file is present, it is loaded by nosqlbench when it starts even if you
|
||||
don't ask it to. That is, nosqlbench behaves as if your first set of
|
||||
command line arguments is `-argsfile "$HOME/.nosqlbench/argsfile
|
||||
`. However, unlike when you specify `-argsfile ...` explicitly on
|
||||
command line arguments is `--argsfile "$HOME/.nosqlbench/argsfile
|
||||
`. However, unlike when you specify `--argsfile ...` explicitly on
|
||||
your command line, this form will not throw an error if the file is
|
||||
missing. This means that when you explicitly ask for an args file
|
||||
to be loaded, and it does not exist, an error is thrown. If you
|
||||
@ -36,51 +36,52 @@ An args file simply contains an argument on each line, like this:
|
||||
## Pinning options
|
||||
|
||||
It is possible to pin an option to the default args file by use of the
|
||||
`-pin` meta-option. This option will take the following command line
|
||||
`--pin` meta-option. This option will take the following command line
|
||||
argument and add it to the currently active args file. That means, if
|
||||
you use `-pin --docker-metrics`, then `--docker-metrics` is added to
|
||||
you use `--pin --docker-metrics`, then `--docker-metrics` is added to
|
||||
the args file. If there is an exact duplicate of the same option
|
||||
and value, then it is skipped, but if the option name is the same
|
||||
with a different value, then it is added at the end. This allows
|
||||
for options which may be called multiple times normally.
|
||||
|
||||
If the `-pin` option occurs after an explicit use of `-argsfile
|
||||
If the `--pin` option occurs after an explicit use of `--argsfile
|
||||
<filename>`, then the filename used in this argument is the one that
|
||||
is modified.
|
||||
|
||||
After the `-pin` option, the following argument is taken as any global
|
||||
After the `--pin` option, the following argument is taken as any global
|
||||
option (--with-double-dashes) and any non-option values after it which
|
||||
are not commands (reserved words)
|
||||
|
||||
When the `-pin` option is used, it does not cause the pinned option
|
||||
When the `--pin` option is used, it does not cause the pinned option
|
||||
to be excluded from the current command line call. The effects of the
|
||||
pinned option will take place in the current nosqlbench invocation
|
||||
just as they would without the `-pin`. However, when pinning global
|
||||
just as they would without the `--pin`. However, when pinning global
|
||||
options when there are no commands on the command line, nosqlbench
|
||||
will not run a scenario, so this form is suitable for setting
|
||||
arguments.
|
||||
|
||||
As a special case, if the `-pin` is the last option of
|
||||
As a special case, if the `--pin` is the last option of
|
||||
|
||||
## Unpinning options.
|
||||
|
||||
To reverse the effect of pinning an option, you simply use
|
||||
`-unpin ...`.
|
||||
`--unpin ...`.
|
||||
|
||||
The behavior of -unpin is slightly different than -pin. Specifically,
|
||||
The behavior of --unpin is slightly different than --pin. Specifically,
|
||||
an option which is unpinned will be removed from the arg list, and will
|
||||
not be used in the current invocation of nosqlbench after removal.
|
||||
|
||||
Further, you can specify `-unpin --grafana-baseurl` to unpin an option which
|
||||
Further, you can specify `--unpin --grafana-baseurl` to unpin an option
|
||||
which
|
||||
normally has an argument, and all instances of that argument will be
|
||||
removed. If you want to unpin a specific instance of a multi-valued
|
||||
option, or one that can be specified more than once with different
|
||||
parameter values, then you must provide the value as well, as in
|
||||
`-unpin --log-histograms 'histodata.log:.*:1m'`
|
||||
`--unpin --log-histograms 'histodata.log:.*:1m'`
|
||||
|
||||
# Setting defaults, the simple way
|
||||
|
||||
To simply set global defaults, you can run nosqlbench with a command
|
||||
line like this:
|
||||
|
||||
./nb -pin --docker-metrics-at metricsnode -pin --annotate all
|
||||
./nb --pin --docker-metrics-at metricsnode --pin --annotate all
|
||||
|
@ -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 <somepath>' version will throw an error if the args file
|
||||
* The '--argsfile-required <somepath>' 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 <somepath> version will not throw an error if the args
|
||||
* The `--argsfile-optional <somepath> 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 <somepath>' will load options if they are
|
||||
* A prefix command of '--argsfile-optional <somepath>' 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;
|
||||
|
@ -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));
|
||||
|
@ -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");
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user