@@ -41,7 +41,7 @@ private CliTools() {
4141 *
4242 * <p>
4343 * Currently supported property types are <code>int, double,
44- * boolean, String, File, Reader, Writer, InputStream, OutputStream</code>,
44+ * boolean, String, File, Reader, Writer, InputStream, OutputStream, Enum </code>,
4545 * plus arrays of all the above types. In the case of arrays, the option
4646 * may appear multiple times on the command line, otherwise recurrance of
4747 * the same option is an error.
@@ -218,6 +218,29 @@ public static String[] configureBean(Object bean, String[] args)
218218 throw new ConfigurationException ("Can't open " + name + " for output" );
219219 }
220220 }
221+ } else if ( propType .isEnum ()) {
222+ String name = args [++i ];
223+ try {
224+ propVal = Enum .valueOf (propType , name );
225+ } catch (Exception ex ) {
226+ try {
227+ // Try with uppercase version, as common for enums
228+ propVal = Enum .valueOf (propType , name .toUpperCase ());
229+ } catch (Exception ex2 ) {
230+ //give up
231+ StringBuilder errMsg = new StringBuilder ();
232+ errMsg .append ("Option " ).append (arg );
233+ errMsg .append (" requires a " ).append (propType .getSimpleName ());
234+ errMsg .append (" parameter. One of: " );
235+ for (Object val : propType .getEnumConstants () ) {
236+ Enum enumVal = (Enum ) val ;
237+ errMsg .append (enumVal .name ());
238+ errMsg .append (" " );
239+ }
240+ throw new ConfigurationException (errMsg .toString ());
241+ }
242+ }
243+
221244 } else {
222245 System .err .println ("Unsupported optionType for " + arg + " propType:" + propType );
223246 System .exit (1 );
0 commit comments