Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testElasticsearchSettingCanNotBeEmpty() throws Exception {
}

public void testElasticsearchSettingCanNotBeDuplicated() throws Exception {
assertUsage(containsString("setting [foo] already set, saw [bar] and [baz]"), "-E", "foo=bar", "-E", "foo=baz");
assertUsage(containsString("setting [foo] set twice via command line -E"), "-E", "foo=bar", "-E", "foo=baz");
}

public void testUnknownOption() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ protected Environment createEnv(OptionSet options, ProcessInfo processInfo) thro
throw new UserException(ExitCodes.USAGE, "setting [" + kvp.key + "] must not be empty");
}
if (settings.containsKey(kvp.key)) {
final String message = String.format(
Locale.ROOT,
"setting [%s] already set, saw [%s] and [%s]",
kvp.key,
settings.get(kvp.key),
kvp.value
);
final String message = String.format(Locale.ROOT, "setting [%s] set twice via command line -E", kvp.key);
throw new UserException(ExitCodes.USAGE, message);
}
settings.put(kvp.key, kvp.value);
Expand Down Expand Up @@ -133,18 +127,17 @@ private static void putSystemPropertyIfSettingIsMissing(
final Map<String, String> settings,
final String setting,
final String key
) {
) throws UserException {
final String value = sysprops.get(key);
if (value != null) {
if (settings.containsKey(setting)) {
final String message = String.format(
Locale.ROOT,
"duplicate setting [%s] found via command-line [%s] and system property [%s]",
"setting [%s] found via command-line -E and system property [%s]",
setting,
settings.get(setting),
value
key
);
throw new IllegalArgumentException(message);
throw new UserException(ExitCodes.USAGE, message);
} else {
settings.put(setting, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.cli.CommandTestCase;
import org.elasticsearch.cli.ProcessInfo;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.junit.Before;
Expand Down Expand Up @@ -127,4 +128,15 @@ public void testDockerEnvVarSettingsOverrideCommandLine() throws Exception {
};
execute("-Esimple.setting=original");
}

public void testDuplicateCommandLineSetting() {
var e = expectThrows(UserException.class, () -> execute("-E", "my.setting=foo", "-E", "my.setting=bar"));
assertThat(e.getMessage(), equalTo("setting [my.setting] set twice via command line -E"));
}

public void testConflictingPathCommandLineSettingWithSysprop() {
sysprops.put("es.path.data", "foo");
var e = expectThrows(UserException.class, () -> execute("-E", "path.data=bar"));
assertThat(e.getMessage(), equalTo("setting [path.data] found via command-line -E and system property [es.path.data]"));
}
}