public static < A > A readArguments ( Class < A > interfaceClass , String [ ] args ) { A result = null ; try { final ArgumentHandler argumentHandler = new ArgumentHandler ( args ) ; result = argumentHandler . getInstance ( interfaceClass ) ; argumentHandler . processArguments ( new ArgumentProcessor ( ) { @ Override public void process ( List < String > remaining ) throws InvalidArgumentsException { if ( remaining . size ( ) > 0 ) { throw new InvalidArgumentsException ( "The following arguments could not be understood: " + remaining ) ; } } } ) ; } catch ( InvalidArgumentsException e ) { System . out . println ( e . getMessage ( ) ) ; showUsage ( interfaceClass ) ; result = null ; } if ( result instanceof ArgumentsWithHelp ) { if ( ( ( ArgumentsWithHelp ) result ) . getHelp ( ) ) { showUsage ( interfaceClass ) ; result = null ; } } return result ; }
Returns an instance of A if the arguments could be correctly parsed and A was not a subclass of ArgumentsWithHelp or no help was requested null otherwise .