package hm.binkley.inject;

import com.google.inject.AbstractModule;
import com.google.inject.Module;
import org.aeonbits.owner.Config;
import org.aeonbits.owner.ConfigFactory;

import javax.annotation.Nonnull;

/**
 * {@code OwnerModule} is light-weight wiring of an OWNER API config instance into Guice.
 * <p/>
 * Guice does not support generic provider methods; each config needs to be separately configured.
 *
 * @author <a href="mailto:binkley@alumni.rice.edu">B. K. Oxley (binkley)</a>
 */
public final class OwnerModule<C extends Config>
        extends AbstractModule {
    private final Class<C> configType;

    private OwnerModule(final Class<C> configType) {
        this.configType = configType;
    }

    /**
     * Creates a new Guice module for the given OWNER API config class.
     *
     * @param configType the config class, never missing
     * @param <C> the config type
     *
     * @return the Guice module, never missing
     */
    @Nonnull
    public static <C extends Config> Module ownerModule(@Nonnull final Class<C> configType) {
        return new OwnerModule<>(configType);
    }

    @Override
    protected void configure() {
        bind(configType).toInstance(
                ConfigFactory.create(configType, System.getProperties(), System.getenv()));
    }
}

@@ -203,16 +203,64 @@
 Nonnull;
+%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -659,16 +659,83 @@
 figType;
+%0A    private final Map%3CString, String%3E overrides = new HashMap%3C%3E();
 %0A%0A    pr
@@ -822,24 +822,201 @@
 ype;%0A    %7D%0A%0A
+    private OwnerModule(final Class%3CC%3E configType, final Map%3CString, String%3E overrides) %7B%0A        this.configType = configType;%0A        this.overrides.putAll(overrides);%0A    %7D%0A%0A
     /**%0A    
@@ -1411,117 +1411,715 @@
     
-@Override%0A    protected void configure() %7B%0A        bind(configType).toInstance(
+/**%0A     * Creates a new Guice module for the given OWNER API config class with %3Cvar%3Eoverrides%3C/var%3E,%0A     * for example from commandline options.%0A     *%0A     * @param configType the config class, never missing%0A     * @param overrides more configuration, never missing%0A     * @param %3CC%3E the config type%0A     *%0A     * @return the Guice module, never missing%0A     */%0A    @Nonnull%0A    public static %3CC extends Config%3E Module ownerModule(@Nonnull final Class%3CC%3E configType,%0A            @Nonnull final Map%3CString, String%3E overrides) %7B%0A        return new OwnerModule%3C%3E(configType, overrides);
 %0A    
+%7D%0A%0A
     
-        ConfigFactory
+@Override%0A    protected void configure() %7B%0A        bind(configType).toInstance(ConfigFactory%0A                
 .cre
@@ -2133,16 +2133,27 @@
 figType,
+ overrides,
  System.

Include overrides for owner module.