I’m going to be writing some command-line utilities which should prompt for various parameters if they are not specified via an option and a value on the command line. To that end, I am interested in adding a feature to do this automatically in commons-cli.
I am also planning to add a way to specify how to interpret values for an option as a type other than String (I know: PatternOptionBuilder can do this, but only for single-letter options). I was thinking of just writing my own personal code (based on commons-cli) to do this, but figured I’d check to see if the dev team thought it might make a good contribution to the code. (Might as well share my efforts if others think they will be useful.) Before continuing, I will note none of the changes I propose would alter the default behavior of commons-cli; existing code that does not invoke the new features would continue to act the same. I am thinking of doing something along the lines of the following: *org.apache.commons.cli.Option* — Allow for two more parameters to be specified: an interpolator and a prompt string. The former would be an interface with a single abstract method whose purpose would be to sanity-check (and, if needed, transform the option argument from a string to another data type). The prompt string, if specified, will cause the option’s associated value to be prompted for if the option was not present on the command line. Both imply that the option in question has an associated value. *org.apache.commons.cli.DefaultParser* — This will have to honor the interpolator and prompt features of the Option object. *org.apache.commons.cli.CommandLine* — The getParsedOptionValue method will return whatever the interpolator (if specified) parsed the option’s value into. * **org.apache.commons.cli.InvalidArgumentException* — (new class, subclass of ParseException) Can be thrown by an interpolator to indicate that the option value in question was not valid. Anyhow, I’d appreciate having some idea of whether the commons-cli dev team would be welcome to a submission of such features on my part. It won’t hurt my feelings any if the answer is “no.” -- David Barts / n5...@me.com He who has nothing to die for has nothing to live for. -- Moroccan proverb