Merge pull request #17289 from rjernst/cli-args

Cli: Reject positional argument for bin/elasticsearch
This commit is contained in:
Ryan Ernst 2016-03-23 11:53:32 -07:00
commit 6e74d1d0c9
2 changed files with 27 additions and 0 deletions

View File

@ -76,6 +76,9 @@ class Elasticsearch extends Command {
@Override
protected void execute(Terminal terminal, OptionSet options) throws Exception {
if (options.nonOptionArguments().isEmpty() == false) {
throw new UserError(ExitCodes.USAGE, "Positional arguments not allowed, found " + options.nonOptionArguments());
}
if (options.has(versionOption)) {
if (options.has(daemonizeOption) || options.has(pidfileOption)) {
throw new UserError(ExitCodes.USAGE, "Elasticsearch version option is mutually exclusive with any other option");

View File

@ -76,6 +76,30 @@ public class ElasticsearchCliTests extends ESTestCase {
runTest(expectedStatus, false, outputConsumer, (foreground, pidFile, esSettings) -> {}, args);
}
public void testPositionalArgs() throws Exception {
runTest(
ExitCodes.USAGE,
false,
output -> assertThat(output, containsString("Positional arguments not allowed, found [foo]")),
(foreground, pidFile, esSettings) -> {},
"foo"
);
runTest(
ExitCodes.USAGE,
false,
output -> assertThat(output, containsString("Positional arguments not allowed, found [foo, bar]")),
(foreground, pidFile, esSettings) -> {},
"foo", "bar"
);
runTest(
ExitCodes.USAGE,
false,
output -> assertThat(output, containsString("Positional arguments not allowed, found [foo]")),
(foreground, pidFile, esSettings) -> {},
"-E", "something", "foo", "-E", "somethingelse"
);
}
public void testThatPidFileCanBeConfigured() throws Exception {
runPidFileTest(ExitCodes.USAGE, false, output -> assertThat(output, containsString("Option p/pidfile requires an argument")), "-p");
runPidFileTest(ExitCodes.OK, true, output -> {}, "-p", "/tmp/pid");