Menu

#5 Allow option to load default values from

open
nobody
None
5
2010-09-21
2010-09-21
Anonymous
No

It would be nice to have a new option -c or --configfile for reading from a config file; these will become default values and can be overridden. IE,

myconfigfile.ini:
a=foo
b=bar

args code:
String[] args = new String[] { "-c", "myconfigfile.ini", "-b", "myoverride" };

parser code:
OptionParser parser = new OptionParser() {
{
accepts("a", "yyy").withRequiredArg();
accepts("b", "xxx").withRequiredArg();
useConfigFile(true); // enables -c or --configfile
}
};

OptionSet options = parser.parse(args);
String a = (String) options.valueOf("a");
String b = (String) options.valueOf("b");

variable a will contain "foo" and variable b will contain "myoverride"

This feature exists in a python library cmdln as the class CmdlnWithConfigParser.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB