public void execute ( GNUishParser p ) { if ( instance == null ) { instance = Utils . newInstance ( className ) ; } final Class < ? > clazz = instance . getClass ( ) ; final Method [ ] methods = clazz . getDeclaredMethods ( ) ; for ( Method m : methods ) { m . setAccessible ( true ) ; if ( ! m . getName ( ) . equals ( p . getCommand ( ) ) ) { continue ; } final List < Object > args = adjustArgs ( p . getArgs ( ) , m ) ; injectOpts ( p , clazz ) ; try { validateArgs ( args , instance , m , this ) ; m . invoke ( instance , args . toArray ( ) ) ; return ; } catch ( InvocationTargetException e ) { final Throwable ex = e . getTargetException ( ) ; if ( ex instanceof RuntimeException ) { throw ( RuntimeException ) e . getCause ( ) ; } else { throw new RuntimeException ( e . getTargetException ( ) ) ; } } catch ( RuntimeException e ) { throw e ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } System . out . println ( p . getCommand ( ) + ": command not found" ) ; }
Execute this command according to the user input arguments parsed by the parser .