private void injectOpts ( GNUishParser p , Class < ? > clazz ) { for ( Field f : clazz . getDeclaredFields ( ) ) { f . setAccessible ( true ) ; final CliOption anno = f . getAnnotation ( CliOption . class ) ; if ( anno == null ) { continue ; } String value = p . getShortOpt ( anno . shortName ( ) ) ; if ( value == null ) { value = p . getLongOpt ( f . getName ( ) ) ; if ( value == null ) { continue ; } } try { f . set ( instance , c . convert ( value , f . getType ( ) ) ) ; } catch ( ConversionException e ) { throw CliException . WRONG_OPT_TYPE ( f . getName ( ) , f . getType ( ) . getName ( ) , value ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } validateOpts ( instance ) ; }
Convert options to appropriate type and inject them into the command instance .