ConfigurationBuilder { public ConfigurationBuilder addCommandlineArgs(final String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(commandlineOptions, args, false); } catch (ParseException e) { HelpFormatter formater = new HelpFormatter(); formater.setWidth(120); formater.printHelp("Main", commandlineOptions); throw new RuntimeException(); } Map<String, String> cliProps = new HashMap<>(); for (Option o : cmd.getOptions()) { cliProps.put(o.getArgName(), o.getValue()); } cliConfiguration = new MapConfiguration(cliProps); return this; } ConfigurationBuilder(); ConfigurationBuilder withDefaults(
            final Map<String, Object> defaults); ConfigurationBuilder withCommandlineOptions(final Options options); ConfigurationBuilder addCommandlineArgs(final String[] args); ConfigurationBuilder addPropertiesFile(final String path); ConfigurationBuilder addPropertiesFile(final File file); Configuration build();  }
@Test public void addCommandlineArgs() { Configuration config = new ConfigurationBuilder() .withCommandlineOptions(ServerFactory.CLI_OPTIONS) .addCommandlineArgs(new String[]{ "-h=example.com", "-p=9000", "--kangaroo.working_dir=/opt/kangaroo", "--kangaroo.keystore_path=/foo/bar", "--kangaroo.keystore_password=keystore_password", "--kangaroo.keystore_type=JKS", "--kangaroo.cert_alias=cert_alias", "--kangaroo.cert_key_password=key_password", "--kangaroo.html_app_root=/var/www" }) .build(); assertEquals(config.getString( Config.HOST.getKey()), "example.com"); assertEquals(config.getInt( Config.PORT.getKey()), 9000); assertEquals(config.getString( Config.WORKING_DIR.getKey()), "/opt/kangaroo"); assertEquals(config.getString( Config.KEYSTORE_PATH.getKey()), "/foo/bar"); assertEquals(config.getString( Config.KEYSTORE_PASS.getKey()), "keystore_password"); assertEquals(config.getString( Config.KEYSTORE_TYPE.getKey()), "JKS"); assertEquals(config.getString( Config.CERT_ALIAS.getKey()), "cert_alias"); assertEquals(config.getString( Config.CERT_KEY_PASS.getKey()), "key_password"); assertEquals(config.getString( Config.HTML_APP_ROOT.getKey()), "/var/www"); }