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.