diff --git a/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java b/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
index d27be965e8..86915fb993 100644
|
a
|
b
|
import org.openstreetmap.josm.data.projection.ProjectionRegistry;
|
| 36 | 36 | import org.openstreetmap.josm.data.projection.Projections; |
| 37 | 37 | import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker; |
| 38 | 38 | import org.openstreetmap.josm.gui.MainApplication; |
| | 39 | import org.openstreetmap.josm.gui.ProgramArguments; |
| 39 | 40 | import org.openstreetmap.josm.gui.io.CustomConfigurator; |
| 40 | 41 | import org.openstreetmap.josm.gui.io.importexport.FileImporter; |
| 41 | 42 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
| … |
… |
public class ValidatorCLI implements CLIModule {
|
| 107 | 108 | /** --load-preferences=<url-to-xml> Changes preferences according to the XML file */ |
| 108 | 109 | LOAD_PREFERENCES(true, 'p'), |
| 109 | 110 | /** --set=<key>=<value> Set preference key to value */ |
| 110 | | SET(true, 's'); |
| | 111 | SET(true, 's', OptionParser.OptionCount.MULTIPLE); |
| 111 | 112 | |
| 112 | 113 | private final String name; |
| 113 | 114 | private final boolean requiresArgument; |
| … |
… |
public class ValidatorCLI implements CLIModule {
|
| 467 | 468 | } |
| 468 | 469 | break; |
| 469 | 470 | case SET: |
| 470 | | |
| | 471 | final Map.Entry<String, String> keyValue = ProgramArguments.parsePreferenceToSet(argument); |
| | 472 | Config.getPref().put(keyValue.getKey(), keyValue.getValue()); |
| | 473 | break; |
| 471 | 474 | default: |
| 472 | 475 | throw new AssertionError("Unexpected option: " + option); |
| 473 | 476 | } |
diff --git a/src/org/openstreetmap/josm/gui/ProgramArguments.java b/src/org/openstreetmap/josm/gui/ProgramArguments.java
index 58353d1378..6b0ec01417 100644
|
a
|
b
|
|
| 1 | 1 | // License: GPL. For details, see LICENSE file. |
| 2 | 2 | package org.openstreetmap.josm.gui; |
| 3 | 3 | |
| | 4 | import java.util.AbstractMap; |
| 4 | 5 | import java.util.ArrayList; |
| 5 | 6 | import java.util.Arrays; |
| 6 | 7 | import java.util.Collection; |
| … |
… |
public class ProgramArguments {
|
| 201 | 202 | */ |
| 202 | 203 | public Map<String, String> getPreferencesToSet() { |
| 203 | 204 | HashMap<String, String> map = new HashMap<>(); |
| 204 | | get(Option.SET).stream().map(i -> i.split("=", 2)).forEach(kv -> map.put(kv[0], getValue(kv))); |
| | 205 | get(Option.SET).stream().map(ProgramArguments::parsePreferenceToSet).forEach(e -> map.put(e.getKey(), e.getValue())); |
| 205 | 206 | return map; |
| 206 | 207 | } |
| 207 | 208 | |
| | 209 | /** |
| | 210 | * Parses a {@code --set} argument. |
| | 211 | * @param keyValue the argument, in the form {@code key=value} |
| | 212 | * @return the key and the value. The value is empty if missing, and {@code null} if it is "null" |
| | 213 | * @since xxx |
| | 214 | */ |
| | 215 | public static Map.Entry<String, String> parsePreferenceToSet(String keyValue) { |
| | 216 | String[] kv = keyValue.split("=", 2); |
| | 217 | return new AbstractMap.SimpleEntry<>(kv[0], getValue(kv)); |
| | 218 | } |
| | 219 | |
| 208 | 220 | private static String getValue(String... kv) { |
| 209 | 221 | if (kv.length < 2) { |
| 210 | 222 | return ""; |
diff --git a/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java b/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java
index f54343a3ff..672294b583 100644
|
a
|
b
|
class ValidatorCLITest {
|
| 190 | 190 | assertEquals(Collections.singletonList("baz"), Config.getPref().getList("plugins")); |
| 191 | 191 | } |
| 192 | 192 | |
| | 193 | /** |
| | 194 | * Test the --set argument |
| | 195 | */ |
| | 196 | @Test |
| | 197 | void testSetPreference() { |
| | 198 | validatorCLI.processArguments(new String[]{"-s", "test.key=foo=bar", "--set=test.other=baz", |
| | 199 | "--input", "resources/styles/standard/elemstyles.mapcss"}); |
| | 200 | assertEquals("foo=bar", Config.getPref().get("test.key")); |
| | 201 | assertEquals("baz", Config.getPref().get("test.other")); |
| | 202 | } |
| | 203 | |
| 193 | 204 | /** |
| 194 | 205 | * Read json objects from a file |
| 195 | 206 | * @param path The file to read |