refactoring option configs processing
@@ -47,7 +47,6 @@ public class JsonNodeConfigurationFactoryProvider implements Provider<Configurat
private Set<OptionMetadata> optionMetadataSet;
private Cli cli;
-
@Inject
public JsonNodeConfigurationFactoryProvider(
ConfigurationSource configurationSource,
@@ -115,14 +114,9 @@ public class JsonNodeConfigurationFactoryProvider implements Provider<Configurat
for (OptionSpec<?> cliOpt : detectedOptions) {
- List<String> optionNames = cliOpt.options();
+ OptionMetadata omd = findMetadata(cliOpt);
- // TODO: allow lookup of option metadata by name to avoid linear scans...
- // Though we are dealing with small collection, so shouldn't be too horrible.
-
- for (OptionMetadata omd : optionMetadataSet) {
-
- if (!optionNames.contains(omd.getName())) {
+ if(omd == null) {
continue;
}
@@ -139,7 +133,6 @@ public class JsonNodeConfigurationFactoryProvider implements Provider<Configurat
sources.add(omd.getConfigResource().getUrl());
}
}
- }
if (!options.isEmpty()) {
overrider = overrider.andThen(new InPlaceMapOverrider(options, true, '.'));
@@ -152,6 +145,23 @@ public class JsonNodeConfigurationFactoryProvider implements Provider<Configurat
return overrider;
}
+ private OptionMetadata findMetadata(OptionSpec<?> option) {
+
+ List<String> optionNames = option.options();
+
+ // TODO: allow lookup of option metadata by name to avoid linear scans...
+ // Though we are dealing with small collection, so shouldn't be too horrible.
+
+ for (OptionMetadata omd : optionMetadataSet) {
+ if (optionNames.contains(omd.getName())) {
+ return omd;
+ }
+ }
+
+ // this was likely a command, not an option.
+ return null;
+ }
+
@Override
public ConfigurationFactory get() {
