mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-21 12:27:37 +00:00
Merge pull request #13737 from jasontedor/cli-parameter-order-error-message
More helpful error message on parameter order
This commit is contained in:
commit
8d1d8f9c46
@ -128,8 +128,14 @@ final class BootstrapCLIParser extends CliTool {
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
String arg = iterator.next();
|
String arg = iterator.next();
|
||||||
if (!arg.startsWith("--")) {
|
if (!arg.startsWith("--")) {
|
||||||
|
if (arg.startsWith("-D") || arg.startsWith("-d") || arg.startsWith("-p")) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Parameter [" + arg + "] starting with \"-D\", \"-d\" or \"-p\" must be before any parameters starting with --"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
throw new IllegalArgumentException("Parameter [" + arg + "]does not start with --");
|
throw new IllegalArgumentException("Parameter [" + arg + "]does not start with --");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// if there is no = sign, we have to get the next argu
|
// if there is no = sign, we have to get the next argu
|
||||||
arg = arg.replace("--", "");
|
arg = arg.replace("--", "");
|
||||||
if (arg.contains("=")) {
|
if (arg.contains("=")) {
|
||||||
|
@ -220,6 +220,16 @@ public class BootstrapCliParserTests extends CliToolTestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testThatHelpfulErrorMessageIsGivenWhenParametersAreOutOfOrder() throws Exception {
|
||||||
|
BootstrapCLIParser parser = new BootstrapCLIParser(terminal);
|
||||||
|
try {
|
||||||
|
parser.parse("start", new String[]{"--foo=bar", "-Dbaz=qux"});
|
||||||
|
fail("expected IllegalArgumentException for out-of-order parameters");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
assertThat(e.getMessage(), containsString("must appear before any parameters starting with --"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void registerProperties(String ... systemProperties) {
|
private void registerProperties(String ... systemProperties) {
|
||||||
propertiesToClear.addAll(Arrays.asList(systemProperties));
|
propertiesToClear.addAll(Arrays.asList(systemProperties));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user